安装docker
001 上传docker的repo
cd /etc/yum.repos.d/
put docker-ce.repo
002 安装docker并启动docker服务
yum -y install docker-ce
systemctl enable docker && systemctl start docker
003 配置镜像下载加速器
vi /etc/docker/daemon.json
{
"debug":true,"experimental":true,
"registry-mirrors":["https://pb5bklzr.mirror.aliyuncs.com","https://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"]
}
#配置完后重启
systemctl enable docker && systemctl start docker
004 删除某个容器
[root@localhost ~]# docker rm -f fccb33da83a4
005 查看容器日志
[root@localhost ~]# docker logs fccb33da83a4 -f
安装Gitlab
001 docker加载相关包
[root@localhost ~]# docker load -i gitlab.tar
......
370ece9304e9: Loading layer [==================================================>] 1.781GB/1.781GB
Loaded image: gitlab/gitlab-ce:latest
002 启动docker
#创建持久化文件夹
[root@localhost ~]# mkdir /opt/gitlab
#设置并查看全局变量
[root@localhost ~]# GITLAB_HOME=/opt/gitlab
[root@localhost gitlab]# echo $GITLAB_HOME
/opt/gitlab
#启动gitlab服务
docker run --detach \
--hostname gitlab.pcitc.com \
--publish 443:443 --publish 80:80 --publish 2222:22 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
003 登录gitlab
root
12345678(初始化设置)
Gitlab邮件配置
001 进入容器
[root@localhost ~]# docker exec -it gitlab bash
root@gitlab:/# vi /etc/gitlab/gitlab.rb
002 修改相关配置文件
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "BBTGIGYUNBZNNQEB"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
003 重启相关配置
root@gitlab:/# gitlab-ctl reconfigure
004 测试邮件是否配置成功
gitlab-rails console
irb(main):001:0> Notify.test_email('[email protected]', 'test Gitlab', 'test Gitlab').deliver_now
irb(main):002:0> exit
配置https
001 证书准备
[root@bogon cfssl]# tar -xzvf cfssl.tar.gz
cfssl
cfssl-certinfo
cfssljson
[root@bogon cfssl]# mv cfssl* /usr/bin
002 修改certs.sh的域名并生成证书
[root@bogon cfssl]# chmod 777 certs.sh
[root@bogon cfssl]# ./certs.sh
003 配置文件映射
--volume $GITLAB_HOME/config:/etc/gitlab
--volume $GITLAB_HOME/logs:/var/log/gitlab
--volume $GITLAB_HOME/data:/var/opt/gitlab
004 上传证书文件到/etc/gitlab/ssl目录
[root@bogon config]# cd /opt/gitlab/config
[root@bogon config]# mkdir ssl
[root@bogon cfssl]# cp -r gitlab.pcitc.com.pem /opt/gitlab/config
[root@bogon cfssl]# cp -r gitlab.pcitc.com-key.pem /opt/gitlab/config
005 修改配置文件证书
[root@localhost ~]# docker exec -it gitlab bash
root@gitlab:/# vi /etc/gitlab/gitlab.rb
-------------------------------------------------------------------
external_url 'https://gitlab.pcitc.com'
nginx['enable'] = true
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.pcitc.com.pem"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.pcitc.com-key.pem"
-------------------------------------------------------------------------
#重新加载配置:
gitlab-ctl reconfigure
006 登录验证
https://gitlab.pcitc.com/
创建用户
001 进入创建用户页面
管理中心-New user
002 编辑用户
为该用户赋初始化密码
003 新用户登录验证
新用户登录,修改新密码
用新密码登录
创建群组
001 新建群组
新建群组test
002 新建项目
该群组下新建项目
该项目下新建自述文件和html文件
003 群组邀请成员
进入test项目
添加成员
赋予权限
将用户加入群组
该用户的账号登录后可发现该项目
Gitlab使用流程
001 clone版本库
#可能出现问题
fatal: unable to access 'https://gitlab.pcitc.com/test/cs.git/': Issuer certificate is invalid.
#问题解决
[root@localhost gitlab]# git config --global http.sslVerify false
#clone新项目
[root@localhost gitlab]# git clone https://gitlab.pcitc.com/test/cs.git
正克隆到 'cs'...
Username for 'https://gitlab.pcitc.com': lql
Password for 'https://[email protected]':
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
002 配置使用者
[root@localhost cs]# git config --global user.name lql
[root@localhost cs]# git config --global user.email [email protected]
[root@localhost cs]# git config --list
http.sslverify=false
user.name=lql
[email protected]
......
[root@localhost cs]# cat .git/config
[remote "origin"]
url = https://gitlab.pcitc.com/test/cs.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
#查看分支
[root@localhost cs]# git branch
* master
003 新建开发分支
[root@localhost cs]# git branch dev
[root@localhost cs]# git branch
dev
* master
[root@localhost cs]# git checkout dev
切换到分支 'dev'
[root@localhost cs]# git branch
* dev
master
[root@localhost cs]# vi login.html
004 将本地代码推送到远程服务器
[root@localhost cs]# git add login.html
[root@localhost cs]# git commit -m 'login'
[dev 95e1e63] login
1 file changed, 1 insertion(+)
create mode 100644 login.html
[root@localhost cs]# git push origin dev
Gitlab 备份
001 数据备份
[root@localhost ~]# docker exec -it gitlab gitlab-rake gitlab:backup:create
[root@localhost backups]# pwd
/opt/gitlab/data/backups
[root@localhost backups]# ls
1634109464_2021_10_13_13.3.5_gitlab_backup.tar
002 配置文件备份
[root@localhost ~]# docker exec -it gitlab gitlab-ctl backup-etc
[root@localhost config_backup]# pwd
/opt/gitlab/config/config_backup
[root@localhost config_backup]# ls
gitlab_config_1634109543_2021_10_13.tar
Gitlab 恢复
001 准备新环境
[root@localhost config_backup]# docker stop gitlab
gitlab
[root@localhost config_backup]# docker rm -f gitlab
gitlab
[root@localhost opt]# mv gitlab gitlabbak
002 拷贝数据备份文件
#宿主机执行
[root@localhost backups]# cp -r /opt/gitlabbak/data/backups/1634109464_2021_10_13_13.3.5_gitlab_backup.tar /opt/gitlab/data/backups
003 为数据备份文件添加备份权限
[root@localhost backups]# docker exec -it gitlab bash
root@gitlab:/# chown git.git /var/opt/gitlab/backups/1634109464_2021_10_13_13.3.5_gitlab_backup.tar
004 停写库服务
root@gitlab:/# gitlab-ctl stop unicorn
root@gitlab:/# gitlab-ctl stop puma
ok: down: puma: 0s, normally up
root@gitlab:/# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
005 执行恢复数据命令
root@gitlab:/# gitlab-rake gitlab:backup:restore BACKUP=1634109464_2021_10_13_13.3.5
006 恢复配置文件
#宿主机
[root@localhost config]# cp /opt/gitlabbak/config/config_backup /opt/gitlab/config/ -rf
#进入容器
root@gitlab:/etc# cd /etc/gitlab/config_backup/
#查看配置文件tar
root@gitlab:/etc/gitlab/config_backup# ls
gitlab_config_1634109543_2021_10_13.tar
#解压缩
root@gitlab:/etc/gitlab/config_backup# tar xvf gitlab_config_1634109543_2021_10_13.tar
#进入解压缩路径
root@gitlab:/etc/gitlab/config_backup/etc/gitlab# pwd
/etc/gitlab/config_backup/etc/gitlab
#复制相关文件到容器的配置目录下
root@gitlab:/etc/gitlab/config_backup/etc/gitlab# cp -r gitlab.rb /etc/gitlab/
root@gitlab:/etc/gitlab/config_backup/etc/gitlab# cp -r gitlab-secrets.json /etc/gitlab/
root@gitlab:/etc/gitlab/config_backup/etc/gitlab# cp -r gitlab.pcitc.com.pem /etc/gitlab/
root@gitlab:/etc/gitlab/config_backup/etc/gitlab# cp -r gitlab.pcitc.com-key.pem /etc/gitlab/
root@gitlab:/etc/gitlab/config_backup/etc/gitlab# cp ssl /etc/gitlab -rf
007 重新启动容器
[root@localhost backups]# docker restart gitlab
gitlab