天天看點

gitlab 安裝_Linux學習14CentOS安裝gitlab環境前言安裝依賴包gitlab安裝配置并啟動gitlab-ce502問題gitlab配置檢視相關操作

前言

在學習Gitlab的環境搭建之前,首先需要了解Git,Gitlab,GitHub他們三者之間的關系

Git 它是一個源代碼版本控制系統,可讓您在本地跟蹤更改并從遠端資源推送或提取更改。

GitHub 是一項公開可用的免費服務,它要求所有代碼(除非您有付費帳戶)公開。 任何人都可以看到您推送給GitHub的代碼并提供改進建議。

GitLab是一種類似github的服務,組織可以使用它來提供git存儲庫的内部管理。 它是一個自我托管的Git-repository管理系統,可以保持使用者代碼的私密性,并且可以輕松地部署代碼的更改。

簡單來說,github是全世界最大的開源的gay友平台,适合免費公開的代碼。gitlab是搭建本公司的代碼管理平台,适合私有的平台代碼管理。

因為本公司的代碼不想被其它人看到,這就需要搭建一個本公司的gitlab平台,供公司内部人員使用。

安裝依賴包

GitLab 10.x之後添加多了一些依賴,并且要啟動sshd服務,是以我們先添加依賴,啟動sshd,為防火牆添加服務

sudo yum install -y curl policycoreutils-python openssh-server 
openssh-clients 
sudo systemctl enable sshd 
sudo systemctl start sshd  

# 防火牆這2步可以不用管
# sudo firewall-cmd –permanent –add-service=http 
# sudo systemctl reload firewalld
           

postfix的産生是為了替代傳統的sendmail.相較于sendmail,postfix在速度。性能和穩定性上都更勝一籌。

如今眼下許多的主流郵件服務事實上都在採用postfix. 當我們須要一個輕量級的的郵件server是,postfix不失為一種選擇。

  • postfix想要作用的範圍是廣大的Internet使用者。試圖影響大多數的Internet上的電子郵件系統,是以它是免費的。
  • postfix在性能上大約比sendmail快三倍。一部執行postfix的台式PC每天能夠收發上百萬封郵件。
  • postfix是sendmail相容的,進而使sendmail使用者能夠非常友善地遷移到postfix。Postfix支援/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 檔案。
  • postfix被設計成在重負荷之下仍然能夠正常工作。當處理的郵件數目增長時,postfix執行的程序不會跟着添加。
  • postfix是由超過一打的小程式組成的,每一個程式完畢特定的功能。

gitlab配置需要用到郵件發送,是以先安裝postfix

yum -y install postfix

安裝完之後,啟動postfix

systemctl start postfix

啟動過程中如果報錯:Job for postfix.service failed because the control process exited with error code. See “systemctl status postfix.service” and “journalctl -xe” for details.

解決辦法,vim打開/etc/postfix/main.cf,修改如下兩項,修改之前可以先備份下

gitlab 安裝_Linux學習14CentOS安裝gitlab環境前言安裝依賴包gitlab安裝配置并啟動gitlab-ce502問題gitlab配置檢視相關操作
# 修改 /etc/postfix/main.cf的設定  

inet_protocols = ipv4  
inet_interfaces = all
           

修改完成後,再次啟動,就不會報錯了,設定postfix為開機自啟動

systemctl enable postfix

檢視啟動狀态,看到 Active: active (running) 就是已經正常啟動了

[[email protected] ~]# systemctl status postfix

完整的操作如下

[[email protected] ~]# yum -y install policycoreutils-python openssh-server openssh-clients
[[email protected] ~]# systemctl enable sshd 
[[email protected] ~]# systemctl start sshd[[email protected] ~]# yum -y install postfix
[[email protected] ~]# systemctl start postfix
Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.
[[email protected] ~]# cp /etc/postfix/main.cf  /etc/postfix/main.cf.bak
[[email protected] ~]# vim /etc/postfix/main.cf
# 修改inet_protocols = ipv4   和inet_interfaces = all  
[[email protected] ~]# systemctl start postfix
[[email protected] ~]# systemctl enable postfix
 [[email protected] ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-01-15 15:37:28 CST; 5min ago
  Process: 3171 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 3167 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 3164 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 3244 (master)
   CGroup: /system.slice/postfix.service
           ├─3244 /usr/libexec/postfix/master -w
           ├─3245 pickup -l -t unix -u
           └─3246 qmgr -l -t unix -u

Jan 15 15:37:27 yoyo systemd[1]: Starting Postfix Mail Transport Agent...
Jan 15 15:37:28 yoyo postfix/postfix-script[3242]: starting the Postfix mail system
Jan 15 15:37:28 yoyo postfix/master[3244]: daemon started -- version 2.10.1, configuration /etc/postfix
Jan 15 15:37:28 yoyo systemd[1]: Started Postfix Mail Transport Agent.
[[email protected] ~]#
           

gitlab安裝

GitLab官方文檔中有多種安裝方式,分别為deb,rpm,node,python,gem。詳情請看:https://packages.gitlab.com/gitlab/gitlab-ce/install

centos 7系統的下載下傳位址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

gitlab 安裝_Linux學習14CentOS安裝gitlab環境前言安裝依賴包gitlab安裝配置并啟動gitlab-ce502問題gitlab配置檢視相關操作

找個最新版去下載下傳gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm

下載下傳rpm包并安裝

[[email protected] ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
[[email protected] ~]# mkdir /usr/local/gitlab
[[email protected] ~]# mv gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm /usr/local/gitlab/
[[email protected] ~]# cd /usr/local/gitlab/
[[email protected] gitlab]# rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
error: Failed dependencies:
    policycoreutils-python is needed by gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

# 如果出現上面這個報錯就執行yum install policycoreutils-python
[[email protected] gitlab]# yum -y install policycoreutils-python

[[email protected] gitlab]# rpm -i gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
           

安裝完成之後,會出現gitlab官方文檔位址https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

配置并啟動gitlab-ce

gitlab安裝完成後,需要設定一個通路位址(或域名),打開

/etc/gitlab/gitlab.rb

,将預設的

external_url = 'http://git.example.com'

修改為自己的IP位址:

http://xxx.xx.xxx.xx

[[email protected] conf]# vim /etc/gitlab/gitlab.rb

原來預設的external_url

## GitLab URL
##! 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://git.example.com'
           

修改成自己定義的url位址,端口自己設定一個,别和已有的沖突了

## GitLab URL
##! 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://47.104.x.x:8100'
           

修改完成後:wq儲存退出,執行以下指令,讓配置生效

[[email protected] conf]# gitlab-ctl reconfigure

啟動Gitlab

[[email protected] conf]# gitlab-ctl start
[[email protected] ~]# gitlab-ctl start
ok: run: gitaly: (pid 6638) 186s
ok: run: gitlab-monitor: (pid 6656) 186s
ok: run: gitlab-workhorse: (pid 6659) 186s
ok: run: logrotate: (pid 6703) 185s
ok: run: nginx: (pid 6709) 185s
ok: run: node-exporter: (pid 6715) 184s
ok: run: postgres-exporter: (pid 6720) 184s
ok: run: postgresql: (pid 7324) 44s
ok: run: prometheus: (pid 6752) 171s
ok: run: redis: (pid 6761) 171s
ok: run: redis-exporter: (pid 6765) 170s
ok: run: sidekiq: (pid 7299) 45s
ok: run: unicorn: (pid 7476) 18s
           

啟動完成後,在浏覽器輸入

http://47.104.x.x:8100

,就是gitlab的登入首頁了,如果出現502頁面,需修改預設的8080端口

502問題

打開gitlab首頁出現502問題

gitlab 安裝_Linux學習14CentOS安裝gitlab環境前言安裝依賴包gitlab安裝配置并啟動gitlab-ce502問題gitlab配置檢視相關操作

出現這個問題,主要是因為8080端口被占用,之前安裝tomcat預設的是8080端口,netstat -ntpl檢視端口情況

[[email protected] ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9100          0.0.0.0:*               LISTEN      6715/node_exporter       
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      801/java      
tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      6709/nginx: master  
tcp        0      0 127.0.0.1:9121          0.0.0.0:*               LISTEN      6765/redis_exporter 
tcp        0      0 127.0.0.1:9090          0.0.0.0:*               LISTEN      6752/prometheus     
tcp        0      0 127.0.0.1:9187          0.0.0.0:*               LISTEN      6720/postgres_expor 
tcp        0      0 0.0.0.0:8100            0.0.0.0:*               LISTEN      6709/nginx: master  
tcp        0      0 127.0.0.1:8101          0.0.0.0:*               LISTEN      7495/unicorn master 
tcp6       0      0 :::3306                 :::*                    LISTEN      1370/mysqld
           

殺掉8080端口即可,8080端口對應的pip是801

[[email protected] ~]# kill -9 801

重新開機下服務,重新整理頁面就可以通路了

[[email protected] ~]# gitlab-ctl restart

為了避免8080端口沖突問題,可以修改下unicorn的預設端口,vim打開/etc/gitlab/gitlab.rb配置檔案

新增一項unicorn[‘port’] = 8101,修改後内容如下

## GitLab URL
##! 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://47.104.x.x:8100'

unicorn['port'] = 8101
           

修改完成後:wq儲存退出,執行gitlab-ctl reconfigure指令,讓配置生效,再重新啟動服務

[[email protected] conf]# gitlab-ctl reconfigure
[[email protected] conf]# gitlab-ctl stop
[[email protected] conf]# gitlab-ctl start
           

接着在浏覽器通路就能看的gitlab登入首頁了

gitlab 安裝_Linux學習14CentOS安裝gitlab環境前言安裝依賴包gitlab安裝配置并啟動gitlab-ce502問題gitlab配置檢視相關操作

gitlab配置檢視

gitlab的配置主要是etc/gitlab/gitlab.rb下的兩個地方

external_url 'http://47.104.x.x:8100'

unicorn['port'] = 8101
           

檢視更多配置資訊可以,在/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml檢視具體的詳情

 gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 47.104.x.x
    port: 8100
    https: false
           

相關操作

啟動服務:gitlab-ctl start

檢視狀态:gitlab-ctl status

停掉服務:gitlab-ctl stop

重新開機服務:gitlab-ctl restart

讓配置生效:gitlab-ctl reconfigure

2019年《python全棧自動化測試課程》2月16号開學!

主講老師:上海-悠悠

上課方式:QQ群視訊線上教學

上課時間:每周六、周日晚上20:30-22:30

2019年《python全棧自動化測試課程》2月16号開學!

繼續閱讀