前言
本案例安装 gitlab、jenkins、并部署springboot应用程序,所以准备了3台服务器。
`服务器1:安装gitlab
服务器2:安装jdk、maven、git、jenkins
因为jenkins需要jdk、maven、git
服务器3:安装jdk。
jenkins自动部署的springboot应用程序在服务器3
注意:以上springboot项目中用到的java版本与服务器2,服务器3中安装的一致
我虚拟机模拟搭建时版本如下:
- jdk : jdk-11.0.16.1
- maven : 3.8.6
- jenkins : Jenkins 2.361.4 LTS
- springboot : 2.7.1
一、安装gitlab
gitlab中文官网
英文官网
1、手动安装gitlab
官方安装
1)查看内存是否符合条件
内存大于4G
[root@VM-16-2-centos ~]# free -m
total used free shared buff/cache available
Mem: 7725 231 7262 0 231 7260
Swap: 0 0 0
2)安装依赖
yum install -y curl policycoreutils-python openssh-server perl
systemctl enable sshd
systemctl start sshd
3)配置镜像
curl -fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash
4)安装gitlab
EXTERNAL_URL="http://192.168.109.144" yum install -y gitlab-jh
2、docker安装gitlab
1)安装gitlab
restart aways:开机自启动
docker run --detach \
--hostname 192.168.109.144 \
--publish 443:443 --publish 80:80 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab:z \
--volume $GITLAB_HOME/logs:/var/log/gitlab:z \
--volume $GITLAB_HOME/data:/var/opt/gitlab:z \
--shm-size 256m \
registry.gitlab.cn/omnibus/gitlab-jh:latest
查看镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.gitlab.cn/omnibus/gitlab-jh latest ead385313244 2 days ago 3.03GB
2)启动gitlab
整体如下:
[root@localhost ~]# docker start gitlab
gitlab
3)查看容器,进入容器,查看密码
docker ps -a
docker exec -it gitlab /bin/bash
cat /etc/gitlab/initial_root_password
整体如下:
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c2c7bd2c196a registry.gitlab.cn/omnibus/gitlab-jh:latest "/assets/wrapper" 6 minutes ago Up 6 minutes (unhealthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 22/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp gitlab
[root@localhost ~]# docker exec -it gitlab /bin/bash
root@192:/# cd /etc/gitlab/
root@192:/etc/gitlab# ll
total 184
drwxrwxr-x. 3 root root 268 Nov 16 09:28 ./
drwxr-xr-x. 1 root root 66 Nov 16 09:27 ../
-rw-------. 1 root root 19349 Nov 16 09:28 gitlab-secrets.json
-rw-------. 1 root root 138956 Nov 16 09:27 gitlab.rb
-rw-------. 1 root root 749 Nov 16 09:28 initial_root_password
-rw-------. 1 root root 513 Nov 16 09:27 ssh_host_ecdsa_key
-rw-r--r--. 1 root root 182 Nov 16 09:27 ssh_host_ecdsa_key.pub
-rw-------. 1 root root 411 Nov 16 09:27 ssh_host_ed25519_key
-rw-r--r--. 1 root root 102 Nov 16 09:27 ssh_host_ed25519_key.pub
-rw-------. 1 root root 2610 Nov 16 09:27 ssh_host_rsa_key
-rw-r--r--. 1 root root 574 Nov 16 09:27 ssh_host_rsa_key.pub
drwxr-xr-x. 2 root root 6 Nov 16 09:28 trusted-certs/
root@192:/etc/gitlab# cat initial_root_password
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: bvWqJ2Dg+eOhI+E5Lu6695yoPfJoiwoBH+4aLsXnQM4=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
root@192:/etc/gitlab#
进入容器查看默认生成的密码密码存在/etc/gitlab/initail_root_password中
4)登录并修改密码
访问网址:http://192.168.109.144
用户名:root
密码:密码存在/etc/gitlab/initail_root_password中,24小时后会过期,所以登陆后需要修改密码。
开始修改密码:主菜单——》管理员——》用户——》编辑密码——》保存更改
5)重新登录验证新密码是否生效
二、IDEA新建本地项目关联远程本地仓库和git仓库
1、创建本地项目,配置maven
2、创建本地Git仓库
选择VCS——》Create Git Repository——》跳出弹框选择需要版本控制的项目,ok
3、将本地项目提交到本地仓库
4、连接远程仓库
5、推送代码push
总结:遇到的问题
1)关联远程仓库时遇到如下问题:
原因:
解决:
将当前用户加入到gitlab本项目仓库权限中
进入项目跟目录.git路径下编辑config文件
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true[remote "origin"] url = http://qlx:qwedsa123@192.168.109.144/root/test1.git