寫在前面
有時候可能做項目組長,負責一個項目開發,但是工作是內網,也沒有公司的版本庫權限,那這個時候,我們怎么用處理版本控制,可以用集中式的版本庫工具SVN,或者分布式的Git,這里和小伙伴分享如何搭建自己的Git中文版本庫。
前提條件: 一臺可以連接外網的linux或者windows機器,當然可以是虛機或者ESC之類。或者只要可以裝Docker的機器就可以。
我深怕自己本非美玉,故而不敢加以刻苦琢磨,卻又半信自己是塊美玉,故有不肯庸庸碌碌,與瓦礫為伍。于是我漸漸地脫離凡塵,疏遠世人,結果便是一任憤懣與悔恨日益助長內心那怯弱的自尊心。其實任何人都是馴獸師,而那野獸,無非就是各人的性情而已。 -----中島敦《山月記》
服務器: liruilongs.github.io:192.168.26.55
一、docker 環境安裝
┌──[root@liruilongs.github.io]-[~]
└─$ yum -y install docker-ce
┌──[root@liruilongs.github.io]-[~]
└─$ systemctl enable docker --now
配置docker加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://2tefyfv7.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
二、安裝GitLab
1.安裝GitLab 并配置
拉取鏡像
┌──[root@liruilongs.github.io]-[~]
└─$ docker pull beginor/gitlab-ce
– |
|
2.創建共享卷目錄
創建共享卷目錄,用于持久化必要的數據和更改相關配置
┌──[root@liruilongs.github.io]-[~]
└─$ mkdir -p /data/gitlab/etc/ /data/gitlab/log /data/gitlab/data
┌──[root@liruilongs.github.io]-[~]
└─$ chmod 777 /data/gitlab/etc/ /data/gitlab/log /data/gitlab/data
3.創建 Gitlab 容器
這里的訪問端口一定要要設置成80,要不push項目會提示沒有報錯,如果宿主機端口被占用,需要把這個端口騰出來
┌──[root@liruilongs.github.io]-[~]
└─$ docker run -itd --name=gitlab --restart=always --privileged=true -p 8443:443 -p 80:80 -p 222:22 -v /data/gitlab/etc:/etc/gitlab -v /data/gitlab/log:/var/log/gitlab -v /data/gitlab/data:/var/opt/gitlab beginor/gitlab-ce
acc95b2896e8475915275d5eb77c7e63f63c31536432b68508f2f216d4fec634
┌──[root@liruilongs.github.io]-[~]
└─$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
acc95b2896e8 beginor/gitlab-ce "/assets/wrApper" 53 seconds ago Up 51 seconds (health: starting) 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:222->22/tcp, :::222->22/tcp, 0.0.0.0:8443->443/tcp, :::8443->443/tcp gitlab
┌──[root@liruilongs.github.io]-[~]
└─$
┌──[root@liruilongs.github.io]-[~]
└─$#
4.關閉容器修改相關配置文件
┌──[root@liruilongs.github.io]-[~]
└─$ docker stop gitlab
gitlab
external_url 'http://192.168.26.55’
┌──[root@liruilongs.github.io]-[~]
└─$ cat /data/gitlab/etc/gitlab.rb | grep external_url
##! For more details on configuring external_url see:
# external_url 'GENERATED_EXTERNAL_URL'
# registry_external_url 'https://registry.gitlab.example.com'
# pages_external_url "http://pages.example.com/"
# gitlab_pages['artifacts_server_url'] = nil # Defaults to external_url + '/api/v4'
# mattermost_external_url 'http://mattermost.example.com'
┌──[root@liruilongs.github.io]-[~]
└─$ sed -i "/external_url 'GENERATED_EXTERNAL_URL'/a external_urlt'http://192.168.26.55' " /data/gitlab/etc/gitlab.rb
┌──[root@liruilongs.github.io]-[~]
└─$ cat /data/gitlab/etc/gitlab.rb | grep external_url
##! For more details on configuring external_url see:
# external_url 'GENERATED_EXTERNAL_URL'
external_url 'http://192.168.26.55'
# registry_external_url 'https://registry.gitlab.example.com'
# pages_external_url "http://pages.example.com/"
# gitlab_pages['artifacts_server_url'] = nil # Defaults to external_url + '/api/v4'
# mattermost_external_url 'http://mattermost.example.com'
┌──[root@liruilongs.github.io]-[~]
└─$
gitlab_rails[‘gitlab_ssh_host’] = '192.168.26.55’
┌──[root@liruilongs.github.io]-[~]
└─$ cat /data/gitlab/etc/gitlab.rb | grep gitlab_ssh_host
# gitlab_rails['gitlab_ssh_host'] = 'ssh.host_example.com'
┌──[root@liruilongs.github.io]-[~]
└─$ sed -i "/gitlab_ssh_host/a gitlab_rails['gitlab_ssh_host'] = '192.168.26.55' " /data/gitlab/etc/gitlab.rb
┌──[root@liruilongs.github.io]-[~]
└─$ cat /data/gitlab/etc/gitlab.rb | grep gitlab_ssh_host
# gitlab_rails['gitlab_ssh_host'] = 'ssh.host_example.com'
gitlab_rails['gitlab_ssh_host'] = '192.168.26.55'
┌──[root@liruilongs.github.io]-[~]
└─$
gitlab_rails[gitlab_shell_ssh_port] = 222
┌──[root@liruilongs.github.io]-[~]
└─$ cat /data/gitlab/etc/gitlab.rb | grep gitlab_shell_ssh
# gitlab_rails['gitlab_shell_ssh_port'] = 22
┌──[root@liruilongs.github.io]-[~]
└─$ sed -i "/gitlab_shell_ssh_port/a gitlab_rails['gitlab_shell_ssh_port'] = 222" /data/gitlab/etc/gitlab.rb
┌──[root@liruilongs.github.io]-[~]
└─$ cat /data/gitlab/etc/gitlab.rb | grep gitlab_shell_ssh
# gitlab_rails['gitlab_shell_ssh_port'] = 22
gitlab_rails[gitlab_shell_ssh_port] = 222
┌──[root@liruilongs.github.io]-[~]
└─$
/data/gitlab/data/gitlab-rails/etc/gitlab.yml
┌──[root@liruilongs.github.io]-[~]
└─$ vim /data/gitlab/data/gitlab-rails/etc/gitlab.yml
┌──[root@liruilongs.github.io]-[~]
└─$
##############################
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: 192.168.26.55
port: 80
https: false
– |
|
修改完配置文件之后。直接啟動容器
┌──[root@liruilongs.github.io]-[~]
└─$ docker start gitlab
5.訪問測試
訪問測試 |
在宿主機所在的物理機訪問,http://192.168.26.55/ ,會自動跳轉到修改密碼(root用戶),如果密碼設置的沒有滿足一定的復雜性,則會報500,需要從新設置 |
|
|
登錄進入儀表盤 |
三、新建項目,push代碼測試
新建一個項目,push代碼測試 |
|
|
|
然后我們簡單測試一下,push一個項目上去 |
|
項目成功上傳Gitlab |
|
|
PS F:blogger> git init
Initialized empty Git repository in F:/blogger/.git/
PS F:blogger> git config --global user.name "Administrator"
PS F:blogger> git config --global user.email "admin@example.com"
PS F:blogger> git remote add origin http://192.168.26.55/root/blog.git
PS F:blogger> git add .
PS F:blogger> git commit -m "Initial commit"
PS F:blogger> git push -u origin master
Enumerating objects: 322, done.
Counting objects: 100% (322/322), done.
Delta compression using up to 8 threads
Compressing objects: 100% (302/302), done.
Writing objects: 100% (322/322), 11.31 MiB | 9.22 MiB/s, done.
Total 322 (delta 24), reused 0 (delta 0)
remote: Resolving deltas: 100% (24/24), done.
To http://192.168.26.55/root/blog.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
PS F:blogger>
時間原因,關于 【搭建自己的中文Git版本庫】先分享到這里。生活加油 ^ _ ^