CentOS安装GitLab

安装GitLab

1.0> 安装 Postfix ,用于发送通知邮件

// 安装 postfix
yum install postfix
// 将 postfix 服务设置成开机自启动 
systemctl enable postfix
// 启动postfix
systemctl start postfix

2.0> 安装指定版本GitLab,

下载时会有多个系统版本可供选择,其中:el6代表适用于Centos6、el7代表适用于Centos7、el8代表适用于Centos8;

## 参见官网安装:https://about.gitlab.com/install/#centos-7

## 添加源
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
## 安装
yum install -y gitlab-ee

编辑gitlab配置文件,参见官网

vim /etc/gitlab/gitlab.rb

修改external_url访问路径

external_url 'http://localhost:8800/gitlabs/'

使配置生效

## 配置生效
sudo gitlab-ctl reconfigure
## 重启
gitlab-ctl restart

3.0> 配置nginx,添加配置文件

$ vim gitlab.conf 

添加如下内容:

server {
    listen 80;
    server_name  114.115.161.114;
    
    charset utf-8;
    location /gitlabs/ {

        # 客户端请求正文的最大允许大小
        # 这个大小的非常重要,如果git版本库里有大文件,设置的太小,文件push会失败,根据情况调整
        client_max_body_size 50m;

        # 安全相关 header
        # 禁止网站被嵌入到其它网页中,如:iframe、embed等,SAMEORIGIN表示该页面仅能在相同域名页面的iframe中展示
        add_header X-Frame-Options "SAMEORIGIN" always; 
        # 当检测到XSS攻击时阻止页面加载
        add_header X-XSS-Protection "1; mode=block" always;
        # 禁止请求类型为style和script时,但MIME类型却不为text/css和JavaScript的请求
        add_header X-Content-Type-Options "nosniff" always;
     
        proxy_pass http://localhost:8800;
     }

     # 防止爬虫抓取 
     if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot") { 
          return 403; 
     }
}

4.0> 重载nginx

sudo /usr/local/nginx/sbin/nginx -t
sudo /usr/local/nginx/sbin/nginx -s reload
或
sudo systemctl reload nginx

卸载GitLab

删除GitLab前,务必备份好数据

1.0> 停止GibLab服务

gitlab-ctl stop

2.0> 删除

gitlab-ctl uninstall;
yum remove gitlab-ce;


GitLib常用命令

## 启动
gitlab-ctl start

## 停止
gitlab-ctl stop

## 重启
gitlab-ctl restart

## 设为开机启动
systemctl enable gitlab-runsvdir.service


其它

配置GitLab域名访问

迁移/备份/恢复GitLab

修改GitLab的root用户密码


举报

© 著作权归作者所有


0