安装JDK:
yum install -y fontconfig java-11-openjdk
# 安装目录:/usr/lib/jvm
# fontconfig 是 Linux 系统中用于配置和管理字体的一种工具
下载jenkins安装包:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
修改jenkins的启动配置文件:
vim /usr/lib/systemd/system/jenkins.service
sed -i 's/^User=.*/User=root/' /usr/lib/systemd/system/jenkins.service
sed -i 's/^Group=.*/Group=root/' /usr/lib/systemd/system/jenkins.service
# 修改为自己想要的访问端口号
sed -i 's/^Environment=\"JENKINS_PORT=.*/Environment=\"JENKINS_PORT=8888\"/' /usr/lib/systemd/system/jenkins.service
# 修改Jenkins前缀(方便Nginx代理)
sed -i 's/^#Environment=\"JENKINS_PREFIX/Environment=\"JENKINS_PREFIX/' /usr/lib/systemd/system/jenkins.service
启动jenkins:
systemctl daemon-reload && systemctl start jenkins && systemctl enable jenkins
jenkins默认安装目录 /var/lib/jenkins在服务启动成功后创建文件
[root@localhost ~]# ll /var/lib/jenkins
total 28
-rw-r--r-- 1 root root 1640 Dec 18 10:53 config.xml
-rw-r--r-- 1 root root ?156 Dec 18 10:53 hudson.model.UpdateCenter.xml
-rw------- 1 root root 1712 Dec 18 10:53 identity.key.enc
-rw-r--r-- 1 root root ? ?7 Dec 18 10:53 jenkins.install.UpgradeWizard.state
-rw-r--r-- 1 root root ?171 Dec 18 10:53 jenkins.telemetry.Correlator.xml
drwxr-xr-x 2 root root ? ?6 Dec 18 10:53 jobs
drwxr-xr-x 3 root root ? 19 Dec 18 10:53 logs
-rw-r--r-- 1 root root ?907 Dec 18 10:53 nodeMonitors.xml
drwxr-xr-x 2 root root ? ?6 Dec 18 10:53 nodes
drwxr-xr-x 2 root root ? ?6 Dec 18 10:53 plugins
-rw-r--r-- 1 root root ? 64 Dec 18 10:53 secret.key
-rw-r--r-- 1 root root ? ?0 Dec 18 10:53 secret.key.not-so-secret
drwx------ 4 root root ?265 Dec 18 10:53 secrets
drwxr-xr-x 2 root root ? 26 Dec 18 10:53 updates
drwxr-xr-x 2 root root ? 24 Dec 18 10:53 userContent
drwxr-xr-x 3 root root ? 56 Dec 18 10:53 users
修改镜像地址:
vim /var/lib/jenkins/hudson.model.UpdateCenter.xml
# 将<url></url>内的地址修改为
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
重启jenkins:(jenkins没有重启)
systemctl daemon-reload && systemctl start jenkins
浏览器访问:
http://192.168.174.202:8888/jenkins
将此路径文件中的密钥复制到输入框:
[root@jenkins-server ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
0c28e6d1e10d4e858a1c38e09ca8df86
因为Jenkins插件需要连接默认官网下载,速度非常慢,而且经过会失败,所以我们暂时先跳过插件安装
创建一个新的管理员账号:
确认jenkins的访问地址:
完成:
重新访问: