1.安装环境
服务器ip | 虚拟机版本 |
---|---|
192.168.5.132 | centos7.6 |
192.168.5.152 | centos7.6 |
2. 安装docker
安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
添加软件源信息,要确保centos7能上外网
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新并安装docker
yum makecache fast
yum -y install docker-ce
启动docker
service docker start
3. 安装docker-compose
curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
4. 安装jenkins
编写yaml文件
vim jenkins.yaml
version: '3.1'
services:
jenkins:
image: jenkins/jenkins:2.361.3
volumes:
- /data/jenkins/:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /usr/lib/x86_64-linux-gnu/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7
ports:
- "8080:8080"
expose:
- "8080"
- "50000"
privileged: true
user: root
restart: always
container_name: jenkins
environment:
JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'
启动容器
docker-compose -f jenkins.yaml up -d
jenkins访问地址
http://192.168.5.137:8080/
5. 安装gitlab
编写yaml文件
vim gitlab.yaml
version: '3.1'
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.5.152:8929'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '8929:8929'
- '2224:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
启动容器
docker-compose -f gitlab.yaml up -d
gitlab访问地址
http://192.168.5.152:8929/
查看gitlab初始密码
docker exec -it gitlab_gitlab_1 grep 'Password:' /etc/gitlab/initial_root_password
6. 配置两台服务器免密
jenkins服务器操作
ssh-keygen -t rsa
ssh-copy-id 192.168.5.152
gitlab服务器操作
ssh-keygen -t rsa
ssh-copy-id 192.168.5.137
7. 配置jenkins
安装必要插件
GitLab、Generic Webhook Trigger、Git Parameter、Publish Over SSH,安装完插件重启系统
配置密钥
cat /root/.ssh/id_rsa
将里面的密钥填的此处
新建任务
7. 配置gitlab