【问题标题】:centos 7.x jenkins2 on port 80端口 80 上的 centos 7.x jenkins2
【发布时间】:2019-12-05 10:37:38
【问题描述】:

我在 https://app.vagrantup.com/centos/boxes/7 上运行 jenkins,它在 8080 端口上运行良好。

我在过去 2 个小时里一直在寻找将端口从 8080 更改为 80。没有成功 我一直在“拒绝连接”。

我猜这是某种防火墙问题?

centos box 是最小的 jenkins,java 只是安装在上面的应用程序。

到目前为止,我尝试了这些。

https://jenkins.io/doc/book/installing/

firewall-cmd --permanent --new-service=jenkins
firewall-cmd --permanent --service=jenkins --set-short="Jenkins Service Ports"
firewall-cmd --permanent --service=jenkins --set-description="Jenkins service firewalld port exceptions"
firewall-cmd --permanent --service=jenkins --add-port=80/tcp
firewall-cmd --permanent --add-service=jenkins
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

从这里更新端口 vi /etc/sysconfig//jenkins JENKINS_PORT="80"

how to change port number for Jenkins installation In Ubuntu 12.04

https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions

我正在使用 puppet 安装 Jenkins

 exec {'Add Jenkins Repo':
    command => 'yum-config-manager --add-repo http://pkg.jenkins-ci.org/redhat/jenkins.repo && rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key',
    path    => '/usr/bin:/bin',
    unless  => 'ls /etc/yum.repos.d/jenkins.repo',
  }

  exec { 'Install Java':
    command => 'yum -y install java',
    unless  => 'ls /usr/bin/java',
    path    => ['/bin', '/usr/bin', '/usr/sbin'],
    # noop    => true,
  }
  exec { 'Install dejavu-sans-fonts': # https://wiki.jenkins.io/display/JENKINS/Jenkins+got+java.awt.headless+problem
    command => 'yum -y install dejavu-sans-fonts',
    unless  => 'ls /usr/share/fonts/dejavu/', # TODO Find location 
    path    => ['/bin', '/usr/bin', '/usr/sbin'],
  }
  exec { 'Install fontconfig': # https://wiki.jenkins.io/display/JENKINS/Jenkins+got+java.awt.headless+problem
    command => 'yum -y install fontconfig',
    unless  => 'ls /usr/share/fontconfig', # TODO Find location 
    path    => ['/bin', '/usr/bin', '/usr/sbin'],
  }
  exec { 'Install Jenkins':
    command => 'yum -y install jenkins',
    unless  => 'ls /etc/init.d/jenkins',
    path    => ['/bin', '/usr/bin', '/usr/sbin'],
    require => Exec['Install Java', 'Add Jenkins Repo', 'Install dejavu-sans-fonts',  'Install fontconfig'],
    # noop    => true,
  }

  service { 'jenkins':
    ensure  => 'running',
    # enable  => true,
    require => Exec['Install Jenkins'],
  }

更新

[root@jenkins]# firewall-cmd --query-port=80/tcp
yes
[root@jenkins]# firewall-cmd --query-port=8080/tcp
yes

【问题讨论】:

    标签: jenkins


    【解决方案1】:

    如果您没有进行任何进一步的自定义,那么可能是 Jenkins 没有启动,而不是防火墙问题。该服务配置为以用户 jenkins 启动,但绑定到低于 1024 的端口仅限于 root。

    我运行的步骤与您提到的相同,并且在日志中很清楚:

    # cat /var/log/jenkins/jenkins.log
    ...
    2019-12-06 09:39:23.781+0000 [id=1]     INFO    winstone.Logger#logInternal: Jetty shutdown successfully
    java.io.IOException: Failed to start Jetty
    ...
    Caused by: java.net.SocketException: Permission denied
            at sun.nio.ch.Net.bind0(Native Method)
    ...
    
    # service jenkins status
    jenkins dead but pid file exists
    

    要使其在端口 80 上工作,您可以在技术上将 JENKINS_USER 更改为 /etc/sysconfig/jenkins 中的 root 并重新保护文件,但不建议这样做,因为这将是一个很大的安全漏洞。最好安装 nginx 并将其配置为反向代理,监听 80 端口并将流量重定向到 localhost:8080。

    【讨论】:

      【解决方案2】:

      感谢 raspy 提供线索, 我最终在

      中使用带有以下代码的nginx
      include nginx
      nginx::resource::server { $host:
        listen_port       => 80,
        proxy             => 'http://localhost:8080',
        ssl               => true,
        ssl_redirect      => true,
        ssl_redirect_port => 443,
        ssl_cert          => '/etc/ssl/certs/one_certificate.crt',
        ssl_key           => '/etc/ssl/private/one_certificate.key',
        owner             => 'root',
        group             => 'root',
        require           => [Class['jenkins::package'], File['/etc/ssl/certs/one_certificate.crt'], File['/etc/ssl/private/one_certificate.key']],
      }
      

      您可以使用以下方法在本地生成自签名 ssl 证书或在上面的代码中完全注释掉 ssl 以在端口 80 上使用 http

       openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/one_certificate.key -out /etc/ssl/certs/one_certificate.crt
      

      我使用了这个 puppet nginx 模块https://forge.puppet.com/puppet/nginx

      $host 将是您的主机名或本地主机

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-20
        • 2014-01-31
        • 2011-07-29
        • 1970-01-01
        • 2012-07-01
        • 2016-07-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多