selinux iptables off
主机名 | IP | 系统版本 |
---|---|---|
gitlab | 10.10.10.200 | rhel7.5 |
jenkins | 10.10.10.10 | rhel7.5 |
tomcat | 10.10.10.11 | rhel7.5 |
下载地址:https://download.docker.com/linux/static/stable/x86_64/
[root@jenkins ~]# tar xf docker-18.06.3-ce.tgz
[root@jenkins ~]# cd docker/
[root@jenkins docker]# cp * /usr/bin/
[root@jenkins ~]# vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
[root@jenkins ~]# chmod +x /etc/systemd/system/docker.service
[root@jenkins ~]# systemctl daemon-reload
[root@jenkins ~]# systemctl enable docker && systemctl restart docker
[root@jenkins ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
[root@jenkins ~]# systemctl restart docker
[root@gitlab ~]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
[root@gitlab ~]# yum install -y gitlab-ce
[root@gitlab ~]# gitlab-ctl reconfigure
其他命令:
# 启动 gitlab 服务
gitlab-ctl start
# 停止 gitlab 服务
gitlab-ctl stop
http://10.10.10.200
[root@gitlab ~]# cat /etc/gitlab/initial_root_password
[root@server1 ~]# tar xf jdk-8u45-linux-x64.tar.gz
[root@server1 ~]# mv jdk1.8.0_45/ /usr/local/jdk
[root@server1 ~]# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
[root@server1 ~]# . /etc/profile
官网下载地址:https://tomcat.apache.org/download-80.cgi
[root@server1 ~]# tar xf apache-tomcat-8.5.59.tar.gz
[root@server1 ~]# mv apache-tomcat-8.5.59 /usr/local/tomcat
[root@server1 ~]# /usr/local/tomcat/bin/startup.sh
[root@server1 ~]# /usr/local/tomcat/bin/shutdown.sh ###关闭
[root@jenkins ~]# docker pull jenkins/jenkins:2.361.4-lts-jdk11
[root@jenkins ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins/jenkins 2.361.4-lts-jdk11 25fa92c47840 6 months ago 463MB
[root@jenkins ~]# tar xf jdk-8u45-linux-x64.tar.gz
[root@jenkins ~]# mv jdk1.8.0_45/ /usr/local/jdk
[root@jenkins ~]# tar xf apache-maven-3.5.0-bin.tar.gz
[root@jenkins ~]# mv apache-maven-3.5.0 /usr/local/maven
[root@jenkins ~]# vim /usr/local/maven/conf/settings.xml
central
central
aliyun maven
https://maven.aliyun.com/repository/public
docker run -d --name jenkins -p 8080:8080 -p 50000:50000 -u root \
-v /opt/jenkins_home:/var/jenkins_home \
-v /usr/local/maven:/usr/local/maven \
-v /usr/local/jdk:/usr/local/jdk \
-v /etc/localtime:/etc/localtime \
-v /usr/bin/docker:/usr/bin/docker \
-v /var/run/docker.sock:/var/run/docker.sock \
--restart=always \
jenkins/jenkins:2.361.4-lts-jdk11
[root@jenkins ~]# cd /opt/jenkins_home/
[root@jenkins jenkins_home]# sed -i ‘s#https://updates.jenkins.io/update-center.json#http://mirror.esuni.jp/jenkins/updates/update-center.json#g’ hudson.model.UpdateCenter.xml
[root@jenkins jenkins_home]# systemctl restart docker
[root@jenkins ~]# cat /opt/jenkins_home/secrets/initialAdminPassword
375dd3d01ef9411b833a8860d028683d
[root@jenkins ~]# cd /opt/jenkins_home/updates/
[root@jenkins updates]# sed -i 's/https:\/\/updates.jenkins.io\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json
[root@jenkins updates]# sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
提前下载
git parameter
、Publish Over SSH
插件,git parameter版本低于0.95正常,否则报错:Retrieving Git references
,无法获取到正常版本
Manage Jenkins -> Configure System -> Public over SSH
JAVA_HOME=/usr/local/jdk
PATH=$PATH:$JAVA_HOME/bin
/usr/local/maven/bin/mvn clean package -Dmaven.test.skip=true
tomcat=/usr/local/tomcat
cd $tomcat/webapps
rm -rf $tomcat/webapps/ROOT
mv *.war /data/backup/$(date +"%F_%T")_ROOT.war
# 部署新程序并重启Tomcat
mv /tmp/$JOB_NAME/*.war $tomcat/webapps/ROOT.war
pid=$(ps -ef |grep $tomcat |egrep -v 'grep' |awk '{print $2}')
[ -n "$pid" ] && kill -9 $pid
export JAVA_HOME=/usr/local/jdk
/bin/bash /usr/local/tomcat/bin/startup.sh
安装插件
Maven IntegrationVersion 3.22
系统管理->全局工具配置
clean package -DskipTests=true
tomcat=/usr/local/tomcat
cd $tomcat/webapps
rm -rf $tomcat/webapps/ROOT
mv *.war /data/backup/$(date +"%F_%T")_ROOT.war
# 部署新程序并重启Tomcat
mv /tmp/$JOB_NAME/*.war $tomcat/webapps/ROOT.war
pid=$(ps -ef |grep $tomcat |egrep -v 'grep' |awk '{print $2}')
[ -n "$pid" ] && kill -9 $pid
export JAVA_HOME=/usr/local/jdk
/bin/bash /usr/local/tomcat/bin/startup.sh
pipeline {
agent any
stages {
stage('拉取代码') {
steps {
checkout scmGit(branches: [[name: '$Branch']], extensions: [], userRemoteConfigs: [[credentialsId: 'e94bf465-be00-490b-9f24-856106362015', url: 'http://10.10.10.200/wielun/java-test.git']])
}
}
stage('maven编译') {
steps {
sh '''JAVA_HOME=/usr/local/jdk
PATH=$PATH:$JAVA_HOME/bin
/usr/local/maven/bin/mvn clean package -Dmaven.test.skip=true'''
}
}
stage('发送到tomcat服务器并启动') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: 'tomcat-test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '''tomcat=/usr/local/tomcat
cd $tomcat/webapps
rm -rf $tomcat/webapps/ROOT
mv *.war /data/backup/$(date +"%F_%T")_ROOT.war
# 部署新程序并重启Tomcat
mv /tmp/$JOB_NAME/*.war $tomcat/webapps/ROOT.war
pid=$(ps -ef |grep $tomcat |egrep -v \'grep\' |awk \'{print $2}\')
[ -n "$pid" ] && kill -9 $pid
export JAVA_HOME=/usr/local/jdk
/bin/bash /usr/local/tomcat/bin/startup.sh''', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '$JOB_NAME', remoteDirectorySDF: false, removePrefix: 'target', sourceFiles: 'target/*.war')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
注:第一次看不到分支,构建一次就好了