Centos7安裝jenkins+docker部署tomcat
Centos7安裝jenkins+docker部署tomcat
環境:centos7.5
硬體:gitlab:cpu=1,記憶體=2G
Jenkins:cpu=1,記憶體=1G
伺服器:
10.125.7.20 node1
10.125.7.21 node2
10.125.7.22 node3
1、安裝docker(每臺執行)
- 關閉防火牆
systemctl stop firewalld
systemctl disable firewalld
- 關閉selinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config && setenforce 0
- 安裝依賴包
yum install -y yum-utils device-mapper-persistent-data lvm2
- 安裝docker
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce -y
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s https://i9iblr0h.mirror.aliyuncs.com
systemctl restart docker
systemctl enable docker
2、安裝gitlab(10.125.7.21)
- 拉取gitlab映象
docker pull gitlab/gitlab-ce
- 啟動gitlab容器
docker run --detach --hostname node2 --publish 443:443 --publish 80:80 --publish 2222:22 --name gitlab --restart always --volume ~/gitlab/config:/etc/gitlab --volume ~/gitlab/logs:/var/log/gitlab --volume ~/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latest
- 建立使用者
修改及新增使用者密碼
- 用新建立的使用者登入gitlab並建立專案
- gitlab建立使用者,組,專案操作等
可參考 - 在本地安裝開發者工具idea最新版(一定要下載企業版,然後再破解)
然後在idea上建立springboot專案簡單的寫一個jsp並push到gitlab上,具體操作可自行百度,如果需要本地打包需在本地安裝jdk,git,maven等
3、安裝jenkins(10.125.7.22)
-
部署git和maven
yum install git -y
在http://maven.apache.org/download.cgi下載maven包
tar xf apache-maven-3.6.3-bin.tar.gz mkdir /opt/app/maven -pv mv apache-maven-3.6.3/* /opt/app/maven mkdir /opt/java && cd /opt/java && tar xf jdk-8u251-linux-x64.tar.gz
配置環境變數vim /etc/profile
export JAVA_HOME=/opt/java/jdk1.8.0_251 export M2_HOME=/opt/app/maven export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin source /etc/profile
-
安裝jenkins並啟動
配置yum源
vim /etc/yum.repos.d/jenkins.repo [jenkins] name=Jenkins-stable baseurl=http://pkg.jenkins.io/redhat-stable gpgcheck=1 ## 安裝jenkins yum install jenkins -y
-
配置jenkins使用
vim /etc/sysconfig/jenkins #監聽埠 JENKINS_PORT="8080" #修改配置 $JENKINS_USER="root" vim /etc/init.d/jenkins 在candidates="下面新增 /opt/java/jdk1.8.0_251/bin/java ## 啟動jenkins systemctl start jenkins
-
登入jenkins並簡單進行配置
4、安裝harbor私有倉庫(10.125.7.20)
-
安裝docker-compose
- 下載二進位制檔案
curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
- 賦予二進位制檔案可執行許可權
chmod +x /usr/local/bin/docker-compose
- 根據自己的情況決定是否安裝命令補全功能
yum install bash-completion curl -L https://raw.githubusercontent.com/docker/compose/1.16.1/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
- 測試是否安裝成功
docker-compose --version
-
安裝harbor
- 下載
wget -P /usr/local/src/ https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-online-installer-v1.2.0.tgz
- 解壓
cd /usr/local/src && tar zxf harbor-online-installer-v1.2.0.tgz -C /usr/local/
- 修改配置檔案
cd /usr/local/harbor/ vim /usr/local/harbor/harbor.cfg hostname = 192.168.68.134 ui_url_protocol = https ssl_cert = /etc/certs/ca.crt ssl_cert_key = /etc/certs/ca.key secretkey_path = /data
- 生成證照
mkdir /etc/certs openssl genrsa -out /etc/certs/ca.key 2048 openssl req -x509 -new -nodes -key /etc/certs/ca.key -subj "/CN=10.125.7.20" -days 5000 -out /etc/certs/ca.crt
- 客戶端配置(harbor客戶端,10.125.7.22和10.125.7.21)
mkdir -pv /etc/docker/certs.d/10.125.7.20 scp /etc/certs/ca.crt root@10.125.7.21:/etc/docker/certs.d/10.125.7.20/ scp /etc/certs/ca.crt root@10.125.7.22:/etc/docker/certs.d/10.125.7.20/
- 客戶端配置加速器
vim /etc/docker/daemon.json { "registry-mirrors": ["http://hub-mirror.c.163.com"], "insecure-registries": ["10.125.7.20"] } systemctl restart docker
- 執行安裝
cd /usr/local/harbor && ./prepare ./install.sh
- 訪問https://10.125.7.20/harbor/sign-in
預設賬號密碼: admin / Harbor12345 登入後修改密碼
如果harbor-adminserver一直Restarting狀態
解決辦法:1、docker-compose down
2、rm -rf /data/secretkey
3、cd /usr/local/harbor && ./prepare
4、docker-compose up -d- 登入驗證
5、jenkins上構建maven專案
先在jenkins伺服器上安裝ansible並與所部屬伺服器免密登入
10.125.7.21 jenkins
10.125.7.22 tomcat
安裝並配置ansible(10.125.7.22)
yum install ansible
vim /etc/ansible/hosts新增以下配置
[tomcat]
10.125.7.22
[tomcat:vars]
ansible_ssh_user='root'
ansible_ssh_pass='123456
配置免密登入
ssh-keygen -t rsa -p
ssh-copy-id -i ~/.ssh/id_rsa.pub “10.125.7.22”
驗證
相關文章
- CentOS7 Tomcat JSP 安裝部署CentOSTomcatJS
- Centos7安裝安裝部署dockerCentOSDocker
- Tomcat 8安裝部署Tomcat
- CentOS7 docker安裝部署教程CentOSDocker
- Centos7編譯安裝Tomcat教程。CentOS編譯Tomcat
- CentOS7系統GitLab安裝部署教程。CentOSGitlab
- 熱門報導:CentOS7安裝[Mysql,JDK,TomCat]CentOSMySqlJDKTomcat
- Ubuntu下Java、Nginx和Tomcat的安裝部署UbuntuJavaNginxTomcat
- Centos6.3下jdk+tomcat安裝部署CentOSJDKTomcat
- Tomcat手動啟動/部署[非安裝版]Tomcat
- jenkins+docker進行微服務部署JenkinsDocker微服務
- Linux系統安裝tomcat並部署專案。LinuxTomcat
- 使用docker搭建環境:安裝tomcat、部署war包DockerTomcat
- Centos7安裝部署openstack--nova計算服務CentOS
- Tomcat安裝Tomcat
- Liunx(CentOS7)中介軟體Weblogic的安裝與部署CentOSWeb
- Tomcat—部署配置及優化(安裝部署;虛擬主機配置;優化)Tomcat優化
- 安裝centos7最小化安裝CentOS
- CentOS7 安裝 memcacheCentOS
- Centos7安裝nginxCentOSNginx
- CentOS7 安裝 dockerCentOSDocker
- CentOS7 安裝 MySQLCentOSMySql
- CentOS7安裝RedisCentOSRedis
- Centos7 安裝ffmpegCentOS
- centos7安裝protobufCentOS
- 4.1 CentOS7安裝CentOS
- CentOS7 安裝NginxCentOSNginx
- centos7 安裝pipCentOS
- Centos7安裝RabbitMQCentOSMQ
- centos7安裝dockerCentOSDocker
- centos7安裝iptablesCentOS
- CentOS7安裝xrdpCentOS
- centos7 安裝rocketmqCentOSMQ
- centos7 安裝 rcloneCentOS
- centos7安裝mysqlCentOSMySql
- Centos7 安裝 NginxCentOSNginx
- Docker 安裝 TomcatDockerTomcat
- tomcat安裝使用Tomcat