gitlab基本维护和使用
基本介绍
GitLab是一个自托管的Git项目仓库,可以自己搭建个人代码管理的仓库,功能与github类似。
安装
下载 gitlab下载地址: https://about.gitlab.com/downloads/
安装依赖的包
|
1
2
3
4
5
6
7
8
9
10
11
|
sudo yum install curl-develsudo yum install expat-develsudo yum install gettext-develsudo yum install openssl-develsudo yum install zlib-develsudo yum install perl-develsudo yum install curlsudo yum install openssh-serversudo yum install openssh-clientssudo yum install postfixsudo yum install cronie |
Ubuntu系统使用apt-get方式安装依赖包。
使用gitlab官网的脚本安装
|
1
|
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash |
或者使用gitlab的yum安装gitlab
|
1
|
sudo yum install gitlab-ce |
安装完毕后,使用Web登录

进入gitlab的管理页面,进行常用的分组,工程,用户等功能点的维护。

安装完gitlab后的运维操作
初次配置服务
|
1
|
sudo gitlab-ctl reconfigure |
启动服务
|
1
|
sudo gitlab-ctl start |
停止服务
|
1
|
sudo gitlab-ctl stop |
重启服务
|
1
|
sudo gitlab-ctl restart |
检查服务的日志信息
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 检查redis的日志sudo gitlab-ctl tail redis# 检查postgresql的日志sudo gitlab-ctl tail postgresql# 检查gitlab-workhorse的日志sudo gitlab-ctl tail gitlab-workhorse# 检查logrotate的日志sudo gitlab-ctl tail logrotate# 检查nginx的日志sudo gitlab-ctl tail nginx# 检查sidekiq的日志sudo gitlab-ctl tail sidekiq# 检查unicorn的日志sudo gitlab-ctl tail unicorn |
检查服务状态
|
1
|
sudo gitlab-ctl status |
一般服务状态显示信息
显示格式:
状态 : 进程名称:(进程ID)运行时间(秒);进程的日志服务进程和运行时间
|
1
2
3
4
5
6
7
|
run: gitlab-workhorse: (pid 11892) 281s; run: log: (pid 8630) 4742472srun: logrotate: (pid 11904) 280s; run: log: (pid 8631) 4742472srun: nginx: (pid 11911) 280s; run: log: (pid 8796) 4742455srun: postgresql: (pid 12866) 18s; run: log: (pid 8627) 4742472srun: redis: (pid 11989) 249s; run: log: (pid 8638) 4742472srun: sidekiq: (pid 12850) 20s; run: log: (pid 8634) 4742472srun: unicorn: (pid 12022) 247s; run: log: (pid 8629) 4742472s |
| 状态 | 说明 |
| run | 运行状态 |
| down | 服务停止 |
常见的问题
1. 页面显示500,Whoops, something went wrong on our end.
|
1
2
3
4
5
6
7
|
500Whoops, something went wrong on our end.Try refreshing the page, or going back and attempting the action again.Please contact your GitLab administrator if this problem persists. |
如何检查和定位问题?
使用命令检查所有服务的状态
|
1
|
sudo gitlab-ctl status |
检查服务状态如下
|
1
2
3
4
5
6
7
|
run: gitlab-workhorse: (pid 11892) 91s; run: log: (pid 8630) 4742282srun: logrotate: (pid 11904) 90s; run: log: (pid 8631) 4742282srun: nginx: (pid 11911) 90s; run: log: (pid 8796) 4742265sdown: postgresql: 1s, normally up, want up; run: log: (pid 8627) 4742282srun: redis: (pid 11989) 59s; run: log: (pid 8638) 4742282srun: sidekiq: (pid 12201) 2s; run: log: (pid 8634) 4742282srun: unicorn: (pid 12022) 57s; run: log: (pid 8629) 4742282s |
定位问题
从服务状态信息中显示数据库postgresql的状态是down,即服务停止。
检查数据库postgresql的运行日志,检查出现什么错误?
|
1
2
3
4
5
6
7
8
|
$ sudo gitlab-ctl tail postgresql==> /var/log/gitlab/postgresql/state <====> /var/log/gitlab/postgresql/current <==2016-12-24_01:39:39.00188 FATAL: data directory "/var/opt/gitlab/postgresql/data" has group or world access2016-12-24_01:39:39.00190 DETAIL: Permissions should be u=rwx (0700).2016-12-24_01:39:40.00698 FATAL: data directory "/var/opt/gitlab/postgresql/data" has group or world access2016-12-24_01:39:40.00700 DETAIL: Permissions should be u=rwx (0700). |
日志显示,数据库的访问权限应该是只有用户本身有读写执行的权限,用户组和其他用户不能有权限。
修改数据库数据的权限后,检查服务运行正常。
了解了问题的定位和解决方式,其他问题也很容易在日志中发现和解决,问题可能是磁盘空间少,用户权限错误或者其他原因。
2. gitlab管理员密码忘记,怎么重置密码
Gitlab 修改root用户密码
使用rails工具打开终端
|
1
|
sudo gitlab-rails console production |
查询用户的email,用户名,密码等信息,id:1 表示root账号
|
1
|
user = User.where(id: 1).first |
重新设置密码
|
1
2
|
user.password = '新密码'user.password_confirmation = '新密码' |
保存密码
|
1
|
user.save! |
完整的操作ruby脚本
|
1
2
3
4
|
user = User.where(id: 1).firstuser.password = '新密码'user.password_confirmation = '新密码'user.save! |
然后使用重置过的密码重新登录。
浙公网安备 33010602011771号