https://www.ilanni.com/?p=12819html
gitlab的安装能够分为源码安装和经过安装包进行安装,要是按照我之前的写做习惯的话,我也会把源码安装在本文章中提现,可是考虑到gitlab自己须要集成的软件比较多,因此在此咱们选择的是经过安装包进行安装的。nginx
gitlab经过安装包安装很简单的,咱们只须要下载对应的RPM包,进行安装便可。git
由于本次实验的OS是centos7,因此咱们直接从官网下载对应的RPM包便可,以下:redis
https://www.gitlab.com.cn/downloads/#centos7sql
sudo yum install curl policycoreutils openssh-server openssh-clientsvim
sudo systemctl enable sshdcentos
sudo systemctl start sshd安全
sudo yum install postfix服务器
sudo systemctl enable postfixsession
sudo systemctl start postfix
sudo firewall-cmd –permanent –add-service=http
sudo systemctl reload firewalld
按照上述操做便可完整gitlab的安装。
在此咱们只指出咱们在操做过程须要注意的地方,建议把gitlab的yum源修改成清华大学gitlab镜像源或者是浙大gitlab镜像源,缘由你懂得。
以下:
vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.zju.edu.cn/gitlab-ce/yum/el7/
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
sudo yum -y install gitlab-ce
sudo gitlab-ctl reconfigure
上图说明咱们已经把gitlab安装成功。
gitlab安装时会使用到nginx、redis、postgresql等相关软件,可是在实际使用过程当中,咱们想把redis和postgresql等分离出来使用,第三方或者本身搭建的软件。
要达到上述目的,咱们只须要修改gitlab的配置文件gitlab.rb,同时还要执行sudo gitlab-ctl reconfigure命令才能使gitlab.rb文件内容生效。
PS:如下全部配置项,咱们只给出当前正确的配置,不进行相关的讲解。
gitlab要使用阿里云的企业邮箱,咱们能够在gitlab配置文件gitlab.rb中添加以下配置:
vim /etc/gitlab/gitlab.rb
gitlab_rails[‘smtp_enable’] = true
gitlab_rails[‘smtp_address’] = “smtp.mxhichina.com”
gitlab_rails[‘smtp_port’] = 25
gitlab_rails[‘smtp_user_name’] = “gitlab@ilanni.com”
gitlab_rails[‘smtp_password’] = “ilanni6543”
gitlab_rails[‘smtp_domain’] = “ilanni.com”
gitlab_rails[‘smtp_authentication’] = “login”
gitlab_rails[‘smtp_enable_starttls_auto’] = true
gitlab_rails[‘gitlab_email_from’] = gitlab@ilanni.com
以上须要修改的地方,在这我就不一一点出来了,根据给出的英文单词就能猜想到它的意思。
要使此配置生效的话,须要咱们在gitlab服务器上执行sudo gitlab-ctl reconfigure命令便可。
gitlab要使用阿里云的提供的redis服务很简单,咱们只须要在gitlab中添加有关redis的相关配置便可,以下:
vim /etc/gitlab/gitlab.rb
redis[‘enable’] = false
gitlab_rails[‘redis_host’] = ‘r-bp15e6c8222ed4.redis.rds.aliyuncs.com’
gitlab_rails[‘redis_port’] = 6379
gitlab_rails[‘redis_password’] = ‘ilannisdfe’
上述命令中的redis[‘enable’] = false表示弃用gitlab自己的redis服务,其余的配置选项就是咱们常见的redis配置了。
gitlab要使用阿里云的提供的postgresql服务很简单,咱们只须要在gitlab中添加有关postgresql的相关配置便可,以下:
vim /etc/gitlab/gitlab.rb
postgresql[‘enable’] = false
gitlab_rails[‘db_username’] = “gitlab”
gitlab_rails[‘db_password’] = “123456”
gitlab_rails[‘db_host’] = “rm-bnjew04ee2r76086.pg.rds.aliyuncs.com”
gitlab_rails[‘db_port’] = 3433
上述命令中的postgresql[‘enable’] = false表示弃用gitlab自己的postgresql服务,其余的配置选项就是咱们常见的postgresql配置了。
gitlab与ldap集成是不属于阿里云产品的一部分的,可是既然本篇文章提到的基本上都是gitlab集成相关的东西,那么咱们就让其与ldap进行集成下。
gitlab与ldap进行集成,咱们只须要在gitlab.rb文件,添加以下配置便可:
vim /etc/gitlab/gitlab.rb
gitlab_rails[‘ldap_enabled’] = true
gitlab_rails[‘ldap_servers’] = YAML.load <<-EOS # remember to close this block with ‘EOS’ below
main: # ‘main’ is the GitLab ‘provider ID’ of this LDAP server
label: ‘LDAP’
host: ‘ldap.ilanni.com’
port: 389
uid: ‘uid’
method: ‘plain’ # “tls” or “ssl” or “plain”
bind_dn: ‘cn=admin,dc=ilanni,dc=com’
password: ‘ilanni123’
timeout: 10
active_directory: false
allow_username_or_email_login: true
base: ‘dc=ilanni,dc=com’
user_filter: ”
EOS
gitlab安装默认状况下是加载/var/opt/gitlab/nginx/conf目录下的gitlab-http.conf和nginx-status.conf两个nginx配置文件的,若是你要加载额外的nginx配置文件,也是须要咱们修改gitlab.rb文件的。
如今来举个例子,须要gitlab除了加载上述两个nginx配置文件外,还要加载/var/opt/gitlab/nginx/conf/81-http.conf文件。
gitlab.rb中配置,以下:
vim /etc/gitlab/gitlab.rb
nginx[‘custom_nginx_config’] = “include /var/opt/gitlab/nginx/conf/81-http.conf;”
gitlab默认状况下数据是存储在/var/opt/gitlab/git-data目录下的,若是咱们要把数据存储到另一个目录的话,咱们能够修改gitlab.rb文件中的git_data_dirs选项,以下:
vim /etc/gitlab/gitlab.rb
git_data_dirs({ “default” => { “path” => “/data/gitlab/git-data” } })
若是要修改gitlab显示时区的话,咱们也能够经过gitlab.rb文件的time_zone来达到目的,以下:
vim /etc/gitlab/gitlab.rb
gitlab_rails[‘time_zone’] = ‘Asia/Shanghai’
默认状况下gitlab使用的是http协议进行访问的,可是为了安全起见须要咱们使用https协议访问gitlab,要启用gitlab的https功能很简单,咱们只须要配置gitlab.rb文件便可。
vim /etc/gitlab/gitlab.rb
nginx[‘redirect_http_to_https’]=true
nginx[‘ssl_certificate’]=”/data/gitlab/sslkey/server.pem”
nginx[‘ssl_certificate_key’]=”/data/gitlab/sslkey/server.key”
此时gitlab-http.conf文件内容以下:
upstream gitlab-workhorse {
server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
server {
listen *:80;
server_name gitlab.ilanni.com;
server_tokens off; ## Don’t show the nginx version number, a security best practice
return 301 https://gitlab.ilanni.com:443$request_uri;
access_log /var/log/gitlab/nginx/gitlab_access.log gitlab_access;
error_log /var/log/gitlab/nginx/gitlab_error.log;
}
server {
listen *:443 ssl http2;
server_name gitlab.ilanni.com;
server_tokens off; ## Don’t show the nginx version number, a security best practice
client_max_body_size 0;
ssl on;
ssl_certificate /data/gitlab/sslkey/server.pem;
ssl_certificate_key /data/gitlab/sslkey/server.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 builtin:1000 shared:SSL:10m;
ssl_session_timeout 5m;
add_header Strict-Transport-Security “max-age=31536000”;
access_log /var/log/gitlab/nginx/gitlab_access.log gitlab_access;
error_log /var/log/gitlab/nginx/gitlab_error.log;
if ($http_host = “”) {
set $http_host_with_default “gitlab.ilanni.com”;
}
if ($http_host != “”) {
set $http_host_with_default $http_host;
}
gzip off;
proxy_read_timeout 3600;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $http_host_with_default;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Ssl on;
location / {
proxy_cache off;
proxy_pass http://gitlab-workhorse;
}
location /assets {
proxy_cache gitlab;
proxy_pass http://gitlab-workhorse;
}
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 /500.html;
error_page 502 /502.html;
location ~ ^/(404|422|500|502)(-custom)?\.html$ {
root /opt/gitlab/embedded/service/gitlab-rails/public;
internal;
}
}