jenkins没有通过谷歌云显示在Ubuntu上

我在我的Ubuntu机器上安装了Jenkins,在Google云计算引擎上运行。

要做到这一点,我已经运行这些命令:

sudo apt-get update sudo apt-get install apache2 libapache2-mod-php5 php5-mcrypt php5-mysql git openjdk-7-jre openjdk-7-jdk -y wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins 

jenkins似乎安装很好,但是当我去端口8080上的公共IP地址有没有什么。 我读到,它可能是这样的Apache使用端口8080,所以我编辑了/etc/default/jenkins ,并将端口更改为8081.但我没有看到该端口jenkins。

我也重新启动了服务,但没有改变。 如果我做:

 sudo netstat -plntu 

我懂了:

 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 422/sshd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9745/apache2 tcp6 0 0 :::22 :::* LISTEN 422/sshd tcp6 0 0 :::8081 :::* LISTEN 17917/java udp 0 0 0.0.0.0:53763 0.0.0.0:* 294/dhclient udp 0 0 0.0.0.0:68 0.0.0.0:* 294/dhclient udp 0 0 10.132.0.2:123 0.0.0.0:* 372/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 372/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 372/ntpd udp6 0 0 :::9732 :::* 294/dhclient udp6 0 0 :::33848 :::* 17917/java udp6 0 0 ::1:123 :::* 372/ntpd udp6 0 0 :::123 :::* 372/ntpd udp6 0 0 :::5353 :::* 17917/java 

如果我检查它似乎正在运行的服务的状态:

  [ + ] acpid [ + ] apache2 [ - ] bootlogs [ - ] bootmisc.sh [ - ] checkfs.sh [ - ] checkroot-bootclean.sh [ - ] checkroot.sh [ + ] cron [ + ] dbus [ - ] generate-ssh-hostkeys [ - ] hostname.sh [ - ] hwclock.sh [ + ] jenkins [ - ] killprocs [ + ] kmod [ - ] motd [ - ] mountall-bootclean.sh [ - ] mountall.sh [ - ] mountdevsubfs.sh [ - ] mountkernfs.sh [ - ] mountnfs-bootclean.sh [ - ] mountnfs.sh [ + ] networking [ + ] ntp [ + ] procps [ + ] rc.local [ - ] rmnologin [ - ] rsync [ + ] rsyslog [ - ] screen-cleanup [ - ] sendsigs [ + ] ssh [ - ] sudo [ + ] udev [ + ] udev-finish [ - ] umountfs [ - ] umountnfs.sh [ - ] umountroot [ - ] unattended-upgrades [ + ] urandom [ - ] uuidd [ - ] x11-common 

有人能告诉我我在做什么错吗?

就VM而言,看起来Jenkins确实在运行(基于netstat的输出和正在运行的服务列表):

tcp6 0 0 :::8081 :::* LISTEN 17917/java

詹金斯是一个Java应用程序,因此该过程可能只显示为java

它看起来像你试图通过实例的公共IP和端口访问服务。 Google计算引擎(GCE)防火墙可能会阻止此操作,因为默认情况下会阻止来自GCE VM中外部IP的所有传入端口。

如果您的目标是通过任何公共IP访问本机上的此端口,则可以按照以下步骤授予访问权限:

使用gcloud

 # Create a new firewall rule that allows INGRESS tcp:8081 with VMs containing tag 'allow-tcp-8081' gcloud compute firewall-rules create rule-allow-tcp-8081 --source-ranges 0.0.0.0/0 --target-tags allow-tcp-8081 --allow tcp:8081 # Add the 'allow-tcp-8081' tag to a VM named VM_NAME gcloud compute instances add-tags VM_NAME --tags allow-tcp-8081 # If you want to list all the GCE firewall rules gcloud compute firewall-rules list 

使用云控制台

  1. Menu -> Networking -> Firewall Rules
  2. Create Firewall Rule
  3. 为防火墙规则选择以下设置:

    1. 规则的Namerule-allow-tcp-8081或您希望用于此防火墙规则的任何其他名称。
    2. Directioningress
    3. Action on matchAllow
    4. TargetsSpecified target tags
    5. Target tagsallow-tcp-8081
    6. Source IP ranges0.0.0.0/0 (或者如果你有一组IP范围,你知道是唯一访问这个范围的,用它们代替更强的限制)
    7. Protocols and portstcp:8081
    8. 选择Create按钮来创建此防火墙规则。
  4. 一旦创建了上述防火墙规则,您将需要将标记allow-tcp-8081添加到需要应用此规则的所有实例。 在你的情况下:

    1. 打开GCE VM Instances页面
    2. 选择Jenkins正在运行的实例
    3. VM instance details页面中,选择最上面的Edit链接。
    4. 在“ Network Tags框中,输入allow-tcp-8081将标签应用于此实例。
    5. 选择Save以保存更改。

现在给它几分钟到几分钟的变化才能生效,你将能够访问詹金斯的网址。

您还可以阅读防火墙规则的文档,以更好地了解它们的工作方式以及如何配置它们。

注意:通过使用源范围0.0.0.0/0 ,您可以将此端口打开到整个互联网,以便世界上任何地方的客户端都能够连接到此端口。 请注意这样做的安全隐患。