小编典典

Jenkins没有通过Google Cloud在Ubuntu上显示

jenkins

我已经在运行于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

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

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


阅读 396

收藏
2020-07-25

共1个答案

小编典典

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

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

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

看来您正在尝试通过实例的公共IP和端口访问服务。Google Compute Engine(GCE)防火墙可能阻止了此操作,因为默认情况下,GCE
VM中来自外部IP的所有传入端口均被阻止。

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

[使用gcloud](https://cloud.google.com/sdk/gcloud/reference/compute/firewall-

rules/)

# 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. 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按钮创建此防火墙规则。
    9. 创建上述防火墙规则后,您需要将标签添加allow-tcp-8081到需要应用此规则的所有实例。在您的情况下:

    10. 打开GCE VM Instances页面

    11. 选择运行Jenkins的实例
    12. VM instance details页面中,选择Edit最顶部的链接。
    13. Network Tags框中,输入allow-tcp-8081以将标签应用于该实例。
    14. 选择Save以保存更改。

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

您还可以浏览 防火墙规则
的文档,以更好地了解它们的工作方式和配置方式。

注意: 通过使用0.0.0.0/0,您将向整个Internet开放此端口,以便世界各地的客户端都可以连接到该端口。请注意这样做的安全隐患。

2020-07-25