经验总结:
1、配置需求:云服务器内存最低4G
2、内存4G的云服务器,在运行容器后,会遇到云服务器操作卡顿问题,这里有解决方案
3、云服务器的操作系统会影响容器化的gitlab环境搭建,若有问题,重新装操作系统,这里我选择的是ubuntu 20.04,曾经也选择过Centos 7,但是创建gitlab 容器后,发现网络问题。
4、云服务器需要配置安全组的入方向规则,添加相应的协议端口
5、网址访问突然报502,重启容器发现报错如下
root@hecs-198528:~# docker restart gitlab
Error response from daemon: Cannot restart container gitlab: driver failed programming external connectivity on endpoint gitlab (042be20d8e5ebd6d0c71966020c46a46ec9a4adfb729a95a946cbb12a66738ce): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8888 -j DNAT --to-destination 172.17.0.2:80 ! -i docker0: iptables: No chain/target/match by that name.
(exit status 1))
解决方法:重启docker 服务后,重启容器
systemctl restart docker
docker start gitlab
详细操作步骤:
1、安装docker
apt install docker.io
2、下载gitlab docker 镜像
docker pull gitlab/gitlab-ce
3、执行docker 命令
建议运行在默认80端口上,不然后面git clone项目代码有麻烦
docker run --detach \
--publish 8443:443 --publish 80:80 --publish 8822:22 \
--name gitlab \
--restart always \
--volume /mydata/gitlab/config:/etc/gitlab \
--volume /mydata/gitlab/logs:/var/log/gitlab \
--volume /mydata/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
4、开启防火墙的指定端口
由于Gitlab运行在80端口上,所以我们需要开放该端口,注意千万不要直接关闭防火墙,否则Gitlab会无法启动。
开启80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙才能生效
systemctl restart firewalld
查看已经开放的端口
firewall-cmd --list-ports
5、配置云服务器的安全组入方向规则

6、浏览器访问
浏览器访问的网址是 ip:端口号,由于我配置的默认80端口,可以不加端口号,在网页上输入ip就可以了,正常访问是这样的

7、重置管理员密码
# 进入容器
docker exec -it 容器id /bin/bash
# 查看管理员密码
cat /etc/gitlab/initial_root_password

找到密码后,我们就可以使用root管理员账号登录了
重置密码

8、中文设置


9、添加密钥
生成ssh-key,默认一路回车即可
ssh-keygen

在~/.ssh/下会生成两个文件,id_rsa和id_rsa.pub
id_rsa是私钥
id_rsa.pub是公钥
添加ssh-key公钥到gitlab
登录gitlab,在右上角设置中找到SSH密钥


将刚才生成的公钥内容复制到密钥中,标题名字随意

