1、GitLab类似github,是个私有仓库
1、GitLab安装,至少8G内存4核cpu
# 查找Gitlab镜像
docker search gitlab/gitlab-ce
# gitlab镜像拉取
docker pull gitlab/gitlab-ce
# 查看镜像
docker images
# 本机先建3个目录,为了gitlab容器通过挂载本机目录启动后可以映射到本机目录
# 配置文件
mkdir -p /home/gitlab/etc
# 数据文件
mkdir -p /home/gitlab/data
# 日志文件
mkdir -p /home/gitlab/logs
# 启动容器 mygitlab,如果不指定--hostname,默认使用的是容器id访问。
docker run --name mygitlab -d \
--hostname=10.1.1.118 \
-p 4443:443 -p 8888:80 -p 8022:22 \
-v /home/gitlab/etc:/etc/gitlab \
-v /home/gitlab/data:/var/opt/gitlab \
-v /home/gitlab/logs:/var/log/gitlab \
--privileged=true \
gitlab/gitlab-ce:latest
# 动态查看容器日志
docker logs -f mygitlab
# 配置http协议所使用的访问地址,不加端口默认为80
vim /home/gitlab/etc/gitlab.rb 加上下面这一行配置
external_url 'http://10.1.1.118'
/home/gitlab/data/gitlab-rails/etc/gitlab.yml,刚才启动容器指定的--hostname可在此配置文件查看
网页访问登入,http://10.1.1.118:8888
# 查看root用户默认密码
cat /home/gitlab/etc/initial_root_password
Password: Gsxzpjm/RwJgHlHIUJIOTFvfYnM19sC2VMPM7NTmCng=
登录成功后,修改密码
创建项目
直接像使用github一样,所有操作都一样。
# 本机需要安装git环境
yum install git -y
git --version
# 克隆项目
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
git config --global credential.helper store
# 注意点:需要配置端口8888
git clone http://10.1.1.118:8888/root/base-test.git
cd base-test
touch README.md
git add .
git commit -m "update"
git push -u origin master
设置免密提交
[root@node1 ~]# ssh-keygen -t rsa -b 4096 -C "admin@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:woYgeVBL3AKa5oQ2Rz722JDGPBaLo26Mqd9XNPzYhcQ admin@example.com
The key's randomart image is:
+---[RSA 4096]----+
|o+o+ . |
|o=O.= E |
|*B+/ . . . |
|*oB.Bo + . . |
|.. ..o+.S= . |
|+. . .o o |
|o+ . |
|o . . |
|... .. |
+----[SHA256]-----+
[root@node1 ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDBm6BA8cjS4bjQKOpvReIE8nHEVTnd9tT25jhcxiQU2Epx190bCe/VVxomYQdIFEeECjPzx3TCLMHHxd5rNFaw9hljJwcQuaODmil5g1LmQRFZqnKoTXc9a5VDtW5CZpyGcgrl8lsE2Bgdh95Bmqta64VOhhc5sLjuSY6X5HQjBOvMmg6WetdlAiUIWp4egTXMXzXqCHfRkLw9opuqQpITpCmUOl94PRNG8eqhHGr0o38c/OJmNKDFXx9ouuuRLUJWvmK+qCsyvMTSGlvw3bKxsFGQA2V+Gn6jCgzrEZI1tZakmhoGw8EvuIViRrAjgre1tfzsO424cGGpRElXBHwhYx10NTX+e6HwZfvRznDuPsvkIQ6TlNIX0CIy2UxN63x4w3ZP3kOa+ZL0XTaGbHcxJZ2GUgYjQrHzSbDQ7cKKqiazl2epukcV+osf19QoVnbsg9uIBMC3t+i28fl+byZoJCpxIF+5ItmsyUq770ryKfaWVMrCYI76tMQHFKVE7rEe/fg6c2RwQxcEPfHOl1UN3nVo82x0HfqtMbDRmUdDMJaCf5X/QIS6oKTg7HosjnRb1XOioPAvr8aF2R5Qa3djkFssIj7BdNTia1lg7AuaGypMRIDohbrNOtkspxmVAyw4UQaqMX5buGYdJa+rBHUOK/UAXzj/EGKQCtmlkXGxFQ== admin@example.com