wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/gitlab-ce-13.11.0-ce.0.el8.x86_64.rpm
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.0.2-ce.0.el7.x86_64.rpm --no-check-certificate
安装gitlab
rpm -i gitlab-ce-13.11.0-ce.0.el8.x86_64.rpm
vi /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 makecache
yum clean all
yum install -y gitlab-ce
vi /etc/gitlab/gitlab.rb
gitlab_rails['time_zone'] = 'Asia/Shanghai'
external_url 'http://gitlab.example.com'
或者
external_url 'http://47.111.xxx.14x'
unicorn['port'] = 8066
puma['port'] = 8066
nginx['listen_port'] = 8081
gitlab-ctl reconfigure
重新编译后会更新gitlab的nginx配置,比如nginx监听的端口号
查看gitlab-http.conf
vi /var/opt/gitlab/nginx/conf/gitlab-http.conf
server {
listen *:8081; #执行gitlab-ctl reconfigure命令后自动更新监听端口(不要手动改)
server_name gitlab.example.com;
server_tokens off; ## Don't show the nginx version number, a security best practice
## Increase this if you want to upload large attachments
## Or if you want to accept large git objects over http
client_max_body_size 0;
## Real IP Module Config
## http://nginx.org/en/docs/http/ngx_http_realip_module.html
## HSTS Config
## https://www.nginx.com/blog/http-strict-transport-security-hsts-and-nginx/
add_header Strict-Transport-Security "max-age=31536000";
gitlab-ctl restart
ok: run: alertmanager: (pid 129368) 1s
ok: run: gitaly: (pid 129382) 0s
ok: run: gitlab-exporter: (pid 129410) 0s
ok: run: gitlab-workhorse: (pid 129412) 0s
ok: run: grafana: (pid 129421) 1s
ok: run: logrotate: (pid 129435) 0s
ok: run: nginx: (pid 129479) 0s
ok: run: node-exporter: (pid 129525) 1s
ok: run: postgres-exporter: (pid 129536) 0s
ok: run: postgresql: (pid 129547) 1s
ok: run: prometheus: (pid 129558) 0s
ok: run: puma: (pid 129571) 0s
ok: run: redis: (pid 129576) 1s
ok: run: redis-exporter: (pid 129585) 0s
ok: run: sidekiq: (pid 129593) 0s
现在gitlab已启动,可以通过IP加端口号来访问(http://47.111.xxx.14x:8081)
如果gitlab配的访问域名,因为gitlab监听的是非80端口,所以想要通过域名直接访问需要在系统原生nginx下创建vhost并配置反向代理
server
{
listen 80;
#listen [::]:80;
server_name gitlab.example.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/gitlab.example.com;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
#include proxy-pass-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
proxy_pass http://47.111.xxx.14x:8081; # 图片资源反向代理
}
location ~ .*\.(js|css)?$
{
expires 12h;
proxy_pass http://47.111.xxx.14x:8081; # 静态资源反射代理
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/gitlab.example.com.log;
location / {
index index.html index.php; # 请求入口文件
# 这个大小的设置非常重要,如果 git 版本库里面有大文件,设置的太小,文件push 会失败,根据情况调整
client_max_body_size 50m;
proxy_redirect off;
#以下确保gitlab中项目的url是域名而不是IP http://47.111.xxx.14x:8081,这个很重要
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root /home/wwwroot/gitlab.example.com/; # 请求的目录
proxy_pass http://47.111.xxx.14x:8081; #反向代理到8081端口
}
}
修改配置后的编译初始化
gitlab-ctl reconfigure
启动
gitlab-ctl start
停止
gitlab-ctl stop
重启
gitlab-ctl restart
开机自启动
systemctl enable gitlab-runsvdir.service
禁止开机自启动
systemctl disable gitlab-runsvdir.service
firewall-cmd --zone=public --add-port=端口号/tcp --permanent
详解:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
使配置生效:
firewall-cmd --reload
查询指定端口是否开启成功:
firewall-cmd --query-port=端口号/tcp
开放8081端口
firewall-cmd --zone=public --add-port=8081/tcp --permanent
firewall-cmd --reload
firewall-cmd --query-port=8081/tcp
yes
如下图代码页不显示
F12打开页面调试发现获取代码列表数据的接口请求的是
Request URL: http://47.111.xxx.14x:8081/api/graphql
接口返回的数据为{“data”:{“project”:null}}
当我们通过域名访问的时候,正确的接口也应当通过域名访问,
所以问题点出在这里。
解决问题点请检查下图红框里的配置是否配置或配置正确
1. 执行命令 gitlab-rails console production 等待控制台界面显示出来
2. 执行命令 user = User.where(id: 1).first 查询用户id为1的账号
3. 执行命令 user.password=123456 修改密码
4. 执行命令 user.password_confirmation=123456 确认密码
5. 执行命令 user.save! 保存
6. 执行命令 quit 退出
7. 执行命令 gitlab-ctl restart 重启gitlab
8. 用新密码登录gitlab
[root@gitlab ~]# gitlab-rails console production
-------------------------------------------------------------------------------------
Gitlab: 10.8.2 (d0a319c)
Gitlab Shell: 7.1.2
postgresql: 9.6.8
-------------------------------------------------------------------------------------
Loading production environment (Rails 4.2.10)
irb(main):001:0>user.password='123456'
=> "123456"
irb(main):003:0> user.password_confirmation='123456'
=> "123456"
irb(main):004:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: fa9e020f-cf3c-4b75-bb36-16f41ca3d2f8) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
=> true
irb(main):005:0> quit
[root@gitlab ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 58604) 0s
ok: run: gitaly: (pid 58629) 0s
timeout: run: gitlab-monitor: (pid 752) 1551010s, got TERM
ok: run: gitlab-workhorse: (pid 59374) 0s
ok: run: logrotate: (pid 59384) 1s
ok: run: nginx: (pid 59390) 0s
ok: run: node-exporter: (pid 59413) 0s
ok: run: postgres-exporter: (pid 59419) 0s
ok: run: postgresql: (pid 59477) 0s
ok: run: prometheus: (pid 59497) 1s
ok: run: redis: (pid 59518) 0s
ok: run: redis-exporter: (pid 59535) 0s
timeout: run: sidekiq: (pid 758) 1551046s, got TERM
ok: run: unicorn: (pid 60249) 1s