yum 安装Jenkins

67

安装JDK

yum install java -y
[root@jenkins ~]# java --version
openjdk 11.0.16 2022-07-19 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.16.0.8-1.el7_9) (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.0.8-1.el7_9) (build 11.0.16+8-LTS, mixed mode, sharing)

安装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 epel-release 

安装Jenkins

yum install jenkins -y

启动
systemctl start jenkins

访问

浏览器访问:
	ip+8080端口
获取密码登录jenkins;
	cat /var/lib/jenkins/secrets/initialAdminPassword

初始化jenkins
	选择后续安装插件

优化

  • 修改Jenkins的权限 因为执行一些命令需要root权限

此行为有风险,谨慎操作

vi /usr/lib/systemd/system/jenkins.service
改为
User=root
Group=root

-----------------------------------------------------------------------------------
[root@jenkins home]# chown -R root:root /var/lib/jenkins
[root@jenkins home]# chown -R root:root /var/cache/jenkins/
[root@jenkins home]# chown -R root:root /var/cache/jenkins
[root@jenkins home]# chown -R root:root /var/log/jenkins/
[root@jenkins home]# systemctl daemon-reload
[root@jenkins home]# systemctl restart jenkins