Jenkins

snow chuai汇总、整理、撰写---2020/3/22


1. 安装OpenJDK11
1) 安装OpenJDK11
[root@jenkins ~]# yum  install java-11-openjdk java-11-openjdk-devel -y
2) 配置OpenJDK11 Shell环境 [root@jenkins ~]# cat > /etc/profile.d/java11.sh <<EOF export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac))))) export PATH=\$PATH:\$JAVA_HOME/bin EOF
[root@jenkins ~]# source /etc/profile.d/java11.sh
3) 确认java可正常使用 [root@jenkins ~]# java --version openjdk 11.0.6 2020-01-14 LTS OpenJDK Runtime Environment 18.9 (build 11.0.6+10-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.6+10-LTS, mixed mode, sharing)
4) 如果有多个Java版本,可按以下操作切换 [root@jenkins ~]# alternatives --config java There is 1 program that provides 'java'.
Selection Command ----------------------------------------------- *+ 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.6.10-1.el7_7.x86_64/bin/java)
Enter to keep the current selection[+], or type selection number: 1
2. 安装Jenkins
1) 安装Jenkins Repo
[root@jenkins ~]# cd /etc/yum.repos.d
[root@jenkins yum.repos.d]# curl -O https://pkg.jenkins.io/redhat-stable/jenkins.repo
2) 下载Jenkins GPG Key [root@jenkins yum.repos.d]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key [root@jenkins yum.repos.d]# cd [root@jenkins ~]#
3) 安装并启动Jenkins [root@jenkins ~]# yum install jenkins -y
[root@jenkins ~]# systemctl start jenkins [root@jenkins ~]# systemctl enable jenkins jenkins.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig jenkins on
4) 加速Jenkins插件下载(需等到Jenkins服务真正启动) # 耐心等待一会,JAVA比较慢.....大约5~15s左右
4.1) 修改Jenkins插件为国内源 [root@jenkins ~]# vim /var/lib/jenkins/hudson.model.UpdateCenter.xml 将https:......改为如下内容 https://mirror.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
4.2) 在清华tuna镜像下载Jenkins插件 [root@jenkins ~]# yum --enablerepo=epel install nginx -y [root@jenkins ~]# vim /etc/nginx/conf.d/mirrors.jenkins-ci.org.conf server { listen 80; server_name mirrors.jenkins-ci.org;
location / { proxy_redirect off; proxy_pass https://mirrors.tuna.tsinghua.edu.cn/jenkins/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Accept-Encoding ""; proxy_set_header Accept-Language "zh-CN"; } index index.html index.htm index.php;
location ~ /\. { deny all; }
access_log /var/log/nginx/jenkins.access.log; error_log /var/log/nginx/jenkins.error.log; }

[root@jenkins ~]# vim /etc/hosts 将jenkins-ci的site重定向为本地 ...... ......
127.0.0.1 mirrors.jenkins-ci.org
[root@jenkins ~]# systemctl enable --now nginx
[root@jenkins ~]# systemctl restart jenkins
5) 防火墙配置 [root@jenkins ~]# firewall-cmd --add-port=8080/tcp --permanent success [root@jenkins ~]# firewall-cmd --reload success
3. 初始化Jenkins
1) 安装Jenkins插件
[浏览器] ===> http://192.168.10.250:8080/

2) 获取Jenkins管理员密码并复制 [root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword 59666a15ef784490896ac5b05e687eec
3) 粘贴Jenkins管理员密码并继续
4) 安装jenkins推荐的插件

5) 创建管理员账号
6) 配置实例
7) 初始化完成并进入Jenkins

 

如对您有帮助,请随缘打个赏。^-^

gold