Linux-安装-Gitlab


time 20191203

author Venki


目录指引
gitlab安装
  1. 准备说明
  • CPU内核2个以上
  • 运行内存4G(虽说官方要求2G以上,但是还是会经常出现卡顿,毕竟一般不可能用一台服务器专门部署gitlab,还有其他服务同时并行,所以,最好还是4G以上吧)
  • 我的操作心态是centOs7.7
  1. 开始安装
  • 配置yum源
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
  • 更新本地yum缓存
yum makecache
  • 安装GitLab社区版
# 自动安装最新版
yum install gitlab-ce

# 安装指定版本
yum install gitlab-ce-x.x.x
  • 初始化gitlab
# 第一次初始化时间较久,大概4-5min
gitlab-ctl reconfigure
  • 访问

如果服务器上面没有部署其他web服务器,那么直接输入服务器IP地址即可进行访问,但是因为我的服务器上面已经部署了Nginx,所以,我是首先停掉Nginx然后在进行访问,测试成功,那么接下来,我要做的就是如何将gitlab默认的服务器更换成我配置的服务器

gitlab汉化

回到顶部

暂时不进行汉化,英文版的比较好,毕竟是一名程序员,使用原生态的。

gitlab服务器更换

回到顶部

  1. 将服务部署到内网
# 直接在Windowshosts文件中配置如下即可 cms(code management system)
192.168.1.243 gd.cms.com

# 浏览器输入域名即可解析
  1. 更换成自己的Nginx服务器
  • 禁用gitlab自带的Nginx服务器
vi /etc/gitlab/gitlab.rb

# 将nginx['enable'] = false 并打开注释,大概在1072行
  • 将域名更改为自定义域名
vi /etc/gitlab/gitlab.rb

# 更改external_url 'http://gd.cms.com'即可
  • 新增gitlab的Nginx配置文件
# gitlab原来的Nginx配置文件
cd /var/opt/gitlab/nginx/conf

# gitlab-http.conf就是默认的配置文件
# 将上述文件复制到/usr/local/nginx/conf/vhost/  但是可能会存在问题,要不删除一些,要不直接copy下面的文件内容
upstream gitlab {
  # 此处需要根据具体位置更改
  server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;
}

server {
  server_name gd.cms.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配置是否正确
/usr/local/nginx/sbin/nginx -t

# 重启gitlab服务和Nginx服务
gitlab-ctl reconfigure

service nginx restart
  • 说明

因为停掉了原来gitlab自带的Nginx服务,所以在此初始化gitlab时,将无法访问的,查看Nginx进程,没有启动,那么此时启动Nginx即可!紧接着访问域名即可访问!

gitlab配置

回到顶部

  1. windows下git连接gitlab
  • windows下面配置ssh(通过ssh免密连接)
# git-bash执行,会在C:\Users\MyPC\.ssh生成秘钥对,将公钥上传至gitlab即可 
ssh-keygen -t rsa -C "Venki@goldlight.com"

只要将自己的ssh公钥上传至gitlab,那么每次git clone的时候都可以免密拉取代码,但是克隆地址是ssh对应的。而且可以拉取到所有权限仓库的代码。

  • Windows下通过账号密码连接–暂时没有搞出来
# 清空git账号密码重新输入
git config --system --unset credential.helper

# 查看当前用户(global)配置
git config --global  --list

# 查看当前仓库配置信息
git config --local  --list
  1. Linux下面配置git连接ssh(免密那种,主要用于walle自动化部署)

  2. 用户组以及用户配置

  1. git配置
  • git初始化user.name 和 user.email 出错,想要更换,则重新输入命令即可
git config --global user.name '管理员'
git config --global user.email 'admin@example.com'
辅助资料

回到顶部

  1. 参考文献
  1. 参考命令
# 查看操作系统版本
cat /etc/issue
# 或
cat /etc/centos-release
# 启动所有 gitlab 组件
gitlab-ctl start    

# 停止所有 gitlab 组件
sudo gitlab-ctl stop 

# 重启所有 gitlab 组件
sudo gitlab-ctl restart       

# 查看服务状态
sudo gitlab-ctl status        

# 启动服务
sudo gitlab-ctl reconfigure        

# 修改默认的配置文件
sudo vim /etc/gitlab/gitlab.rb        

# 检查gitlab
gitlab-rake gitlab:check SANITIZE=true --trace   

# 查看日志
sudo gitlab-ctl tail        
# 查看git配置项
git config -l
  1. 问题
  • connect() to unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket failed (13: Permission denied) while connecting toupstream,client:192.168.1.242, server: gl.cms.com, request:“GET/favicon.icoHTTP/1.1”,upstream:“http://unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket:/favicon.ico”,host:“cms.gl.com”, referrer: “http://cms.gl.com/”

问题原因 点我 阅读

  • nginx没有访问gitlab的socket权限

解决方法

  • 查看运行nginx的用户,我的是www
ps -ef | grep nginx
root      21556      1  0 17:23 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www       21557  21556  0 17:23 ?        00:00:00 nginx: worker process
root      21881   9830  0 17:26 pts/2    00:00:00 grep --color=auto nginx
  • 将www用户加入gitlab-www组
# 查看sockets文件属性 主要是看属组用户
ll /var/opt/gitlab/gitlab-rails/

usermod -a -G gitlab-www www
  • 修改配置
vim /etc/gitlab/gitlab.rb
web_server['external_users'] = ['www']
  • 重启gitlab
gitlab-ctl reconfigure
  • 重启nginx
service nginx restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈文小超_自律

努力自己,幸福他人

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值