目錄
- Gitlab
- 1. 使用docker部署gitlab
- 2. 登入gitlab
- 2.1 修改語言為中文
- 2.3 修改密碼
- 3. 使用者管理
- 3.1 建立使用者
- 4. 配置ssh拉取程式碼
- 4.1 新增ssh金鑰
- 4.2 測試拉取
Gitlab
1. 使用docker部署gitlab
[root@master ~]# mkdir -p /data/gitlab/{config,logs,data}
編寫docker-compose.yaml
[root@master ~]# mkdir gitlab
[root@master ~]# vim docker-compose.yaml
version: '3.3'
services:
gitlab:
hostname: gitlab
container_name: gitlab
restart: always
ports:
- "443:443"
- "80:80"
- "2222:22"
volumes:
- "/data/gitlab/config:/etc/gitlab"
- "/data/gitlab/logs:/var/log/gitlab"
- "/data/gitlab/data:/var/opt/gitlab"
# 這裡的映象自己改地址,目前國內不能直接訪問dockerhub
image: gitlab/gitlab-ce
environment:
GITLAB_OMNIBUS_CONDIG: |
# 對外的地址
external_url 'http://gitlab.hcie.com'
gitlab_rails['gitlab_shell_ssh_port'] = 2222
# smtp是郵件,為了安全,gitlab建立賬戶之後不能直接設定密碼,而是給郵箱發一個郵件,透過郵件裡的連結去改密碼,這裡先讓他啟動,後面可以進web介面修改
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.hcie.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "notify@hcie.com"
gitlab_rails['smtp_password'] = "xxxx"
gitlab_rails['smtp_domain'] = "smtp.hcie.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_openssl_verify_mode'] = "peer"
gitlab_rails['gitlab_email_from'] = "notify@hcie.com"
gitlab_rails['gitlab_email_display_name'] = "gitlab"
user["git_user_email"] = "notify@hcie.com"
nginx["client_max_body_size"] = "0"
啟動gitlab
[root@master gitlab]# docker-compose up -d
2. 登入gitlab
等待他啟動之後我們檢視預設密碼
[root@master gitlab]# docker exec -it gitlab bash
root@gitlab:/# cat /etc/gitlab/initial_root_password
root@gitlab:/# cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: JF6/7g7iH/iUX5hP2eJ4c6WVBYKe2sW1HZXu3o02HYA=
這裡的就是密碼了,只能使用24小時
- 預設使用者名稱 root
2.1 修改語言為中文
將這裡修改問中文
2.3 修改密碼
因為臨時密碼只能使用24小時,所以得修改一下密碼
修改完中文之後點選一下旁邊的密碼就可以修改了
-
當前密碼就是那個臨時密碼
-
如果你的介面還是英文就重新整理一下頁面
3. 使用者管理
3.1 建立使用者
點進去之後就會有一個使用者
- 這裡的電子郵件地址不能亂填,之前就說過,他是會給這個郵件地址傳送一封郵件,點選郵件裡的連結才可以改密碼的
- 但是我們之前的smtp服務都是瞎寫的,郵件他肯定是發不出去的
- 我們可以先建立使用者之後點選編輯,可以給他設定密碼
4. 配置ssh拉取程式碼
如果使用http的方式去拉取程式碼的話,如果專案是私有的,那麼每次都是需要登入的,但是在內部使用我們可以使用ssh的方式去拉取,這樣就不用登入了
4.1 新增ssh金鑰
-
將你自己的公鑰放在這
-
公鑰路徑
[root@master test]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCbmEeD5QoRO+iDNIEANlLRU9N0vESKTEdjiUBrxaRk81qXeX4+SBC0fq5iVye9eUQ9QYP+ACOe1e/inGyPX4jAZVY6cNuCIkkIsPKrClkmQGovg/vE6QVIxiOzrFa38O+hGxuqtDVCRPAjTeGSdsU50ZlkvPlFf/R3Ja59BaxwPCTpomtF6Id1gvIdVmfNV1IsGaBjMOcNE24NVzKBwTUyR8MPw+or1uO5+5CGawCMJDQSsVl1KW5CASLcef5TJKq/Z9dDfKWTXEedPl+Ic6DgCCZ4Tyi372C2QUU3Vo78ugsdXW7zjWn/fH4j7vjYiO1eZqdXUxNyJMyB00ASF2ULQ9igAd/c3SvtomKPg+R94p40Nq/UpE8dlUzNFVCHFCEpBsoi8LPlcqmhhOpjv8Q2IESOn2pwZcl9a8T9txsdeCnX93k6my4iEE2ay3xddq/EJKRzbIAmRxjiqjixBtBaqR9qbud4JDgz1mHh6Gsk2Vdui0FslAtqXEFkDiT4s7M= root@master
4.2 測試拉取
[root@master workspace]# mkdir test1
[root@master test1]# git clone ssh://git@gitlab:2222/devops/app.git
Cloning into 'app'...
The authenticity of host '[gitlab]:2222 ([192.168.200.200]:2222)' can't be established.
ED25519 key fingerprint is SHA256:EB9YH9NMwMG5kxg7lYd8nyJdDwebSOiWH0zdXPHTmv0.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[gitlab]:2222' (ED25519) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), done.
[root@master test1]#
這個時候他就沒有讓我們輸入密碼了
注意配置主機的hosts解析