我在我的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访问本机上的此端口,则可以按照以下步骤授予访问权限:
# 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
Menu -> Networking -> Firewall Rules
Create Firewall Rule
为防火墙规则选择以下设置:
Name
– rule-allow-tcp-8081
或您希望用于此防火墙规则的任何其他名称。 Direction
是ingress
Action on match
是Allow
Targets
是Specified target tags
Target tags
是allow-tcp-8081
Source IP ranges
是0.0.0.0/0
(或者如果你有一组IP范围,你知道是唯一访问这个范围的,用它们代替更强的限制) Protocols and ports
是tcp:8081
Create
按钮来创建此防火墙规则。 一旦创建了上述防火墙规则,您将需要将标记allow-tcp-8081
添加到需要应用此规则的所有实例。 在你的情况下:
VM Instances
页面 VM instance details
页面中,选择最上面的Edit
链接。 Network Tags
框中,输入allow-tcp-8081
将标签应用于此实例。 Save
以保存更改。 现在给它几分钟到几分钟的变化才能生效,你将能够访问詹金斯的网址。
您还可以阅读防火墙规则的文档,以更好地了解它们的工作方式以及如何配置它们。
注意:通过使用源范围0.0.0.0/0
,您可以将此端口打开到整个互联网,以便世界上任何地方的客户端都能够连接到此端口。 请注意这样做的安全隐患。