安裝Gitlab到CentOS(YUM)

<font face="宋體">

運行環境

系統版本:CentOS Linux release 7.3.1611 (Core) 軟件版本:Gitlab-ce-11.10.1 硬件要求:最低2核4GB,建議4核8GB

安裝過程

1、安裝依賴

[root@localhost ~]# yum -y install curl policycoreutils-python openssh-server 

2、配置系統環境

[root@localhost ~]# systemctl enable sshd                                                 => 設置SSH遠程服務開機自啓
[root@localhost ~]# systemctl start sshd                                                  => 啓動SSH遠程服務
[root@localhost ~]# systemctl stop firewalld                                              => 停止Firewalld防火牆服務
[root@localhost ~]# systemctl disable firewalld                                           => 禁用Firwalld防火牆服務開機自啓
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux => 關閉SeLinux(重啓主機生效)
[root@localhost ~]# setenforce 0                                                          => 關閉SeLinux(當前生效)

3、添加YUM-Gitlab源

我們使用清華大學提供的YUM源,以提高下載速度。

[root@localhost ~]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
[root@localhost ~]# yum makecache

4、安裝Gitlab

我們選擇安裝最新版本的Gitlab。

[root@localhost ~]# yum install -y gitlab-ce
可以訪問"https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/"查看Gitlab-ce的版本。
安裝歷史版本請使用下面命令:
[root@localhost ~]# yum install -y gitlab-ce-{VERSION}

5、配置Gitlab

建議使用HTTPS。

[root@localhost ~]# vim /etc/gitlab/gitlab.rb
### 基礎配置 ###
external_url 'https://gitlab.xxx.cn'
#用戶訪問所使用的URL,域名或者IP地址
gitlab_rails['time_zone'] = 'Asia/Shanghai'
#時區

### SSH配置 ###
gitlab_rails['gitlab_shell_ssh_port'] = 10222
#使用SSH協議拉取代碼所使用的連接端口。

### 郵箱配置 ###
gitlab_rails['smtp_enable'] = true
#啓用SMTP郵箱功能,綁定一個第三方郵箱,用於郵件發送
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
#設置SMTP服務器地址
gitlab_rails['smtp_port'] = 465
#設置SMTP服務器端口
gitlab_rails['smtp_user_name'] = "[email protected]"
#設置郵箱賬號
gitlab_rails['smtp_password'] = "xxx"
#設置郵箱密碼
gitlab_rails['smtp_authentication'] = "login"
#設置郵箱賬號密碼身份驗證方式,"login"表示採用賬號密碼的方式登陸
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
#設置開啓SMTP郵件使用TLS傳輸加密協議傳輸郵件,以保證郵件安全傳輸
gitlab_rails['gitlab_email_from'] = '[email protected]'
#設置Gitlab來源郵箱地址,設置登陸所使用的郵箱地址


### WEB配置 ###
nginx['enable'] = true
#啓用Nginx服務
nginx['client_max_body_size'] = '250m'
#設置客戶端最大文件上傳大小
nginx['redirect_http_to_https'] = true
#設置開啓自動將HTTP跳轉到HTTPS
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.xxx.cn.pem"
#設置HTTPS所使用的證書
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.xxx.cn.key"
#設置HTTPS所使用的證書密碼
nginx['ssl_protocols'] = "TLSv1.1 TLSv1.2"
#設置HTTPS所使用的TLS協議版本
nginx['ssl_session_cache'] = "builtin:1000  shared:SSL:10m"
#設置開啓SSL會話緩存功能
nginx['ssl_session_timeout'] = "5m"
#設置SSL會話超時時間
nginx['listen_addresses'] = ['*', '[::]']
#設置Nginx監聽地址,"*"表示監聽主機上所有網卡的地址
nginx['gzip_enabled'] = true
#設置開啓Nginx的傳輸壓縮功能,以節約傳輸帶寬,提高傳輸效率

6、上傳SSL證書到指定目錄

[root@localhost ~]# ll /etc/gitlab/ssl/
total 28
drwxr-xr-x 2 root root 4096 Apr 25 11:48 ./
drwxrwxr-x 4 root root 4096 Apr 25 12:50 ../
-rw-r--r-- 1 root root 1675 Apr 25 11:45 gitlab.xxx.cn.key
-rw-r--r-- 1 root root 3671 Apr 25 11:45 gitlab.xxx.cn.pem

7、刷新配置

當配置文件發生變化時,或者是第一次啓動時,我們需要刷新配置。
[root@localhost ~]# systemctl restart gitlab-runsvdir
[root@localhost ~]# gitlab-ctl reconfigure

8、啓動服務

[root@localhost ~]# gitlab-ctl restart
[root@localhost ~]# gitlab-ctl status
run: alertmanager: (pid 13541) 2171s; run: log: (pid 13221) 2192s
run: gitaly: (pid 13557) 2170s; run: log: (pid 12463) 2266s
run: gitlab-monitor: (pid 13580) 2169s; run: log: (pid 13103) 2208s
run: gitlab-workhorse: (pid 13602) 2169s; run: log: (pid 12887) 2226s
run: logrotate: (pid 13617) 2168s; run: log: (pid 12959) 2218s
run: nginx: (pid 13628) 2168s; run: log: (pid 12927) 2222s
run: node-exporter: (pid 13714) 2168s; run: log: (pid 13002) 2214s
run: postgres-exporter: (pid 13720) 2167s; run: log: (pid 13270) 2188s
run: postgresql: (pid 13740) 2167s; run: log: (pid 12669) 2258s
run: prometheus: (pid 13748) 2166s; run: log: (pid 13181) 2198s
run: redis: (pid 13761) 2166s; run: log: (pid 11907) 2293s
run: redis-exporter: (pid 13800) 2165s; run: log: (pid 13143) 2202s
run: sidekiq: (pid 13821) 2163s; run: log: (pid 12872) 2227s
run: unicorn: (pid 13833) 2162s; run: log: (pid 12832) 2233s

9、測試郵件發送

我們在啓動完成後測試一下郵件發送功能是否正常工作。

[root@localhost ~]# gitlab-rails console
irb(main):001:0> Notify.test_email('郵箱地址', '標題', '內容').deliver_now
irb(main):002:0> exit

10、第一次訪問登陸

第一次需要輸入新的超級管理員(root)密碼。 修改成功後,我們使用超級管理員用戶“root”賬號登錄Gitlab管理平臺。

11、關閉用戶註冊功能

爲了避免用戶隨便註冊賬號,我們將註冊功能關閉。

11、設置語言爲"簡體中文"

保存後重啓登陸即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章