Gitlab Centos7 搭建

默认分类 2018-11-09

搭建地址:https://www.cnblogs.com/wenwei-blog/p/5861450.html
Lnmp配合Gitlab域名访问:https://blog.csdn.net/peterxiaoq/article/details/73330302

我这里使用的是centos 7 64bit,我试过centos 6也是可以的!

  1. 安装依赖软件
  2. -y install policycoreutils openssh-server openssh-clients postfix

2.设置postfix开机自启,并启动,postfix支持gitlab发信功能
systemctl enable postfix && systemctl start postfix
3.下载gitlab安装包,然后安装
centos 6系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
centos 7系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
我的是centos7,所以我在https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7中找了个gitlab8.0.0版本,建议下载一个比较新的版本,我这里选了一个比较旧的版本仅仅是实验
下载rpm包并安装:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm
rpm -i gitlab-ce-8.0.0-ce.0.el7.x86_64.rpm
4.修改gitlab配置文件指定服务器ip和自定义端口:
vim /etc/gitlab/gitlab.rb
请输入图片描述

退出并保存

ps:注意这里设置的端口不能被占用,默认是8080端口,如果8080已经使用,请自定义其它端口,并在防火墙设置开放相对应得端口

5.重置并启动GitLab

执行:

gitlab-ctl reconfigure

gitlab-ctl restart

复制代码

ok: run: gitlab-git-http-server: (pid 3922) 1s
ok: run: logrotate: (pid 3929) 0s
ok: run: nginx: (pid 3936) 1s
ok: run: postgresql: (pid 3941) 0s
ok: run: redis: (pid 3950) 0s
ok: run: sidekiq: (pid 3955) 0s
ok: run: unicorn: (pid 3961) 1s

复制代码

提示“ok: run:”表示启动成功

6.访问 GitLab页面

如果没有域名,直接输入服务器ip和指定端口进行访问

初始账户: root 密码: 5iveL!fe

第一次登录修改密码
请输入图片描述

6.设置gitlab发信功能,需要注意一点:

发信系统用的默认的postfix,smtp是默认开启的,两个都启用了,两个都不会工作。

我这里设置关闭smtp,开启postfix

关闭smtp方法:vim /etc/gitlab/gitlab.rb

找到#gitlab_rails['smtp_enable'] = true 改为 gitlab_rails['smtp_enable'] = false

修改后执行gitlab-ctl reconfigure

另一种是关闭postfix,设置开启smtp,相关教程请参考官网https://doc.gitlab.cc/omnibus/settings/smtp.html

测试是否可以邮件通知:

登录并添加一个用户,我这里使用qq邮箱添加一个用户

登录qq邮箱,可以收到邮件通知(如果收不到,请查看垃圾邮箱或者检查邮件是否被拦截并删除,如果有请添加到白名单并删除用户再重新添加用户就可以收到了,否则请检查邮件日志并做好相关设置)
请输入图片描述

gitlab 安装自带 nginx,如果想利用原有 nginx,可按如下操作:

8.0 版本 socket 文件位置有变动,感谢评论区的同学。

nginx 增加虚拟主机配置

gitlab socket 文件地址

upstream gitlab {
# 7.x 版本在此位置
# server unix:/var/opt/gitlab/gitlab-rails/tmp/sockets/gitlab.socket;
# 8.0 位置
server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

server {
listen *:80;

server_name gitlab.liaohuqiu.com; # 请修改为你的域名

server_tokens off; # don't show the version number, a security best practice
root /opt/gitlab/embedded/service/gitlab-rails/public;

# Increase this if you want to upload large attachments
# Or if you want to accept large git objects over http
client_max_body_size 250m;

# individual nginx logs for this gitlab vhost
access_log /var/log/gitlab/nginx/gitlab_access.log;
error_log /var/log/gitlab/nginx/gitlab_error.log;

location / {

# serve static files from defined root folder;.
# @gitlab is a named location for the upstream fallback, see below
try_files $uri $uri/index.html $uri.html @gitlab;

}

# if a file, which is not found in the root folder is requested,
# then the proxy pass the request to the upsteam (gitlab unicorn)
location @gitlab {

# If you use https make sure you disable gzip compression 
# to be safe against BREACH attack

proxy_read_timeout 300; # Some requests take more than 30 seconds.
proxy_connect_timeout 300; # Some requests take more than 30 seconds.
proxy_redirect     off;

proxy_set_header   X-Forwarded-Proto $scheme;
proxy_set_header   Host              $http_host;
proxy_set_header   X-Real-IP         $remote_addr;
proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
proxy_set_header   X-Frame-Options   SAMEORIGIN;

proxy_pass http://gitlab;

}

# Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
# WARNING: If you are using relative urls do remove the block below
# See config/application.rb under "Relative url support" for the list of
# other files that need to be changed for relative url support
location ~ ^/(assets)/ {

root /opt/gitlab/embedded/service/gitlab-rails/public;
# gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;

}

error_page 502 /502.html;
}
禁用自带 nginx

vim /etc/gitlab/gitlab.rb
加入

nginx['enable'] = false
重启 nginx, 重启gitlab

sudo /usr/local/nginx/sbin/nginx -s reload
sudo gitlab-ctl reconfigure
权限配置

访问会报502。原本是 nginx 用户无法访问gitlab用户的 socket 文件,用户权限配置,因人而异。粗暴地:

sudo chmod -R o+x /var/opt/gitlab/gitlab-rails


本文由 布墨 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。
阅读:311

只有地板了

  1. zgcwkj
    zgcwkj

    踩一脚,我家的布墨

添加新评论