官方安装帮助
https://www.gitlab.com.cn/installation/#centos-6
GitLab分为两个版本:gitlab-ee(企业版,收费),gitlab-ce(社区版,免费,推荐)
Gitlab服务构成
GitLab由主要由以下服务构成,他们共同承担了Gitlab的运作需要。
nginx: 静态web服务器
gitlab-shell: 用于处理Git命令和修改authorized keys列表
gitlab-workhorse: 轻量级的反向代理服务器
logrotate:日志文件管理工具
postgresql:数据库
redis:缓存数据库
sidekiq:用于在后台执行队列任务(异步执行)
unicorn:HTTP服务,GitLab Rails应用是托管在这个服务器上面的。
更新镜像源
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo (Centos 6.x 版本)
//阿里云镜像源:http://mirrors.aliyun.com/repo/Centos-6.repo
//清华:https://mirror.tuna.tsinghua.edu.cn/
yum clean all (清理缓存)
yum makecache (生成缓存)
安装GitLab-ce
sudo yum install -y curl policycoreutils-python openssh-server cronie
sudo lokkit -s http -s ssh
curl -sS http://packages.gitlab.com.cn/install/gitlab-ce/script.rpm.sh | sudo bash
指定访问网址开始安装(网址将被写入配置文件/etc/gitlab/gitlab.rb):
sudo EXTERNAL_URL="http://git.ju3b**.net" yum install -y gitlab-ce
安装完成显示:
Running handlers:
Running handlers complete
Chef Client finished, 454/647 resources updated in 02 minutes 32 seconds
gitlab Reconfigured!
*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Thank you for installing GitLab!
GitLab should be available at http://git.ju3b**.net
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
Verifying : gitlab-ce-11.6.5-ce.0.el6.x86_64 1/1
已安装:
gitlab-ce.x86_64 0:11.6.5-ce.0.el6
完毕!
重置默认管理员和密码
我们可以使用默认的管理员root来登录控制台,管理员首次登录时会要求我们重置登录密码。进入控制台之后,你可以重新修改密码,但这时你会发现GitLab管理员账号,缺省邮箱[email protected]是个根本不存在的地址,所以无法通过邮箱重置密码。
这时,我们可以通过Gitlab服务器控制台命令来重新设置管理员或指定账户的登录密码。
在SSH连接窗口中切换到root用户,执行:
# gitlab-rails console production
-------------------------------------------------------------------------------------
GitLab: 11.6.5 (237bddc)
GitLab Shell: 8.4.3
postgresql: 9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = '2019Gitlab'
=> "2019Gitlab"
irb(main):003:0> user.password_confirmation = '2019Gitlab'
=> "2019Gitlab"
irb(main):004:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 213008ce-71dd-4eb1-8137-bbcd5b45d8f8) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f9f4c6f5840 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):005:0> exit
修改GitLab配置
mkdir -p /data/gitlab-data #建立仓库存储路径
mkdir -p /data/gitlab-backup #建立仓库、数据库、配置文件备份存储路径
cd /etc/gitlab/
cp gitlab.rb gitlab.bak
vim gitlab.rb
gitlab.rb文件修改后的内容如下:
(注意点已经注释在代码后方,需要重点留意,不然会踩到坑。)
external_url 'http://git.ju3b**.net' #解析域名,也可以是IP+端口号
# 自定义邮箱配置,邮箱是gitlab必须配置的,用于通知版本变动情况
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = ""
gitlab_rails['smtp_domain'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_authentication'] = "plain"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
# unicorn['enable'] = false
# unicorn['port'] = 11001
nginx['enable'] = false #由于之前已经安装了nginx,所以禁用gitlab自带的nginx服务
web_server['external_users'] = ['www'] #默认nginx用户为gitlab-www,但这里需要用到已经安装nginx的用户名,见nginx.conf配置文件里的用户名
nginx['client_max_body_size'] = '250m' #允许提交的单个文件最大容量
unicorn['port'] = 11001 #默认为8080,为了不与jenkins相冲突,这里修改一下端口
# 自定义仓库存储目录,为了后续容量的扩展性,建立使用独立盘或文件夹存储
git_data_dirs({
"default" => {
"path" => "/data/gitlab-data"
}
})
# 自定义备份目录,仓库、数据库、配置文件备份等,打包形式
gitlab_rails['backup_path'] = '/data/gitlab-backup';
注意:
1、如果nginx是使用GitLab自带的,默认nginx['enable'] = true
,且会自动生成配置文件/var/opt/gitlab/nginx/conf/gitlab-http.conf
,一般情况下只要端口不冲突,域名或IP解析好,重启GitLab后都能正常访问。
2、默认的Gitlab数据存储路径,在目录/var/opt/gitlab/git-data
下,为了防止以后数据过大,所以可以修改路径存储为如:/data/gitlab-data
, /data可以是挂载的2T的硬盘。
3、web_server['external_users'] = ['www']
会自动将www这个用户加入gitlab-www组,如果没有,可手工加入,sudo usermod -aG gitlab-www www
再查看www所属哪个组groups www
www : www gitlab-www
cat /etc/passwd
可以查看所有用户的列表
重新生成配置,并重启GitLab:
gitlab-ctl reconfigure #重新生成配置
gitlab-ctl restart #一安装就会自启动
Nginx配置
由于本次安装没有使用GitLab自带的nginx,需要手工下载并修改gitlab配置文件,切换到已有nginx配置目录:/usr/local/nginx/conf/vhost/
,去官网找一下配置文件:https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/nginx/gitlab-omnibus-nginx.conf(Apache配置文件在同一仓库中查找),将其下载并修改成如下:
upstream gitlab-workhorse { #反向代理
server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
server {
listen *:80;
#listen [::]:80;
server_name git.ju3b**.net;
server_tokens off;
root /opt/gitlab/embedded/service/gitlab-rails/public;
client_max_body_size 100m;
access_log /home/wwwlogs/gitlab_access.log; #修改访问和错误日志路径
error_log /home/wwwlogs/gitlab_error.log;
location / {
client_max_body_size 0;
#gzip off;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
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-Forwarded-Proto $scheme;
proxy_pass http://gitlab-workhorse;
}
}
重启nginx/etc/init.d/nginx restart
即可通过git.ju3b**.net访问GitLab。
注意:如果自带的nginx和已经安装的nginx发生冲突,可以先将已经安装的nginx服务停止掉,或将进程结束掉。
查看nginx的进程pid:ps -ef | grep nginx
查看监听端口情况:netstat -nlp
查看当前安装的版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
11.6.3
GitLab汉化
中文版仓库地址:https://gitlab.com/xhang/gitlab/
cd /opt/gitlab/embedded/service/
cp -r /opt/gitlab/embedded/service/gitlab-rails{,.ori} #先做备份,在当前目录下会复制成gitlab-rails.ori
wget -c https://gitlab.com/xhang/gitlab/-/archive/11-6-stable-zh/gitlab-11-6-stable-zh.tar.bz2 #下载汉化包
注意:下载的汉化包版本要与安装的版本相同,否则会出错,导致不能正常访问GitLab。
GitLab备份
主要针对GitLab仓库、数据库、配置文件进行打包备份。
/usr/bin/gitlab-rake gitlab:backup:create
cd /data/gitlab-backup #查看备份文件
GitLab常用命令
gitlab几乎所有的命令都在此目录下/opt/gitlab/embedded/bin/
# 重新应用gitlab的配置,每次修改/etc/gitlab/gitlab.rb文件之后执行
sudo gitlab-ctl reconfigure
# 启动gitlab服务
sudo gitlab-ctl start
# 重启gitlab服务
sudo gitlab-ctl restart
# 查看gitlab运行状态
sudo gitlab-ctl status
#停止gitlab服务
sudo gitlab-ctl stop
# 查看gitlab运行所有日志
sudo gitlab-ctl tail
#查看 nginx 访问日志
sudo gitlab-ctl tail nginx/gitlab_acces.log
#查看 postgresql 日志
sudo gitlab-ctl tail postgresql
# 停止相关数据连接服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
# 系统信息监测
gitlab-rake gitlab:env:info
GitLab相关目录
如果不是通过纯手工的方式安装,一般来说Gitlab的各个模块配置文件存放目录是固定的,手动编译安装出来的所有配置文件理论上会存放与手动置顶的编译安装目录。在日常的配置中,我们可以通过修改以下配置文件之中的参数来调节Gitlab的功能。
主配置文件: /etc/gitlab/gitlab.rb
/var/opt/gitlab/git-data/repositories/root:库默认存储目录
/opt/gitlab:文档根目录,gitlab的应用代码和相应的依赖程序
/var/opt/gitlab:此目录下是运行gitlab-ctl reconfigure命令编译后的应用数据和配置文件,不需要人为修改配置
/var/opt/gitlab/git-data/repositories:默认存储库位置
Nginx配置文件: /var/opt/gitlab/nginx/conf/gitlab-http.conf
Postgresql数据目录: /var/opt/gitlab/postgresql/data
/etc/gitlab:此目录下存放了以omnibus-gitlab包安装方式时的配置文件,这里的配置文件才需要管理员手动编译配置
/var/log/gitlab:此目录下存放了gitlab各个组件产生的日志
/opt/gitlab/backups/:默认备份文件生成的目录
一般来说我们的常规配置都可以通过修改/etc/gitlab/gitlab.rb这一配置文件来达到目的。
参考:
https://docs.gitlab.com/ #官方帮助文档
https://www.jianshu.com/p/b04356e014fa #手把手教你 GitLab 的安装及使用
https://blog.csdn.net/wzx19840423/article/details/52350512 #CentOS 6安装GitLab
https://www.cnblogs.com/duzishanglu/articles/4536645.html
https://www.cnblogs.com/int32bit/p/5310382.html
https://www.jianshu.com/p/da016ce34cec
https://www.zhihu.com/question/268284854 #解决nginx冲突
https://www.jianshu.com/p/104a51b56c5c #CentOS 6.x安装GitLab
https://www.jianshu.com/p/136068fe44e2 #汉化
https://www.jianshu.com/p/2400d9e57fd1 #汉化