gitlab服務搭建
阿新 • • 發佈:2020-12-22
1.原因
新專案需要使用gitlab管理程式碼,在clone專案的時候一直提示輸入密碼,輸入密碼顯示許可權拒絕請重新輸入。反覆檢視原因仍然無法解決,最後決定伺服器重新搭建gitlab服務。
2.流程
2.1 伺服器資訊
[root@localhost ~]# uname -a Linux localhost.localdomain 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux [root@localhost ~]# cat /etc/system-release CentOS Linux release 7.8.2003 (Core)
2.2 安裝軟體
# 安裝依賴 sudo yum install -y curl policycoreutils-python openssh-server postfix # 啟動SSH和postfix sudo systemctl enable sshd sudo systemctl start sshd sudo systemctl enable postfix sudo systemctl start postfix # 開放埠(防火牆未開忽略) sudo firewall-cmd --add-service=ssh --permanent sudo firewall-cmd --add-service=http --permanent sudo firewall-cmd --reload # 安裝gitlab curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash sudo yum install -y gitlab-ce 最後一步安裝失敗多次,最後改用阿里雲的映象下載順利通過 # 修改阿里雲映象 1、備份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup or cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 2、下載新的CentOS-Base.repo 到/etc/yum.repos.d/ CentOS 5 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo CentOS 6 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 或者 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo CentOS 8 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo 3.新增EPEL源 EPEL(http://fedoraproject.org/wiki/EPEL)是由 Fedora 社群打造,為 RHEL 及衍生髮行版如 CentOS、Scientific Linux 等提供高質量軟體包的專案。裝上 EPEL後,可以像在 Fedora 上一樣,可以通過 yum install package-name,安裝更多軟體。 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo 4.清理快取並生成新的快取 yum clean all yum makecache
2.3配置
[root@node102 ~]# ll /etc/gitlab/ total 96 -rw------- 1 root root 97727 Nov 26 23:05 gitlab.rb [root@node102 ~]# [root@node102 ~]# cat /etc/gitlab/gitlab.rb |grep -v "#" |grep -Ev "^$" external_url 'http://gitlab.example.com' [root@node102 ~]# [root@node102 ~]# vim /etc/gitlab/gitlab.rb [root@node102 ~]# [root@node102 ~]# cat /etc/gitlab/gitlab.rb |grep -v "#" |grep -Ev "^$" external_url 'http://192.168.16.102' unicorn['listen'] = '192.168.16.102' unicorn['port'] = 8081 [root@node102 ~]# [root@test102 ~]# gitlab-ctl diff-config diff --git a/etc/gitlab/gitlab.rb b/opt/gitlab/etc/gitlab.rb.template index 3e27e40..31c0b45 100644 --- a/etc/gitlab/gitlab.rb +++ b/opt/gitlab/etc/gitlab.rb.template @@ -20,7 +20,7 @@ ##! URL on which GitLab will be reachable. ##! For more details on configuring external_url see: ##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab -external_url 'http://192.168.16.102' +external_url 'GENERATED_EXTERNAL_URL' ## Roles for multi-instance GitLab ##! The default is to have no roles enabled, which results in GitLab running as an all-in-one instance. @@ -740,8 +740,8 @@ external_url 'http://192.168.16.102' # unicorn['worker_processes'] = 2 ### Advanced settings -unicorn['listen'] = '192.168.16.102' -unicorn['port'] = 8081 +# unicorn['listen'] = 'localhost' +# unicorn['port'] = 8080 # unicorn['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket' # unicorn['pidfile'] = '/opt/gitlab/var/unicorn/unicorn.pid' # unicorn['tcp_nopush'] = true [root@test102 ~]# [root@node102 ~]# firewall-cmd --zone=public --permanent --add-port=8081/tcp success [root@node102 ~]# firewall-cmd --reload success [root@node102 ~]# [root@node102 ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 enp0s8 sources: services: ssh dhcpv6-client http ports: 8081/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@node102 ~]# [root@node102 ~]# gitlab-ctl reconfigure Starting Chef Client, version 14.13.11 resolving cookbooks for run list: ["gitlab"] Synchronizing Cookbooks: - gitlab (0.0.1) - package (0.1.0) - postgresql (0.1.0) - redis (0.1.0) - monitoring (0.1.0) - registry (0.1.0) - mattermost (0.1.0) - consul (0.1.0) - gitaly (0.1.0) - nginx (0.1.0) - praefect (0.1.0) - letsencrypt (0.1.0) - runit (4.3.0) - acme (4.0.0) - crond (0.1.0) Installing Cookbook Gems: Compiling Cookbooks... Recipe: gitlab::default ...... ...... ...... Recipe: <Dynamically Defined Resource> * service[alertmanager] action restart - restart service service[alertmanager] * service[postgres-exporter] action restart - restart service service[postgres-exporter] * service[grafana] action restart - restart service service[grafana] Running handlers: Running handlers complete Chef Client finished, 543/1455 resources updated in 04 minutes 09 seconds gitlab Reconfigured! [root@node102 ~]# [root@node102 ~]# gitlab-ctl status run: alertmanager: (pid 6469) 45s; run: log: (pid 6123) 128s run: gitaly: (pid 6335) 50s; run: log: (pid 5516) 263s run: gitlab-exporter: (pid 6380) 48s; run: log: (pid 5972) 146s run: gitlab-workhorse: (pid 6358) 49s; run: log: (pid 5882) 174s run: grafana: (pid 6529) 44s; run: log: (pid 6273) 74s run: logrotate: (pid 5920) 159s; run: log: (pid 5929) 158s run: nginx: (pid 5893) 171s; run: log: (pid 5905) 167s run: node-exporter: (pid 6367) 49s; run: log: (pid 5960) 152s run: postgres-exporter: (pid 6488) 45s; run: log: (pid 6150) 121s run: postgresql: (pid 5632) 255s; run: log: (pid 5644) 254s run: prometheus: (pid 6406) 47s; run: log: (pid 6080) 132s run: redis: (pid 5471) 272s; run: log: (pid 5479) 271s run: redis-exporter: (pid 6384) 48s; run: log: (pid 6003) 140s run: sidekiq: (pid 5842) 183s; run: log: (pid 5853) 180s run: unicorn: (pid 5803) 189s; run: log: (pid 5835) 186s [root@node102 ~]#
2.4 登陸
http://192.168.16.102 注意:這個地址是“external_url 'http://192.168.16.102'” 首次登入顯示為密碼設定介面,設定管理員密碼,管理員賬號預設username是root 設定完成之後,重新整理即可使用root賬號登入,登陸後會進入登陸頁面
3.gitlab操作
gitlab 基本操作建立使用者建立分組分配許可權,專案的建立,分支的合併等不細說。
4.備忘
預設儲存目錄為/var/opt/gitlab/git-data/repositories
如果要更新或增加儲存倉庫目錄,可以修改/etc/gitlab/gitlab.rb配置檔案中git_data_dirs部分的內容,然後執行“gitlab-ctl reconfigure”命令使之生效。
gitlab-ctl 常用操作
sudo gitlab-ctl upgrade # 元件更新(可選)
sudo gitlab-ctl stop # 停止服務
sudo rsync -av <old-dir> <new-dir>/ # 目錄同步(注意斜槓的作用)
ls <new-dir> # 檢查檔案及目錄層級
sudo gitlab-ctl start # 啟動服務
sudo gitlab-ctl reconfigure # 重配置
gitlab-ctl reconfigure # 過載配置
gitlab-ctl check-config # 檢查配置並啟動
gitlab-ctl diff-config # 將使用者配置與包可用配置進行比較
gitlab-ctl status # 檢視所有啟動元件的程序和狀態
gitlab-ctl service-list # 檢視所有服務
gitlab-ctl stop # 停止GitLab服務
gitlab-ctl start # 啟動GitLab服務
gitlab-ctl restart # 重啟GitLab服務
gitlab-ctl once # 如果GitLab服務已停止則啟動服務,如果GitLab服務已啟動則重啟GitLab服務
修改root密碼
https://docs.gitlab.com/ce/security/reset_root_password.html