最近搭建了一套java的ci/cd环境,记录下搭建过程😄�
注:下面演示软件安装在/opt
准备一台机器,内存8G以上 系统版本centos 7
image安装java
从oracle官网下载并解压
image
设置环境变量
vim /etc/profile
export JAVA_HOME=/opt/jdk1.8.0_201
export PATH=$JAVA_HOME/bin:/opt/rancher:/opt:/opt/apache-maven-3.6.0/bin:/opt/gitlab-runner:$PATH
安装nexus私服
编写私服docker-compose.yml
version: "3"
services:
nexus:
image: sonatype/nexus3
environment:
- INSTALL4J_ADD_VM_PARAMS=-Xms512m -Xmx768m -XX:MaxDirectMemorySize=1g -Djava.util.prefs.userRoot=/nexus-data/javaprefs
volumes:
- ./nexus-data:/nexus-data
ports:
- "8081:8081"
启动
mkdir nexus-data
chmod -R 777 nexus-data
docker-compose up -d
使用默认用户名密码 admin / admin123 登陆查看效果
image安装jenkins
wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
制作jenkins启动脚本
start_jenkins.sh
#!/bin/bash
export JAVA_HOME=/opt/jdk1.8.0_201
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/*.jar:$JRE_HOME/lib:$CLASSPATH
export JENKINS_SERVER_PATH=/opt/jenkins_server
cd ${JENKINS_SERVER_PATH}
# nohup java -jar jenkins.war --httpPort=8080 >/dev/null 2>&1 &
nohup java -jar jenkins.war --httpPort=8080 > jenkins.log &
设置开机启动
vim /etc/rc.local
/opt/jenkins_server/start_jenkins.sh
添加开发机
image安装jenkins插件
在jenkins插件中心安装以下插件: http://127.0.0.1:8080/pluginManager/available
名称 | 作用 |
---|---|
Publish Over SSH | 将文件发到目标服务器 |
SonarQube Scanner for Jenkins | 代码质量分析 |
Maven Integration plugin | maven打包 |
JaCoCo plugin | 自动测试并上报sonarqube |
gitlab | 连接gitlab代码库 |
安装docker
yum install -y docker
systemctl enable docker
systemctl start docker
安装gitlab
下载laradock工具包
git clone https://github.com/laradock/laradock.git && cp env-example .env
启动gitlab
cd laradock && docker-compose up -d gitlab
访问ip:8989查看效果
image
安装yearning
下载yearning docker工具包
git clone https://github.com/cookieY/Yearning.git
cd Yearning/install/yearning-docker-compose
docker-compose up -d
使用 默认账号:admin,默认密码:Yearning_admin 登陆查看效果
image安装sonarqube
下载sonarqube docker工具包
git clone https://github.com/thyrlian/SonarOnDocker.git
启动sonarqube
docker-compose -f docker-compose-mysql.yml up -d
访问9000端口,查看效果
image安装maven && graddle
从https://maven.apache.org/download.cgi下载maven并解压
从https://gradle.org/releases/下载gradle并解压
设置环境变量: vim /etc/profile
export JAVA_HOME=/opt/jdk1.8.0_201
export PATH=$JAVA_HOME/bin:/opt/rancher:/opt:/opt/apache-maven-3.6.0/bin:/opt/gradle-5.3.1/bin:/opt/gitlab-runner:$PATH
验证安装
image
安装kubectl && rancher cli
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
chmod +x kubectl
mv kubectl /opt/
从https://github.com/rancher/cli/releases下载rancher cli并解压
把rancher和kubectl加入环境变量
在rancher上创建api token并取得token内容
image
rancher cli配置token认证
rancher login https://rancherip:8843 -t rancher的token
最终目录结构
image image待后续更新...
网友评论