Gitlab安装

基础包安装

yum install -y curl policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd
firewall-cmd --permanent --add-service=http
systemctl reload firewalld

安装 postfix

yum install postfix
systemctl enable postfix
systemctl start postfix

添加Gitlab包的yum库

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

安装gitlab

EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ce
vi /etc/gitlab/gitlab.rb 修改 EXTERNAL_URL=“http://IP:port”

汉化

下载最新汉化包

git clone https://gitlab.com/xhang/gitlab.git

  • 下载指定版本汉化包 git clone https://gitlab.com/xhang/gitlab.git -b v12.0.6-zh

查看汉化补丁版本

cat gitlab/VERSION

获取汉化包

git diff 12.0.6-stable 12.0.6-stable-zh > ../12.0.6.diff

更新补丁到gitlab中

yum install patch -y #安装patch工具

patch -d/opt/gitlab/embedded/service/gitlab-rails -p1 < 10.7.diff

重新配置gitlab

gitlab-ctl reconfigure #重载配置
gitlab-ctl start  #启动gitlab

常用管理命令

gitlab-ctl start    # 启动所有 gitlab 组件;
gitlab-ctl stop        # 停止所有 gitlab 组件;
gitlab-ctl restart        # 重启所有 gitlab 组件;
gitlab-ctl status        # 查看服务状态;
vim /etc/gitlab/gitlab.rb        # 修改gitlab配置文件;
gitlab-ctl reconfigure        # 重新编译gitlab的配置;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
gitlab-ctl check-config #检查在gitlab中是否有任何配置。在指定版本中删除的rb
gitlab-ctl deploy-page #安装部署页面
gitlab-ctl diff-config #将用户配置与包可用配置进行比较
gitlab-ctl remove-accounts #删除所有用户和组
gitlab-ctl upgrade #升级
gitlab-ctl service-list #查看所有服务
gitlab-ctl tail        # 查看日志;
gitlab-ctl tail nginx/gitlab_access.log
gitlab-ctl help  # 查看相关的帮助
gitlab-ctl once  #如果GitLab服务停止了就启动服务,如果已启动就不做任何操作

GitLab配置文件修改

vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
#外网访问的端口,如果服务器已经有服务器占用了80,那么这里可以改成其它
listen *:8888;
server_name gitlab.test.domain.com;
set $http_host_with_default "gitlab.test.domain.com:8888";

gitlab基本配置:

#外部访问url(经过编译后,自动将这个配置编译到nginx配置,nginx就无需配置了)
external_url 'http://gitlab.test.domain.com:8888'
#默认值就是8080。如果端口被占用,可将8080修改为其它(例如:9090)
unicorn['port'] = 8080

gitlab发送邮件配置

gitlab_rails['smtp_enable'] = true  
gitlab_rails['smtp_address'] = “smtp.exmail.qq.com”  
gitlab_rails['smtp_port'] = 25  
gitlab_rails['smtp_user_name'] = “adminstrator@domain.com“  
gitlab_rails['smtp_password'] = "smtp password"  
gitlab_rails['smtp_authentication']= “plain"  
gitlab_rails['smtp_enable_starttls_auto']= true  
gitlab_rails['gitlab_email_from']= 'adminstrator@domain.com' 
gitlab_rails['gitlab_email_reply_to']= ‘noreply@domain.com'

服务器修改过ssh端口的坑(需要修改配置ssh端口)

#修改过ssh端口,gitlab中项目的的ssh地址,会在前面加上协议头和端口号
“ssh://git@gitlab.domain.com:55725/huangdc/test.git”
gitlab_rails['gitlab_shell_ssh_port'] = 55725

更换gitlab服务器ip的地址

cd /opt/gitlab/embedded/service/gitlab-rails/config
vim gitlab.yml

依据自己的情况,更换地址,该地址影响项目代码的地址

gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    #host: 192.168.13.42
    #port: 9988
    host: gitlab.test.com
    port: 80
    https: false

配置生效

#使配置生效
gitlab-ctl reconfigure
#重新启动GitLab 
gitlab-ctl restart