gitlab 日常运维命令

2018-10-24


gitlab查看版本

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

查看gitlab服务状态命令

gitlab-ctl status

启动、停止服务

# 启动Gitlab所有组件
sudo gitlab-ctl start

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

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

备份与恢复

备份配置

配置文件再/etc/gitlab/ 下面,将所有的配置用tar备份即可

[[email protected] init.d]# cd /etc/gitlab/
[[email protected] gitlab]# ls
gitlab.rb  gitlab-secrets.json  trusted-certs

备份数据

Gitlab的备份目录路径设置

[[email protected] ~]# vim /etc/gitlab/gitlab.rb
gitlab_rails[‘manage_backup_path‘] = true
gitlab_rails[‘backup_path‘] = "/data/gitlab/backups"    //gitlab备份目录
gitlab_rails[‘backup_archive_permissions‘] = 0644       //生成的备份文件权限
gitlab_rails[‘backup_keep_time‘] = 7776000              //备份保留天数为3个月(即90天,这里是7776000秒)

[[email protected]-server ~]# mkdir -p /data/gitlab/backups
[[email protected]-server ~]# chown -R git.git /data/gitlab/backups
[[email protected]-server ~]# chmod -R 777 /data/gitlab/backups

如上设置了gitlab备份目录路径为/data/gitlab/backups,最后使用下面命令重载gitlab配置文件,是上述修改生效!
[email protected]-server ~]# gitlab-ctl reconfigure

GItlab备份操作(使用备份命令"gitlab-rake gitlab:backup:create")

手动备份gitlab
[[email protected]-server backups]# gitlab-rake gitlab:backup:create
Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * treesign/treesign ... [DONE]
 * gateway/gateway ... [DONE]
 * treesign/treesign-doc ... [SKIPPED]
 * qwsign/qwsign ... [DONE]
 * qwsign/qwsign-doc ... [DONE]
 * test/test ... [DONE]
done
Dumping uploads ...
done
Dumping builds ...
done
Dumping artifacts ...
done
Dumping pages ...
done
Dumping lfs objects ...
done
Dumping container registry images ...
[DISABLED]
Creating backup archive: 1510471890_2017_11_12_9.4.5_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... done. (0 removed)

然后查看下备份文件(文件权限是设定好的644)
[[email protected]-server backups]# ll
total 244
-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar

编写备份脚本,结合crontab实施自动定时备份,比如每天0点、6点、12点、18点各备份一次
[[email protected]-server backups]# pwd
/data/gitlab/backups
[[email protected]-server backups]# vim gitlab_backup.sh
#!/bin/bash
/usr/bin/gitlab-rake gitlab:backup:create CRON=1

注意:环境变量CRON=1的作用是如果没有任何错误发生时, 抑制备份脚本的所有进度输出

[[email protected]-server backups]# crontab -l
0 0,6,12,18 * * * /bin/bash -x /data/gitlab/backups/gitlab_backup.sh > /dev/null 2>&1

3)Gitlab恢复操作

GItlab只能还原到与备份文件相同的gitlab版本。
假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作:

1)停止相关数据连接服务
[[email protected]-server backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[[email protected]-server backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
[[email protected]-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 1883s; run: log: (pid 194202) 163003s
run: gitlab-monitor: (pid 98101) 1883s; run: log: (pid 194363) 163002s
run: gitlab-workhorse: (pid 98104) 1882s; run: log: (pid 194362) 163002s
run: logrotate: (pid 98117) 1882s; run: log: (pid 5793) 160832s
run: nginx: (pid 98123) 1881s; run: log: (pid 194359) 163002s
run: node-exporter: (pid 98167) 1881s; run: log: (pid 194360) 163002s
run: postgres-exporter: (pid 98173) 1881s; run: log: (pid 194204) 163003s
run: postgresql: (pid 98179) 1880s; run: log: (pid 194365) 163002s
run: prometheus: (pid 98187) 1880s; run: log: (pid 194364) 163002s
run: redis: (pid 98230) 1879s; run: log: (pid 194358) 163002s
run: redis-exporter: (pid 98234) 1879s; run: log: (pid 194208) 163003s
down: sidekiq: 8s, normally up; run: log: (pid 194437) 163001s
down: unicorn: 21s, normally up; run: log: (pid 194443) 163001s

2)现在通过之前的备份文件进行恢复(必须要备份文件放到备份路径下,这里备份路径我自定义的/data/gitlab/backups,默认的是/var/opt/gitlab/backups)
[[email protected]-server backups]# pwd
/data/gitlab/backups
[[email protected]-server backups]# ll
total 244
-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar

Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复
[[email protected]-server backups]# gitlab-rake gitlab:backup:restore BACKUP=1510472027_2017_11_12_9.4.5
Unpacking backup ... done
Before restoring the database we recommend removing all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.

Do you want to continue (yes/no)?
........
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
WARNING:  no privileges were granted for "public"
GRANT
[DONE]
done
Restoring repositories ...
 * treesign/treesign ... [DONE]
 * gateway/gateway ... [DONE]
 * treesign/treesign-doc ... [DONE]
 * qwsign/qwsign ... [DONE]
 * qwsign/qwsign-doc ... [DONE]
 * test/test ... [DONE]
Put GitLab hooks in repositories dirs [DONE]
done
Restoring uploads ...
done
Restoring builds ...
done
Restoring artifacts ...
done
Restoring pages ...
done
Restoring lfs objects ...
done
This will rebuild an authorized_keys file.
You will lose any data stored in authorized_keys file.
Do you want to continue (yes/no)? yes

Deleting tmp directories ... done
done
done
done
done
done
done
done
[[email protected]-server backups]#

最后再次启动Gitlab
[[email protected]-server backups]# gitlab-ctl start
ok: run: gitaly: (pid 98087) 2138s
ok: run: gitlab-monitor: (pid 98101) 2138s
ok: run: gitlab-workhorse: (pid 98104) 2137s
ok: run: logrotate: (pid 98117) 2137s
ok: run: nginx: (pid 98123) 2136s
ok: run: node-exporter: (pid 98167) 2136s
ok: run: postgres-exporter: (pid 98173) 2136s
ok: run: postgresql: (pid 98179) 2135s
ok: run: prometheus: (pid 98187) 2135s
ok: run: redis: (pid 98230) 2134s
ok: run: redis-exporter: (pid 98234) 2134s
ok: run: sidekiq: (pid 104494) 0s
ok: run: unicorn: (pid 104497) 1s
[[email protected]-server backups]# gitlab-ctl status
run: gitaly: (pid 98087) 2142s; run: log: (pid 194202) 163262s
run: gitlab-monitor: (pid 98101) 2142s; run: log: (pid 194363) 163261s
run: gitlab-workhorse: (pid 98104) 2141s; run: log: (pid 194362) 163261s
run: logrotate: (pid 98117) 2141s; run: log: (pid 5793) 161091s
run: nginx: (pid 98123) 2140s; run: log: (pid 194359) 163261s
run: node-exporter: (pid 98167) 2140s; run: log: (pid 194360) 163261s
run: postgres-exporter: (pid 98173) 2140s; run: log: (pid 194204) 163262s
run: postgresql: (pid 98179) 2139s; run: log: (pid 194365) 163261s
run: prometheus: (pid 98187) 2139s; run: log: (pid 194364) 163261s
run: redis: (pid 98230) 2138s; run: log: (pid 194358) 163261s
run: redis-exporter: (pid 98234) 2138s; run: log: (pid 194208) 163262s
run: sidekiq: (pid 104494) 4s; run: log: (pid 194437) 163260s
run: unicorn: (pid 104497) 4s; run: log: (pid 194443) 163260s

恢复命令完成后,可以check检查一下恢复情况
[[email protected]-server backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab Shell ...

GitLab Shell version >= 5.3.1 ? ... OK (5.3.1)
Repo base directory exists?
default... yes
Repo storage directories are symlinks?
default... no
Repo paths owned by git:root, or git:git?
default... yes
Repo paths access is drwxrws---?
default... yes
hooks directories in repos are links: ...
5/1 ... ok
6/2 ... ok
5/3 ... repository is empty
12/4 ... ok
12/5 ... ok
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: OK
Send ping to redis server: OK
gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes
Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured correctly? ... yes
Database config exists? ... yes
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config up to date? ... yes
Log directory writable? ... yes
Tmp directory writable? ... yes
Uploads directory exists? ... yes
Uploads directory has correct permissions? ... yes
Uploads directory tmp has correct permissions? ... yes
Init script exists? ... skipped (omnibus-gitlab has no init script)
Init script up-to-date? ... skipped (omnibus-gitlab has no init script)
Projects have namespace: ...
5/1 ... yes
6/2 ... yes
5/3 ... yes
12/4 ... yes
12/5 ... yes
Redis version >= 2.8.0? ... yes
Ruby version >= 2.3.3 ? ... yes (2.3.3)
Git version >= 2.7.3 ? ... yes (2.13.4)
Active users: ... 11

Checking GitLab ... Finished

然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了!

另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致

GItlab只能还原到与备份文件相同的gitlab版本。

假设在上面gitlab备份之前创建了test项目,然后不小心误删了test项目,现在就进行gitlab恢复操作:

 

1)停止相关数据连接服务

[[email protected] backups]# gitlab-ctl stop unicorn

ok: down: unicorn: 0s, normally up

[[email protected] backups]# gitlab-ctl stop sidekiq

ok: down: sidekiq: 1s, normally up

[[email protected] backups]# gitlab-ctl status

run: gitaly: (pid 98087) 1883s; run: log: (pid 194202) 163003s

run: gitlab-monitor: (pid 98101) 1883s; run: log: (pid 194363) 163002s

run: gitlab-workhorse: (pid 98104) 1882s; run: log: (pid 194362) 163002s

run: logrotate: (pid 98117) 1882s; run: log: (pid 5793) 160832s

run: nginx: (pid 98123) 1881s; run: log: (pid 194359) 163002s

run: node-exporter: (pid 98167) 1881s; run: log: (pid 194360) 163002s

run: postgres-exporter: (pid 98173) 1881s; run: log: (pid 194204) 163003s

run: postgresql: (pid 98179) 1880s; run: log: (pid 194365) 163002s

run: prometheus: (pid 98187) 1880s; run: log: (pid 194364) 163002s

run: redis: (pid 98230) 1879s; run: log: (pid 194358) 163002s

run: redis-exporter: (pid 98234) 1879s; run: log: (pid 194208) 163003s

down: sidekiq: 8s, normally up; run: log: (pid 194437) 163001s

down: unicorn: 21s, normally up; run: log: (pid 194443) 163001s

 

2)现在通过之前的备份文件进行恢复(必须要备份文件放到备份路径下,这里备份路径我自定义的/data/gitlab/backups,默认的是/var/opt/gitlab/backups

[[email protected] backups]# pwd

/data/gitlab/backups

[[email protected] backups]# ll

total 244

-rw-r--r-- 1 git git 245760 Nov 12 15:33 1510472027_2017_11_12_9.4.5_gitlab_backup.tar

 

Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复

[[email protected] backups]# gitlab-rake gitlab:backup:restore BACKUP=1510472027_2017_11_12_9.4.5

Unpacking backup ... done

Before restoring the database we recommend removing all existing

tables to avoid future upgrade problems. Be aware that if you have

custom tables in the GitLab database these tables and all data will be

removed.

 

Do you want to continue (yes/no)?

........

ALTER TABLE

ALTER TABLE

ALTER TABLE

ALTER TABLE

WARNING:  no privileges were granted for "public"

GRANT

[DONE]

done

Restoring repositories ...

 * treesign/treesign ... [DONE]

 * gateway/gateway ... [DONE]

 * treesign/treesign-doc ... [DONE]

 * qwsign/qwsign ... [DONE]

 * qwsign/qwsign-doc ... [DONE]

 test/test ... [DONE]

Put GitLab hooks in repositories dirs [DONE]

done

Restoring uploads ...

done

Restoring builds ...

done

Restoring artifacts ...

done

Restoring pages ...

done

Restoring lfs objects ...

done

This will rebuild an authorized_keys file.

You will lose any data stored in authorized_keys file.

Do you want to continue (yes/no)? yes

 

 

Deleting tmp directories ... done

done

done

done

done

done

done

done

[[email protected] backups]#

 

最后再次启动Gitlab

[[email protected] backups]# gitlab-ctl start

ok: run: gitaly: (pid 98087) 2138s

ok: run: gitlab-monitor: (pid 98101) 2138s

ok: run: gitlab-workhorse: (pid 98104) 2137s

ok: run: logrotate: (pid 98117) 2137s

ok: run: nginx: (pid 98123) 2136s

ok: run: node-exporter: (pid 98167) 2136s

ok: run: postgres-exporter: (pid 98173) 2136s

ok: run: postgresql: (pid 98179) 2135s

ok: run: prometheus: (pid 98187) 2135s

ok: run: redis: (pid 98230) 2134s

ok: run: redis-exporter: (pid 98234) 2134s

ok: run: sidekiq: (pid 104494) 0s

ok: run: unicorn: (pid 104497) 1s

[[email protected] backups]# gitlab-ctl status

run: gitaly: (pid 98087) 2142s; run: log: (pid 194202) 163262s

run: gitlab-monitor: (pid 98101) 2142s; run: log: (pid 194363) 163261s

run: gitlab-workhorse: (pid 98104) 2141s; run: log: (pid 194362) 163261s

run: logrotate: (pid 98117) 2141s; run: log: (pid 5793) 161091s

run: nginx: (pid 98123) 2140s; run: log: (pid 194359) 163261s

run: node-exporter: (pid 98167) 2140s; run: log: (pid 194360) 163261s

run: postgres-exporter: (pid 98173) 2140s; run: log: (pid 194204) 163262s

run: postgresql: (pid 98179) 2139s; run: log: (pid 194365) 163261s

run: prometheus: (pid 98187) 2139s; run: log: (pid 194364) 163261s

run: redis: (pid 98230) 2138s; run: log: (pid 194358) 163261s

run: redis-exporter: (pid 98234) 2138s; run: log: (pid 194208) 163262s

run: sidekiq: (pid 104494) 4s; run: log: (pid 194437) 163260s

run: unicorn: (pid 104497) 4s; run: log: (pid 194443) 163260s

恢复命令完成后,可以check检查一下恢复情况

[[email protected] backups]# gitlab-rake gitlab:check SANITIZE=true

Checking GitLab Shell ...

GitLab Shell version >= 5.3.1 ? ... OK (5.3.1)

Repo base directory exists?

default... yes

Repo storage directories are symlinks?

default... no

Repo paths owned by git:root, or git:git?

default... yes

Repo paths access is drwxrws---?

default... yes

hooks directories in repos are links: ...

5/1 ... ok

6/2 ... ok

5/3 ... repository is empty

12/4 ... ok

12/5 ... ok

Running /opt/gitlab/embedded/service/gitlab-shell/bin/check

Check GitLab API access: OK

Access to /var/opt/gitlab/.ssh/authorized_keys: OK

Send ping to redis server: OK

gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Sidekiq ...

Running? ... yes

Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Reply by email ...

Reply by email is disabled in config/gitlab.yml

Checking Reply by email ... Finished

Checking LDAP ...

LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab ...

Git configured correctly? ... yes

Database config exists? ... yes

All migrations up? ... yes

Database contains orphaned GroupMembers? ... no

GitLab config exists? ... yes

GitLab config up to date? ... yes

Log directory writable? ... yes

Tmp directory writable? ... yes

Uploads directory exists? ... yes

Uploads directory has correct permissions? ... yes

Uploads directory tmp has correct permissions? ... yes

Init script exists? ... skipped (omnibus-gitlab has no init script)

Init script up-to-date? ... skipped (omnibus-gitlab has no init script)

Projects have namespace: ...

5/1 ... yes

6/2 ... yes

5/3 ... yes

12/4 ... yes

12/5 ... yes

Redis version >= 2.8.0? ... yes

Ruby version >= 2.3.3 ? ... yes (2.3.3)

Git version >= 2.7.3 ? ... yes (2.13.4)

Active users: ... 11

Checking GitLab ... Finished

 

然后稍等一会(如果启动gitlab后,访问出现500,这是因为redis等程序还没完全启动,等一会儿访问就ok了),再次登录Gitlab,就会发现之前误删除的test项目已经恢复了!

 

另外:Gitlab迁移与恢复一样,但是要求两个GitLab版本号一致

原文地址:https://www.cnblogs.com/fqxy/p/9842333.html

时间: 2024-10-10 00:40:11

gitlab 日常运维命令的相关文章

kafka知识体系-日常运维命令

本文主要讲解kafka日常运维的命令,包括topic管理.性能测试脚本. kafka版本0.10.0,安装步骤见大数据平台搭建-kafka集群的搭建 常用脚本 如下所有的命令均基于KAFKA_HOME=/wls/oracle/kafka ,服务器列表如下: 10.20.112.59 10.20.112.64 10.20.112.65 10.20.116.129 10.20.116.175 创建topic /wls/oracle/kafka/bin/kafka-topics.sh --zookee

Lync2013日常运维命令整理(十)

近部署完成了Lync 服务器,即将转向运维阶段,运维过程中会涉及到为员工启用Lync帐号.语音功能以及导出统计当前哪些用户开启Lync权限,在这里我简单汇总一些常用的,供大家参考,后期我还会将用到的命令出来供大家平时运维使用. 1.强制刷新更新状态 Invoke-CSManagementStoreReplication 2.检查更新状态 Get-CsManagementStoreReplicationStatus 3.为禁用的账户开启Lync功能 Enable-CsUser 4.为某个部门开启l

AIX—日常运维命令总结

查看系统IP地址: netstat  -in 1. 查看AIX服务器的物理构造信息,包括服务器网络配置信息 #  prtconf #  ifconfig   -a #  lsattr  -E  -l  mem0     :查看系统内存大小 #  netstat  -in             :显示系统各网卡的配置信息 2. 开启和关闭AIX服务器 #  shutdown  -F  :快速关机 #  shutdown  -I :采用交互式模式关闭系统 #  shutdown  -K :避免关闭

ogg日常运维命令

1.查看历史记录.快捷执行历史中的一条命令 GGSCI (11g) 32> h 23: view param exta24: info all25: lag exta.... GGSCI (11g) 33> ! 24-- 这里相当于执行了 上面 24: info all 的命令. 2.查看参数设置使用view params <进程名> 可以查看进程的参数设置.该命令同样支持通配符*. 3.查看进程状态使用 info <进程名> 命令可以查看进程信息.可以查看到的信息包括

linux日常运维命令

修改系统时间 [[email protected] ~]# date -s "2012-11-16 10:16:00" [[email protected] ~]# clock -w 2.查看系统的内核 [[email protected] ~]#  uname–a 3.查看linux服务器物理CPU的个数 [[email protected] ~]# cat /proc/cpuinfo | grep "physicalid" | sort | uniq  | wc

日常运维命令

监控系统状态进行初步的判定w命令时间 用户 网络用户显示是pts tty1 客户端 load average系统负载 :1分钟,5分钟,15分钟时间段内系统负载是多少 单位时间段内使用CUP活动的进程 都是平均值 查看逻辑CPU 显示的比实际少1 processor 系统负载第一段时间段不高于8合适 5分钟内平均有多少个进程login 登录时间 uptime 当显示系统cpu不够用时 想要进一步查询vmstat 1 5 每一秒显示 显示5次r=run 表示有多少个进程处于在执行中 b=block

日常运维命令2

监控系统状态iostat 1 每秒显示硬盘 读写速度iostat -x 1%util 表示等待IOiotop 安装显示占用IO的进程read 读的速度 write 写到速度 swapin 交换分区free free -hbuff/cache 缓冲和缓存 从磁盘度数据 交给CPU 中间需要一个内存(cache) CPU 计算完的数据存到磁盘里去 中间需要内存(buff)available=free+buff/cache(剩余)ps 命令ps aux 列出所以进程的状况ps aux | 检查进程用户

CentOS日常运维命令

查看剩余内存: free -m #-/+ buffers/cache: 6458 1649 #6458M为真实使用内存 1649M为真实剩余内存(剩余内存+缓存+缓冲器) #linux会利用所有的剩余内存作为缓存,所以要保证linux运行速度,就需要保证内存的缓存大小 系统信息: uname -a # 查看Linux内核版本信息 cat /proc/version # 查看内核版本 cat /etc/issue # 查看系统版本 lsb_release -a # 查看系统版本 需安装 cento

zookeeper 用法和日常运维

本文以ZooKeeper3.4.3版本的官方指南为基础:http://zookeeper.apache.org/doc/r3.4.3/zookeeperAdmin.html,补充一些作者运维实践中的要点,围绕ZK的部署和运维两个方面讲一些管理员需要知道的东西.本文并非一个ZK搭建的快速入门,关于这方面,可以查看<ZooKeeper快速搭建>. 1.部署 本章节主要讲述如何部署ZooKeeper,包括以下三部分的内容: 系统环境 集群模式的配置 单机模式的配置 系统环境和集群模式配置这两节内容大