目录
官网安装方法
安装java,**注意java版本,新版本jenkins只支持jdk11及以上
安装jenkins
Jenkins启动失败的七个问题
jenkins 部署脚本
Nginx转发jenkins服务
官网安装方法
Redhat Jenkins Packages (jenkins-ci.org)https://mirrors.jenkins-ci.org/redhat/
安装java,**注意java版本,新版本jenkins只支持jdk11及以上
1、查看本机是否自带java:rpm -qa|grep java
2、有则卸载:rpm -e --nodeps java*
3、查看yum中jdk版本:yum search jdk
发现有java11,列出java11:yum list |grep java-11
看到有文档、源码这些包,没必要安装,所以安装开头的那三个就可以了。
yum install -y java-11-openjdk-headless-11.0.5.10-0.el7_7.x86_64 java-11-openjdk-11.0.5.10-0.el7_7.x86_64 java-11-openjdk-devel-11.0.5.10-0.el7_7.x86_64
可能各个centos版本的jdk版本不一样,输入完yum install -y后挨个用鼠标选择包名后按shift+ins键就可以复制到命令行了,避免手打打错字。
5、安装完成直接java -version就可以出现版本信息。
6、配置环境变量
安装完之后,默认的安装目录是在: /usr/lib/jvm/
跟java8比,已经没有了dt.jar和tools.jar了,并且去看安装位置的jre,发现有一个已经指向了jdk文件夹(懵逼脸)。
在profile文件中添加如下内容
#set java environment
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.5.10-0.el7_7.x86_64
JRE_HOME=$JAVA_HOME
CLASS_PATH=.:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
让修改生效:source /etc/profile
安装jenkins
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
sudo yum upgrade
yum install fontconfig java-11-openjdk
yum install jenkins
说明:默认安装目录
Jenkins启动失败的七个问题
1、jdk版本和路径问题(注意第6个问题)
which java
vim /etc/init.d/jenkins
2、用户名问题
查看/etc/sysconfig/jenkins的JENKINS_USER="root",如果不是root,而是jenkins或者其它,要改成root。或者相反操作。
或者/usr/lib/systemd/system/jenkins.service的,同上处理。
老版本:
vim /etc/sysconfig/jenkins
systemctl daemon-reload
新版本:
vim /usr/lib/systemd/system/jenkins.service
User=root
Group=root
systemctl daemon-reload
3、log权限问题
cd /var/log
chmod 777 -R jenkins/
4、启动方法问题(如果是CS9,则需要执行第一步)
cp /etc/rc.d/init.d/functions /etc/init.d/
cd /etc/init.d/
./jenkins status
./jenkins stop
./jenkins start
5、卸载jenkins
yum remove jenkins
rm -rf /etc/sysconfig/jenkins.rpmsave
rm -rf /var/cache/jenkins/
rm -rf /etc/init.d/jenkins.rpmsave
6、无法使用systemctl启动jenkins
vim /usr/lib/systemd/system/jenkins.service
修改上图为:
Environment="JAVA_HOME=/usr/java/jdk-17.0.4"
其中/usr/java/jdk-17.0.4为使用which java命令得到的路径。
systemctl daemon-reload
systemctl enable jenkins
7、端口占用,可能需要修改端口(修改前kill所有jenkins进程)
查看/etc/sysconfig/jenkins的JENKINS_PORT="8086"
或者/usr/lib/systemd/system/jenkins.service的Environment="JENKINS_PORT=8086"
老版本:
vim /etc/sysconfig/jenkins
systemctl daemon-reload
新版本:
vim /usr/lib/systemd/system/jenkins.service
systemctl daemon-reload
systemctl start jenkins.service
systemctl stop jenkins.service
systemctl status jenkins.service
netstat -ntap | grep 8086
jenkins 部署脚本
方式二:日志会在 jenkins 任务里
Nginx转发jenkins服务
upstream jenkins {
keepalive 32; # keepalive connections
server 127.0.0.1:8080; # jenkins ip and port
}
# Required for Jenkins websocket agents
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80; # Listen on port 80 for IPv4 requests
server_name ; # replace 'jenkins.example.com' with your server domain name
# this is the jenkins web root directory
# (mentioned in the /etc/default/jenkins file)
root /var/run/jenkins/war/;
access_log /var/log/nginx/jenkins.access.log;
error_log /var/log/nginx/jenkins.error.log;
# pass through headers from Jenkins that Nginx considers invalid
ignore_invalid_headers off;
location ~ "^/static/[0-9a-fA-F]{8}\/(.*)$" {
# rewrite all static files into requests to the root
# E.g /static/12345678/css/something.css will become /css/something.css
rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;
}
location /userContent {
# have nginx handle all the static requests to userContent folder
# note : This is the $JENKINS_HOME dir
root /var/lib/jenkins/;
if (!-f $request_filename){
# this file does not exist, might be a directory or a /**view** url
rewrite (.*) /$1 last;
break;
}
sendfile on;
}
location / {
sendfile off;
proxy_pass http://jenkins;
proxy_redirect default;
proxy_http_version 1.1;
# Required for Jenkins websocket agents
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;
#this is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffering off;
proxy_request_buffering off; # Required for HTTP CLI commands
proxy_set_header Connection ""; # Clear for keepalive
}
}