系统环境:
Centos7
机器要求:
4G内存,10GB磁盘空间
需要前置软件环境:
Java8(JRE 或者 JDK)
Docker
测试机信息:
IP 172.16.4.123; 内存3G ; 磁盘100G
参考官网的安装部署
创建宿主机Git挂载目录
#mkdir -p /srv/gitlab
#chmod +777 /srv/gitlab ###赋权可以在宿主机直接修改镜像的配置
执行docker镜像安装(设置别名方便查看日志)
sudo docker run --detach \
--hostname etcd2 \
--publish 443:443 --publish 8080:80 --publish 2222:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
--shm-size 256m \
gitlab/gitlab-ee:latest
安装成功后,会生成root的初始密码。通过以下命令查看
#sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
现在可以登陆Git的web端页面,记得重置密码。步骤如下:
登陆后在右上角头像→Preferences→Password
- 测试通过SSH key 访问git仓库.避免密码遗失或泄露
在客户端生成密钥
#ssh-keygen -t rsa -b 2048 -C "<comment>"
#cat ~/.ssh/id_rsa.pub
将内容复制到git→Preferences→SHH Keys ,其中Title可自定义,有效期根据需要自行设置。开通邮件功能后会每日提醒到期日期
验证是否可免密登陆git代码仓库
#ssh -T -p 2222 git@etcd2 ##因为docker映射的宿主机端口为2222,ssh测试使用2222端口
Welcome to GitLab, @root! ##返回以该提示,说明配置Gitlab上配置的SSh key生效
调测可执行以下命令
#ssh -Tvv -p 2222 git@etcd2
- 如有统一终端使用多账户登陆同一个Gitlab需求,可按以下参照在终端系统设置
创建2个账号:indentify 、warehouse
示例:ssh-keygen -t rsa -C "your_account_info" -f "id_rsa_filename"
#ssh-keygen -t rsa -b 2048 -C "zhengmh_indentify" -f "id_rsa_indentify"
#ssh-keygen -t rsa -b 2048 -C "zhengmh_warehouse" -f "id_rsa_warehouse_git"
将生成的公钥添加到Gitlab的SSH Keys中
在ssh目录下增加config配置
vi ~/.ssh/config
# User1 Account Identity
Host zmh_indentfy ###终端连接的git名称,可自定义区分
Hostname etcd2 ###实际的Git服务器
PreferredAuthentications publickey ###默认值
IdentityFile ~/.ssh/id_rsa_indentify ###对应的密钥
# User2 Account Identity
Host warehouse
Hostname etcd2
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_warehouse_git
# User3 Account Identity
Host indentfy
Hostname etcd2
Port 2222 ###指定连接的ssh端口
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_indentify
验证连接
[root@etcd3 .ssh]# ssh -T git@indentfy ###在config的User3中以指定ssh端口为2222
Welcome to GitLab, @root!
[root@etcd3 .ssh]# ssh -T -p 2222 git@zmh_indentfy
Welcome to GitLab, @root!
测试克隆远端的Gitlba资源仓库到本地,并对分支进行修改,提交到本地版本库并更新至远端的代码仓库
克隆 项目 indentify
[root@etcd3 data]# git clone git@indentfy:gitlab-instance-fbf6ad07/indentify.git
创建文件
[root@etcd3 indentify]#echo "first time" > test.txt
提交暂存区
[root@etcd3 indentify]#git add ./*
更新至版本库
[root@etcd3 indentify]#git commit -m 'add test.txt'
同步到远端的Gitlab代码仓库
[root@etcd3 indentify]#git remote add origin git@indentfy:gitlab-instance-fbf6ad07/indentify.git
登陆Gitlab 找到 indentify工程项目,发现增加test.txt文件