美文网首页
CentOS 7.4 安装Jenkins

CentOS 7.4 安装Jenkins

作者: arobot | 来源:发表于2018-12-03 18:43 被阅读9次

    使用yum方式安装Jenkins
    参考文章CentOS7下yum安装Jenkins

    安装Jenkins

    参考官方指导进行Jenkins yum源导入。

    # sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
    # sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
    

    进行安装

    # yum install jenkins
    

    显示如图所示表示安装完毕


    Jenkins Install Complete

    查看安装路径

    # rpm -ql jenkins
    
    Jenkins Install Path

    路径解析

    • /usr/lib/jenkins:Jenkins安装目录,war包存放于此
    • /etc/sysconfig/jenkins:Jenkins配置文件、端口、JENKINS_HOME等配置信息
    • /var/lib/jenkins:默认的JENKINS_HOME
    • /var/log/jenkins:Jenkins日志存放路径

    启动Jenkins

    查看端口占用

    # netstat -lnp|grep 'port'
    
    端口8081未被占用

    配置启动端口

    # vim /etc/sysconfig/jenkins
    # #vim命令,打开命令框
    # [shift]+[:]
    # #vim命令,执行搜索
    # [/]+"JENKINS_PORT"
    # 修改值"8080"为"8081"
    
    修改Jenkins端口

    防火墙开启端口

    CentOS默认使用firewalld作为防火墙管理工具。

    Firewalld基本使用方式参考

    开启8081端口

    # firewall-cmd --zone=public --add-port=8081/tcp --permanent
    

    刷新配置

    # firewall-cmd --reload
    

    启动Jenkins

    # java -jar /usr/lib/jenkins/jenkins.war --httpPort=8081
    

    启动Jenkins之后访问就可以看到管理员密码输入界面

    添加开机自启动

    将Jenkins服务设置为开机自启动

    # systemctl enable jenkins.service
    jenkins.service is not a native service, redirecting to /sbin/chkconfig.
    Executing /sbin/chkconfig jenkins on
    

    启动Jenkins服务

    # systemctl start jenkins.service
    

    启动Jenkins服务失败

    我这里在启动的时候报了异常信息Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.,通过systemctl status jenkins.service查询得知

    # systemctl status jenkins.service
    ● jenkins.service - LSB: Jenkins Automation Server
       Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
       Active: failed (Result: exit-code) since Wed 2018-12-05 09:51:56 CST; 16s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 25674 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=1/FAILURE)
    
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z systemd[1]: Starting LSB: Jenkins Automation Server...
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z runuser[25679]: pam_unix(runuser:session): session opened for user jenkins by...d=0)
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z jenkins[25674]: Starting Jenkins bash: /usr/bin/java: No such file or directory
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z jenkins[25674]: [FAILED]
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z systemd[1]: jenkins.service: control process exited, code=exited status=1
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z systemd[1]: Failed to start LSB: Jenkins Automation Server.
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z systemd[1]: Unit jenkins.service entered failed state.
    Dec 05 09:51:56 izbp1d1juyl8z6ucflj9v3z systemd[1]: jenkins.service failed.
    

    是因为找不到/usr/bin/java文件造成。这是因为我们是手动安装的jdk,导致并不会在/usr/bin目录下生成相应的文件。此时,只需要修改Jenkins的service文件,添加java启动文件路径即可。

    修改服务配置

    服务配置的路径在/etc/rc.d/init.d/jenkins,编辑该文件

    # vim /etc/rc.d/init.d/jenkins
    

    输入[:]+[/]+'java'+[enter]在文件中搜索'java',添加java执行文件,我这里是/opt/java/jdk1.8/bin

    修改java路径

    启动服务

    # #加载修改过的配置信息
    [root@izbp1d1juyl8z6ucflj9v3z bin]# systemctl daemon-reload
    # #启用配置文件
    [root@izbp1d1juyl8z6ucflj9v3z bin]# systemctl enable jenkins
    jenkins.service is not a native service, redirecting to /sbin/chkconfig.
    Executing /sbin/chkconfig jenkins on
    # #启动jenkins服务
    [root@izbp1d1juyl8z6ucflj9v3z bin]# systemctl start jenkins
    

    此时,Jenkins服务启动成功,可以打开Jenkins了。

    相关文章

      网友评论

          本文标题:CentOS 7.4 安装Jenkins

          本文链接:https://www.haomeiwen.com/subject/ojuycqtx.html