Jenkins 未通过谷歌云显示在 Ubuntu 上

Len*_*tto 0 installation ubuntu port jenkins google-cloud-platform

我已在运行 Google Cloud 计算引擎的 Ubuntu 计算机上安装了 Jenkins。

为此,我运行了以下命令:

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
Run Code Online (Sandbox Code Playgroud)

Jenkins 似乎安装得很好,但是当我访问端口 8080 上的公共 IP 地址时,那里什么也没有。我读到可能是 Apache 使用端口 8080,所以我编辑/etc/default/jenkins并将端口更改为 8081。我仍然在该端口上看不到 jenkins。

我还重新启动了该服务,但没有任何变化。如果我做:

sudo netstat -plntu
Run Code Online (Sandbox Code Playgroud)

我懂了:

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 
Run Code Online (Sandbox Code Playgroud)

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

 [ + ]  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
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我我在这里做错了什么吗?

Tux*_*ude 5

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

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

Jenkins 是一个 Java 应用程序,因此该进程可能仅显示为java.

您似乎正在尝试通过实例的公共 IP 和端口访问该服务。Google 计算引擎 (GCE) 防火墙可能会阻止此行为,因为默认情况下,来自 GCE 虚拟机中外部 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
Run Code Online (Sandbox Code Playgroud)

使用云控制台

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

    1. Name规则 -rule-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 范围,您知道将是唯一访问该范围的 IP 范围,请使用它们来获得更严格的限制)
    7. Protocols and portstcp:8081
    8. 选择Create按钮来创建此防火墙规则。
  4. 创建上述防火墙规则后,您需要将标记添加allow-tcp-8081到需要应用此规则的所有实例。在你的情况下:

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

现在等待几秒钟到几分钟以使更改生效,您将能够访问 jenkins Web URL。

您还可以浏览防火墙规则的文档,以更好地了解它们的工作原理以及如何配置它们。

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