Centos7下Jenkins安装

声明:本文在参考以下文章的基础上实践而来,如有侵权,请留言告知。
https://blog.csdn.net/wzqnls/article/details/78506149
https://blog.csdn.net/wzqnls/article/details/78506149

1. 首先安装好Java环境

# java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-b10)
OpenJDK 64-Bit Server VM (build 25.171-b10, mixed mode)

2. 获取jenkins安装源文件

wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo

结果如下:

--2018-07-20 15:36:23--  http://pkg.jenkins-ci.org/redhat/jenkins.repo
Resolving pkg.jenkins-ci.org (pkg.jenkins-ci.org)... 52.202.51.185
Connecting to pkg.jenkins-ci.org (pkg.jenkins-ci.org)|52.202.51.185|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 71
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

100%[=====================================================================================================================================================================>] 71          --.-K/s   in 0s

2018-07-20 15:36:25 (11.3 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [71/71]

3. 导入公钥

rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

4. 安装Jenkins

yum install -y jenkins
base                                                                                                                                                                                    | 3.6 kB  00:00:00
epel                                                                                                                                                                                    | 3.2 kB  00:00:00
extras                                                                                                                                                                                  | 3.4 kB  00:00:00
jenkins                                                                                                                                                                                 | 2.9 kB  00:00:00
updates                                                                                                                                                                                 | 3.4 kB  00:00:00
(1/5): extras/7/x86_64/primary_db                                                                                                                                                       | 172 kB  00:00:00
(2/5): epel/x86_64/updateinfo                                                                                                                                                           | 928 kB  00:00:00
(3/5): epel/x86_64/primary                                                                                                                                                              | 3.5 MB  00:00:00
(4/5): updates/7/x86_64/primary_db                                                                                                                                                      | 4.2 MB  00:00:00
(5/5): jenkins/primary_db                                                                                                                                                               | 112 kB  00:00:01
epel                                                                                                                                                                                               12614/12614
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.133-1.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================================
 Package                                          Arch                                            Version                                               Repository                                        Size
===============================================================================================================================================================================================================
Installing:
 jenkins                                          noarch                                          2.133-1.1                                             jenkins                                           72 M

Transaction Summary
===============================================================================================================================================================================================================
Install  1 Package

Total download size: 72 M
Installed size: 72 M
Downloading packages:
jenkins-2.133-1.1.noarch.rpm                                                                                                                                                            |  72 MB  00:20:20
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : jenkins-2.133-1.1.noarch                                                                                                                                                                    1/1
  Verifying  : jenkins-2.133-1.1.noarch                                                                                                                                                                    1/1

Installed:
  jenkins.noarch 0:2.133-1.1

Complete!

5. 配置文件修改

vi /etc/sysconfig/jenkins

修改如下内容:

JENKINS_PORT="8787"  

6. 日志信息查看

/var/libs/jenkins/logs
/var/log/jenkins/jenkins.log

7. 启动: http://{IP地址}:8787

service jenkins start

8. 以root用户运行jenkins中shell命令

8.1 修改Jenkins配置文件

#打开配置文件
vim /etc/sysconfig/jenkins
#修改$JENKINS_USER,并去掉当前行注释
$JENKINS_USER="root"

8.2 修改Jenkins相关文件夹用户权限

chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins

8.3 重启Jenkins服务并检查运行Jenkins的用户是否已经切换为root

# 重启Jenkins(若是其他方式安装的jenkins则重启方式略不同)
service jenkins restart
# 查看Jenkins进程所属用户
ps -ef | grep jenkins
# 若显示为root用户,则表示修改完成
    原文作者:梨捉阳笆
    原文地址: https://www.jianshu.com/p/ec896c418867
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞