第十章 Docker安装Jenkins-2.249.3-1.1
Posted 青青子衿悠悠我心
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十章 Docker安装Jenkins-2.249.3-1.1相关的知识,希望对你有一定的参考价值。
一、安装Docker
Docker部署Jenkins前提已经安装Docker,这边脚本安装Docker。
#1.编写Docker安装脚本
[root@ip-10-0-12-212 ~]# vim Ins_Docker.sh
#!/usr/bin/bash
# Author:jh
# Time:2021-10-09 11:54:22
# Name:Ins_Docker.sh
# Version: 1.0
# Discription: To
source /etc/init.d/functions
rely_software=(yum-utils device-mapper-persistent-data lvm2)
echo "-----------------#1.检测系统内核版本-----------------"
kernel_version=`uname -a |awk \'{print $3}\'|cut -d. -f1`
[ $kernel_version -ge 3 ] && action "The System Install Docker is ..." /usr/bin/true || action "The System Can not Install Docker is ...";exit
echo "-----------------#2.安装Docker依赖软件-----------------"
for i in ${rely_software[*]}
do
rpm -q $i &>/dev/null
if [ $? -eq 0 ];then
echo "$i is installed"
else
yum -y install $i &>/dev/null
action "$i is installing" /usr/bin/true
fi
done
echo "-----------------#3.添加Docker镜像源-----------------"
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[ $? -eq 0 ] && action "Docker Image add is ..." /usr/bin/true || echo "Docker Image add is ..." /usr/bin/false;exit
echo "-----------------#4.安装Docker-----------------"
yum -y install docker-ce
rpm -qa |grep docker-ce
[ $? -eq 0 ] && action "Docker-ce is installed ..." /usr/bin/true || action "Docker-ce is install ..." /usr/bin/false;exit
echo "-----------------#5.启动Docker并设置开机自启-----------------"
systemctl enable --now docker
[ $? -eq 0 ] && action "Docker Start is ...;" /usr/bin/true || action "Docker start is ..." /usr/bin/false
docker_version=`docker -v |awk -F \',\' \'{print $1}\'`
echo "-----------------#6.设置Docker加速器-----------------"
sudo mkdir -p /etc/docker
sudo cat >/etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://8mh75mhz.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
echo "-----------------#7.查看Docker是否安装完成-----------------"
cat << EOF
+-------------------------------------------------+
| $docker_version 安 装 已 完 成 |
| 请 使 用 相 关 服 务 ! |
+-------------------------------------------------+
EOF
echo "-----------------#8.迁移Docker根目录-----------------"
systemctl stop docker
mv /var/lib/docker/ /data/
sed -i \'s#ExecStart=/usr/bin/dockerd#ExecStart=/usr/bin/dockerd --graph=/data/docker#g\' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl start docker.service
echo "-----------------#9.验证Docker根目录是否生效-----------------"
docker info |grep "Docker Root Dir"
sleep 5
echo ""-----------------你的小可爱已完成Docker全部部署-----------------"
#2.给脚本添加执行权限
[root@ip-10-0-12-212 ~]# chmod +x Ins_Docker.sh
#3.执行脚本
[root@ip-10-0-12-212 ~]# sh Ins_Docker.sh
二、拉取Jenkins镜像文件
[root@ip-10-0-12-212 ~]# docker pull jenkins/jenkins
三、创建挂载目录并授权
[root@ip-10-0-12-212 ~]# mkdir -p /data/jenkins_mount
[root@ip-10-0-12-212 ~]# chmod 777 /data/jenkins_mount
四、创建并启动Jenkins容器
[root@ip-10-0-12-212 ~]# docker run -d -p 10240:8080 -p 10241:50000 -v /data/jenkins_mount:/var/jenkins_home -v /etc/localtime:/etc/localtime --name Datalake_Jenkins jenkins/jenkins
e0a9964d61fd5eb9f1c0eae0f2f18bdbfcd03ff0d5c2cc0d0beae31c134afa75
五、查看jenkins是否启动成功
[root@ip-10-0-12-212 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e0a9964d61fd jenkins/jenkins "/sbin/tini -- /usr/…" 13 seconds ago Up 12 seconds 0.0.0.0:10240->8080/tcp, :::10240->8080/tcp, 0.0.0.0:10241->50000/tcp, :::10241->50000/tcp Datalake_Jenkin
六、查看docker容器日志
[root@ip-10-0-12-212 ~]# docker logs Datalake_Jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-18 02:00:12.630+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @1247ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-10-18 02:00:12.772+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2021-10-18 02:00:14.184+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2021-10-18 02:00:14.319+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.43.v20210629; built: 2021-06-30T11:07:22.254Z; git: 526006ecfa3af7f1a27ef3a288e2bef7ea9dd7e8; jvm 11.0.12+7
2021-10-18 02:00:14.887+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-10-18 02:00:14.969+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2021-10-18 02:00:14.969+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2021-10-18 02:00:14.973+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2021-10-18 02:00:15.909+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2021-10-18 02:00:16.516+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@316a598d{Jenkins v2.316,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2021-10-18 02:00:16.586+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@505a9d7c{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
七、访问Jenkins
访问Jenkins页面,http://52.82.80.128:10240
八、安装Jenkins
[root@ip-10-0-12-212 ~]# cd /data/jenkins_mount/
[root@ip-10-0-12-212 jenkins_mount]# cat secrets/initialAdminPassword
67925445271c4fe593ba83eede0f9c75
#2.选择安装推荐的插件
#3.填入相应的管理用户信息,点击保存并完成。
#4.配置此处Jenkins的URL。
#5.此处Jenkins已经安装就绪,点击开始使用Jenkins。
#6.此处已经进入Jenkins页面,右下角显示安装的版本号,至此Jenkins安装完毕。
第四十章 微服务CICD- jenkins(war版)
一、下载
官网下载war包,放在tomcat下的webapps下,
jenkins:2.19.1版本。
二、修改编码为utf-8
在/opt/apache-tomcat-7.0.72/conf/server.xml中的<connector>节点下添加URIEncoding="UTF-8"
1 <Connector port="8080" protocol="HTTP/1.1" 2 connectionTimeout="20000" 3 redirectPort="8443" URIEncoding="UTF-8"/> 4 <Connector executor="tomcatThreadPool" 5 port="8080" protocol="HTTP/1.1" 6 connectionTimeout="20000" 7 redirectPort="8443" URIEncoding="UTF-8"/> 8 <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" 9 maxThreads="150" SSLEnabled="true" scheme="https" secure="true" 10 clientAuth="false" sslProtocol="TLS" URIEncoding="UTF-8"/> 11 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
三、启动tomcat
浏览器访问10.211.55.4:8080就可以看到jenkins启动的页面,如果显示无法访问,关闭防火墙。
- systemctl disable firewalld
- systemctl stop firewalld
之后解锁jenkins:输入/root/.jenkins/secrets/initialAdminPassword中的密码来unlock jenkins
说明:/root/.jenkins是jenkins默认的主目录。
四、配置插件
- "系统管理"->"插件管理"->"高级"->手工下载插件,进行"上传"
说明:
- 不要使用在线安装,速度极慢。
- 插件下载地址:http://updates.jenkins-ci.org/download/plugins/
五、配置全局工具配置
"系统管理"->"Global Tool Configuration"
1、maven settings配置
2、jdk配置
前提:第一章 删掉centos原有的openjdk并安装sun jdk
3、git配置
4、maven配置
六、新建一个任务进行配置
1、新建maven项目,项目名(item name)为"mytest-service1"
2、源码管理
注意:
- 如果出现gitlab.zhaojigang.com无法解析,需要在/etc/hosts配置域名ip映射
1 10.211.55.4 gitlab.zhaojigang.com
其中,10.211.55.4是gitlab的机器ip
- 如果出现没有权限操作gitlab.zhaojigang.com,配置Credentials
3、构建触发器
说明:Poll SCM可以配置定时编译代码(如果gitlab上有修改)
4、Build
5、构建后步骤
说明:指定存档文件,这样的话,构建后产生的文件会展示成这样,之后在生产环境可以直接将该jar包拷贝到相应的机器进行执行。
jar包所在的地址是/root/.jenkins/workspace/mytest-service1/target,其中/root/.jenkins/workspace是$WORKSPACE。
七、立即构建项目,查看console就好了
以上是关于第十章 Docker安装Jenkins-2.249.3-1.1的主要内容,如果未能解决你的问题,请参考以下文章