安装supervisor
安装pip
如果服务器上没有pip,则先安装pip,方法如下:
代码语言:javascript复制yum -y install epel-release
yum -y install python-pip
安装supervisor
指定版本安装
代码语言:javascript复制pip install supervisor==4.1.0
配置supervisor
这里可以定义自己的工作目录,例如将supervisor放在/usr/local目录下
代码语言:javascript复制mkdir /usr/local/supervisor/{logs,run,supervisord.d} -p
echo_supervisord_conf > /usr/local/supervisor/supervisord.conf
修改supervisor的配置文件
可以根据情况来配置supervisord.conf里的配置项,然后贴入一下内容(直接覆盖即可)
代码语言:javascript复制[unix_http_server]
file=/usr/local/supervisor/run/supervisord.sock ; the path to the socket file
[supervisord]
logfile=/usr/local/supervisor/logs/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10 ; # of main logfile backups; 0 means none, default 10
loglevel=info ; log level; default info; others: debug,warn,trace
pidfile=/usr/local/supervisor/run/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false ; start in foreground if true; default false
minfds=1024 ; min. avail startup file descriptors; default 1024
minprocs=200 ; min. avail process descriptors;default 200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///usr/local/supervisor/run/supervisord.sock ; use a unix:// URL for a unix socket
[include]
files = supervisord.d/*.conf
将supervisor加入systemd
首先查看下supervisord和supervisorctl的全路径
代码语言:javascript复制# which supervisord supervisorctl
/usr/bin/supervisord
/usr/bin/supervisorctl
用systemd管理supervisor
代码语言:javascript复制vim /usr/lib/systemd/system/supervisord.service
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /usr/local/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
启动supervisor
代码语言:javascript复制systemctl daemon-reload
systemctl restart supervisord
systemctl enable supervisord
正常启动后即部署Jenkins
安装jenkins
准备jdk环境
这里使用yum进行快速安装
代码语言:javascript复制yum -y install java-1.8.0-openjdk*
查看java版本进行确认
代码语言:javascript复制# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
下载Jenkins安装包
这里使用的Jenkins版本为:2.176.2 下载地址:jenkins
创建Jenkins需要的目录
代码语言:javascript复制mkdir /usr/local/jenkins -p
mkdir /data/jenkins -p
设置Jenkins的工作目录
Jenkins有自己的一些环境变量可供使用,其中JENKINS_HOME
为Jenkins的工作目录,我们需要为其设置下工作目录,这里设置的是/data/jenkins
设置方法:加入环境变量即可
vim /etc/profile.d/jenkins.sh
export JENKINS_HOME=/data/jenkins
添加完毕后,source /etc/profile下即可,最后在命令行输入echo $JENKINS_HOME
看下输出是否为我们设置的工作目录
# echo $JENKINS_HOME
/data/jenkins
使用supervisor启动Jenkins
将下载好的war包移动到/usr/local/jenkins/
目录下,然后配置用于启动jenkins的supervisor文件
vim /usr/local/supervisor/supervisord.d/jenkins.conf
[program:jenkins]
command=java -jar jenkins.war --httpPort=8080
directory=/usr/local/jenkins
user=root
environment=JENKINS_HOME=/data/jenkins
stdout_logfile=/usr/local/supervisor/logs/jenkins.log
autostart=true
autorestart=true
startsecs=5
redirect_stderr=true
stopasgroup=true
killasgroup=true
启动Jenkins
代码语言:javascript复制supervisorctl update
supervisorctl start jenkins
#查看jenkins是否启动成功
supervisorctl status jenkins
jenkins RUNNING pid 8171, uptime 0:00:14
问题
如果使用supervisorctl status的过程中报错
# supervisorctl status error: <class ‘socket.error’>, [Errno 113] No route to host: file: /usr/lib64/python2.7/socket.py line: 571
解决办法:加一条软连接 ln -s /usr/local/supervisor/supervisord.conf /etc/supervisord.conf
配置Jenkins
浏览器访问:IP 8080
根据界面提示,查看密码:
# cat /data/jenkins/secrets/initialAdminPassword
870a2b923fc646edb81e5b661622794e
到这一步可以跳过,随后就是设置下代理,可参考博客:如何设置jenkins的代理
到这里就已经结束了,剩下的就是安装插件和配置,这里不再讲诉。。