系統:centos7.4
一、安裝配置必要的依賴
1、安裝ssh
sudo yum install -y curl policycoreutils-pythonopenssh-server
2、ssh設置開機啓動
sudo systemctl enable sshd
3、啓動ssh
sudo systemctl start sshd
4、添加http服務到firewalld,pemmanent表示永久生效,若不加--permanent系統下次啓動後就會失效
sudo firewall-cmd --permanent --add-service=http
如果沒有安裝防火牆,則安裝
yum install firewalld systemd -y
開啓防火牆
service firewalld start
5、重啓防火牆
sudo systemctl reload firewalld
6、接下來安裝postfix以發送通知電子郵件。如果要使用其他解決方案發送電子郵件,請跳過此步驟,並在安裝Gitlab後配置外部SMTP服務器
安裝命令
sudo yum install postfix
7、設置postfix開機啓動
sudo systemctl enable postfix
8、啓動postfix
sudo systemctl start postfix
如果出現以下提示
修改 /etc/postfix/main.cf的設置inet_protocols = ipv4和inet_interfaces = all
vim /etc/postfix/main.cf
二、添加Gitlab包存儲庫並安裝包
1、添加gitlab鏡像
wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.0.3-ce.0.el7.x86_64.rpm/download.rpm
2、安裝gitlab 安裝命令
rpm -i gitlab-ce-12.0.3-ce.0.el7.x86_64
安裝過程中,如果出現以下提示
執行以下命令,然後再執行gitlab安裝命令
yum install policycoreutils-python
出現以下畫面,則表示安裝成功
3、修改gitlab配置文件,指定服務器ip和自定義端口或者域名
vim /etc/gitlab/gitlab.rb
4、執行配置
gitlab-ctl reconfigure
5、啓動,如果出現如下界面就啓動成功,則可以訪問對應的域名或者IP地址
gitlab-ctl start
三、從阿里雲申請ssl證書
1、在阿里雲申請免費ssl證書,並下載到本地
2、解壓後,修改pem文件後綴爲crt
3、上傳crt文件和key到服務器上
四、nginx配置https
第一種方案:內置Nginx配置Https
1、修改/etc/gitlab/gitlab.rb,共修改四處
#修改域名爲https訪問
external_url 'https://gitlab.example.com'
#http重定向到https
nginx['redirect_http_to_https'] = true
#證書地址
nginx['ssl_certificate'] = "/var/opt/gitlab/nginx/conf/cert/jh_ssl.crt"
nginx['ssl_certificate_key'] = "/var/opt/gitlab/nginx/conf/cert/jh_ssl.key"
第二種方案:外置nginx配置Https
1、/etc/gitlab/gitlab.rb 設置
設置外部訪問地址
external_url 'https://git.example.com'
禁用內置的Nginx
nginx['enable'] = false
設置現有Nginx的用戶名,根據服務器安裝Nginx時創建的用戶名
web_server['external_users'] = ['nginx-user']
設置現有Nginx的受信代理
gitlab_rails['trusted_proxies'] = ['127.0.0.1']
2、執行配置生效命令和啓動命令
gitlab-ctl reconfigure
gitlab-ctl start
3、在nginx目錄新增文件名,例如:gitlab-nginx.conf,複製以下內容
upstream gitlab-workhorse {
server unix:/var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0;
}
server {
listen 80;
server_name git.example.com;
server_tokens off;
return 301 https://$http_host$request_uri;
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
}
server {
listen 443 ssl;
server_name git.example.com;
server_tokens off;
root /opt/gitlab/embedded/service/gitlab-rails/public;
ssl on;
ssl_certificate cert/git.example.com/git.example.com.pem;
ssl_certificate_key cert/git.example.com/git.example.com.key;
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
location / {
client_max_body_size 0;
gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://gitlab-workhorse;
}
}
其中修改幾項
A、git.example.com替換成需要的使用的域名
B、ssl_certificate、ssl_certificate_key分別填上傳到服務器的ssl文件地址
4、設置gitlab對應文件夾權限
chmod 777 /var/opt/gitlab/gitlab-workhorse
5、啓動nginx即可
cd /usr/local/nginx/sbin
./nginx -s reload