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更新并安装dockeryum makecache fastyum -y install docker-ce启动dockerservice 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-composechmod +x /usr/local/bin/docker-compose
4. 安装jenkins
编写yaml文件vim jenkins.yamlversion: '3.1'
services:jenkins:image: jenkins/jenkins:2.361.3volumes:- /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.7ports:- "8080:8080"expose:- "8080"- "50000"privileged: trueuser: rootrestart: alwayscontainer_name: jenkinsenvironment:JAVA_OPTS: '-Djava.util.logging.config.file=/var/jenkins_home/log.properties'启动容器docker-compose -f jenkins.yaml up -djenkins访问地址http://192.168.5.137:8080/
5. 安装gitlab
编写yaml文件vim gitlab.yamlversion: '3.1'
services:gitlab:image: 'gitlab/gitlab-ee:latest'restart: alwayshostname: 'gitlab'environment:GITLAB_OMNIBUS_CONFIG: |external_url 'http://192.168.5.152:8929'gitlab_rails['gitlab_shell_ssh_port'] = 2224ports:- '8929:8929'- '2224:22'volumes:- './config:/etc/gitlab'- './logs:/var/log/gitlab'- './data:/var/opt/gitlab'启动容器docker-compose -f gitlab.yaml up -dgitlab访问地址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 rsassh-copy-id 192.168.5.152gitlab服务器操作ssh-keygen -t rsassh-copy-id 192.168.5.137
7. 配置jenkins
安装必要插件
GitLab、Generic Webhook Trigger、Git Parameter、Publish Over SSH,安装完插件重启系统
配置密钥
cat /root/.ssh/id_rsa
将里面的密钥填的此处
新建任务
7. 配置gitlab