【问题标题】:Jenkins not showing on Ubuntu through google cloudJenkins 没有通过谷歌云在 Ubuntu 上显示
【发布时间】:2017-06-16 08:25:09
【问题描述】:

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

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

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

谁能告诉我我在这里做错了什么?

【问题讨论】:

    标签: ubuntu jenkins installation port google-cloud-platform


    【解决方案1】:

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

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

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

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

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

    Using 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
    

    Using Cloud Console

    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. 打开 GCE VM Instances 页面
      2. 选择运行 Jenkins 的实例
      3. VM instance details 页面中,选择最顶部的Edit 链接。
      4. Network Tags 框中,输入allow-tcp-8081 以将标记应用于此实例。
      5. 选择Save 保存更改。

    现在给它几秒钟到几分钟的时间让更改生效,您将能够访问 jenkins 网页 URL。

    您还可以浏览 Firewall rules 的文档,以更好地了解它们的工作原理以及如何配置它们。

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

    【讨论】:

    • 感激不尽!这确实是问题似乎一切都井井有条,但谷歌云默认阻止它。我就是按照你上面所说的去做的。它就像一个魅力!
    • @LennartGiaccotto - 是的,出于安全原因,除非防火墙规则允许,否则 Google Cloud 会阻止所有传入 GCE 虚拟机的流量。我还添加了使用gcloud 执行相同操作的步骤,以防万一。
    【解决方案2】:

    输入项目名称后运行 gcloud compute --project= firewall-rules create firewall-8080 --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:8080 --source-ranges=0.0 .0.0/0

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    相关资源
    最近更新 更多