环境准备:
Centos 7.4
Docker-ce, Docker的安装方式就不说了
步骤:
1. 创建Nexus的持久化目录
useradd jenkins && mkdir -p /data/jenkins-data && chown -R jenkins /data/jenkins-data
2. 将服务文件添加到systemd中,这些就可以随系统一起启动了
#vi /etc/systemd/system/jenkins.service
[Unit]
Description=Jenkins 1.22.0
Documentation=https://jenkins.io/zh/doc/book/installing/#setup-wizard
After=network.target docker.service
Requires=docker.service
[Service]
RestartSec=10
Restart=always
# Modify IP6_PREFIX to match network config
Environment="NAME=jenkins"
Environment="DATA_DIR=/data/jenkins-data"
Environment="IMG=jenkinsci/blueocean:1.22.0"
Environment="PORT=8080:8080/tcp"
# http://www.freedesktop.org/software/systemd/man/systemd.unit.html
# Clean-up bad state if still hanging around
#ExecStartPre=-/usr/bin/docker rm -f $NAME
# Attempt to pull new image for security updates
ExecStartPre=-/usr/bin/docker pull $IMG
# IPv6: Ensure forwarding is enabled on host's networking stack (hacky)
# Would be nice to use systemd-network on the host, but this doens't work
# http://lists.freedesktop.org/archives/systemd-devel/2015-June/032762.html
ExecStartPre=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; sysctl net.ipv6.conf.all.forwarding=1'
# Main process
ExecStart=/usr/bin/docker run --rm -v ${DATA_DIR}:/var/jenkins_home --name ${NAME} -p ${PORT} ${IMG}
# IPv6: Add static route for IPv6 after it starts up
ExecStartPost=/bin/sh -c 'test -z "${IP6_PREFIX}" && exit 0; sleep 1; ip route replace ${IP6_PREFIX} via $(docker inspect -f "{{ .NetworkSettings.GlobalIPv6Address }}" $NAME ) dev docker0'
# IPv6: Clean-up
ExecStopPost=/bin/sh -c 'test -z "$IP6_PREFIX" && exit 0; ip route del $IP6_PREFIX dev docker0'
[Install]
WantedBy=multi-user.target
3. 加入系统自启动并启动服务
systemctl daemon-reload && systemctl enable jenkins && systemctl start jenkins
4. 访问系统,第一次访问的用户名为:admin 密码在宿主机的:/data/jenkins-data/secrets/initialAdminPassword
5. 访问系统,http://10.128.12.12:8080/