【linux】【gitlab】gitlab安装、备份、恢复、升级、内存消耗问题
前言
GitLab:GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
功能:Gitlab 是一个提供代码托管、提交审核和问题跟踪的代码管理平台。对于软件工程质量管理非常重要。
版本:GitLab 分为社区版(CE) 和企业版(EE)。
配置:建议CPU2核,内存2G以上。
安装
一、gitlab安装
1、安装gitlab yum库
1.安装最新版gitlab-ee(企业版)
- curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
2.安装最新版gilab-ce(社区版)
- curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
2、安装gitlab
其中ip为gitlab的访问地址。
1.企业最新版:
- EXTERNAL_URL="http://ip" yum install -y gitlab-ee
2.社区最新版:
- EXTERNAL_URL="http://ip" yum install -y gitlab-ce
3.安装指定版本:
- EXTERNAL_URL="http://ip" yum install -y gitlab-ee-12.1.9-ee.0.el7.x86_64
- EXTERNAL_URL="http://ip" yum install -y gitlab-ce-12.1.9-ce.0.el7.x86_64
4.安装完成基本指令:
查看运行状态
- gitlab-ctl status
启动
- gitlab-ctl start
停止
- gitlab-ctl stop
重启
- gitlab-ctl restart
查看版本
- cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
重载配置
- gitlab-ctl reconfigure
3、访问gitlab
http://ip 浏览器打开
设置root管理员初始密码。
设置邮箱及https等请参考原文。
本文参考CSDN“一缕南风”博主,原文链接:https://blog.csdn.net/weixin_43767602/article/details/84568858
二、gitlab备份、恢复
1.gitlab备份
1.设置gitlab备份目录、权限、有限期
[root@localhost /]# cat /etc/gitlab/gitlab.rb | grep -v "#"
external_url 'http://192.168.8.127' //安装设定的访问域名
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups" //备份路径
gitlab_rails['backup_archive_permissions'] = 0644 //备份文件权限
gitlab_rails['backup_keep_time'] = 7776000 //备份文件有效期 30天
2.创建备份路径
[root@localhost /]# mkdir -vp /data/gitlab/backups
mkdir: 已创建目录 "/data"
mkdir: 已创建目录 "/data/gitlab"
mkdir: 已创建目录 "/data/gitlab/backups"
3.重载配置
[root@localhost /]# gitlab-ctl reconfigure
Starting Chef Client, version 14.13.11
resolving cookbooks for run list: ["gitlab-ee"]
Synchronizing Cookbooks:
- gitlab-ee (0.0.1)
- package (0.1.0)
- gitlab (0.0.1)
- consul (0.1.0)
- runit (4.3.0)
- redis (0.1.0)
- repmgr (0.1.0)
- postgresql (0.1.0)
- gitaly (0.1.0)
- letsencrypt (0.1.0)
- monitoring (0.1.0)
- registry (0.1.0)
- mattermost (0.1.0)
- nginx (0.1.0)
- acme (4.0.0)
- crond (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Recipe: gitlab::default
……
……
……
(up to date)
Recipe: <Dynamically Defined Resource>
* service[repmgrd] action nothing (skipped due to action :nothing)
Recipe: repmgr::repmgrd_disable
* runit_service[repmgrd] action disable
* ruby_block[disable repmgrd] action run (skipped due to only_if)
(up to date)
Recipe: gitlab-ee::geo-secondary_disable
* templatesymlink[Removes database_geo.yml symlink] action delete
* file[/var/opt/gitlab/gitlab-rails/etc/database_geo.yml] action delete (up to date)
* link[/opt/gitlab/embedded/service/gitlab-rails/config/database_geo.yml] action delete (up to date)
(up to date)
Recipe: <Dynamically Defined Resource>
* service[unicorn] action restart
- restart service service[unicorn]
* service[sidekiq] action restart
- restart service service[sidekiq]
Recipe: gitlab::gitlab-rails
* execute[clear the gitlab-rails cache] action run
- execute /opt/gitlab/bin/gitlab-rake cache:clear
Running handlers:
Running handlers complete
Chef Client finished, 10/708 resources updated in 29 seconds
4.开始备份
[root@localhost /]# gitlab-rake gitlab:backup:create
2019-09-16 11:00:23 +0800 -- Dumping database ...
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2019-09-16 11:00:24 +0800 -- done
2019-09-16 11:00:24 +0800 -- Dumping repositories ...
2019-09-16 11:00:24 +0800 -- done
2019-09-16 11:00:24 +0800 -- Dumping uploads ...
2019-09-16 11:00:24 +0800 -- done
2019-09-16 11:00:24 +0800 -- Dumping builds ...
2019-09-16 11:00:24 +0800 -- done
2019-09-16 11:00:24 +0800 -- Dumping artifacts ...
2019-09-16 11:00:24 +0800 -- done
2019-09-16 11:00:24 +0800 -- Dumping pages ...
2019-09-16 11:00:24 +0800 -- done
2019-09-16 11:00:24 +0800 -- Dumping lfs objects ...
2019-09-16 11:00:24 +0800 -- done
2019-09-16 11:00:24 +0800 -- Dumping container registry images ...
2019-09-16 11:00:24 +0800 -- [DISABLED]
Creating backup archive: 1568602824_2019_09_16_12.2.5-ee_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)
30 Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
31 and are not included in this backup. You will need these files to restore a backup.
32 Please back them up manually.
Backup task is done.
红字部分表示 gitlab.rb 和 gitlab-secrets.json 两个文件包含敏感信息。未被备份到备份文件中。需要手动备份。
[root@localhost backups]# pwd
/data/gitlab/backups
[root@localhost backups]# ls -l
总用量 132
-rw-r--r-- 1 git git 133120 9月 16 11:00 1568602824_2019_09_16_12.2.5-ee_gitlab_backup.tar
[root@localhost backups]#
执行完成后在 /data/gitlab/backups 中生成了备份文件。
2.gitlab恢复备份
1.首先停用gitlab的数据连接部分服务
[root@localhost backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@localhost backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@localhost backups]# gitlab-ctl stop nginx
ok: down: nginx: 0s, normally up
[root@localhost backups]# gitlab-ctl status
run: alertmanager: (pid 30960) 3683s; run: log: (pid 30623) 3735s
run: gitaly: (pid 30846) 3685s; run: log: (pid 30081) 3828s
run: gitlab-monitor: (pid 30843) 3685s; run: log: (pid 30498) 3753s
run: gitlab-workhorse: (pid 30820) 3686s; run: log: (pid 30349) 3784s
run: grafana: (pid 30980) 3682s; run: log: (pid 30750) 3698s
run: logrotate: (pid 37253) 178s; run: log: (pid 30384) 3777s
down: nginx: 4s, normally up; run: log: (pid 30368) 3781s
run: node-exporter: (pid 30830) 3685s; run: log: (pid 30418) 3764s
run: postgres-exporter: (pid 30971) 3683s; run: log: (pid 30650) 3730s
run: postgresql: (pid 30127) 3825s; run: log: (pid 30139) 3821s
run: prometheus: (pid 30943) 3684s; run: log: (pid 30588) 3741s
run: redis: (pid 29960) 3838s; run: log: (pid 29972) 3835s
run: redis-exporter: (pid 30854) 3684s; run: log: (pid 30522) 3747s
down: sidekiq: 13s, normally up; run: log: (pid 30324) 3788s
down: unicorn: 17s, normally up; run: log: (pid 30307) 3792s
2.执行恢复
远程复制的备份需要 chmod 777 1568602824_2019_09_16_12.2.5-ee..... 赋予权限
[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1568602824_2019_09_16_12.2.5-ee
Unpacking backup ... done
Before restoring the database, we will remove 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)? yes
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes Deleting tmp directories ... done
done
done
done
done
done
done
done
21 Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data
22 and are not included in this backup. You will need to restore these files manually.
Restore task is done.
备份tar包一定要放到备份路径下。恢复是删除原有数据,恢复备份tar包中的数据。
如果是在其他服务器恢复备份,一定要记得将 gitlab.rb 和 gitlab-secrets.json 手动复制到相应路径下。
gitlab.rb路径:/etc/gitlab/gitlab.rb
gitlab-secrets.json路径:/etc/gitlab/gitlab-secrets.json
3.重载配置
- gitlab-ctl reconfigure
4.重启gitlab,check检查
[root@localhost backups]# gitlab-ctl restart
ok: run: alertmanager: (pid 30960) 3785s
ok: run: gitaly: (pid 30846) 3787s
ok: run: gitlab-monitor: (pid 30843) 3787s
ok: run: gitlab-workhorse: (pid 30820) 3788s
ok: run: grafana: (pid 30980) 3784s
ok: run: logrotate: (pid 37253) 280s
ok: run: nginx: (pid 37535) 0s
ok: run: node-exporter: (pid 30830) 3787s
ok: run: postgres-exporter: (pid 30971) 3785s
ok: run: postgresql: (pid 30127) 3927s
ok: run: prometheus: (pid 30943) 3786s
ok: run: redis: (pid 29960) 3940s
ok: run: redis-exporter: (pid 30854) 3786s
ok: run: sidekiq: (pid 37547) 1s
ok: run: unicorn: (pid 37553) 0s
[root@localhost backups]# gitlab-rake gitlab:check SANITIZE=true
Checking GitLab subtasks ... Checking GitLab Shell ... GitLab Shell: ... GitLab Shell version >= 9.3.0 ? ... OK (9.3.0)
Running /opt/gitlab/embedded/service/gitlab-shell/bin/check
Check GitLab API access: OK
Redis available via internal API: OK Access to /var/opt/gitlab/.ssh/authorized_keys: OK
gitlab-shell self-check successful Checking GitLab Shell ... Finished Checking Gitaly ... Gitaly: ... default ... OK Checking Gitaly ... Finished Checking Sidekiq ... Sidekiq: ... Running? ... yes
Number of Sidekiq processes ... 1 Checking Sidekiq ... Finished Checking Incoming Email ... Incoming Email: ... Reply by email is disabled in config/gitlab.yml Checking Incoming Email ... Finished Checking LDAP ... LDAP: ... LDAP is disabled in config/gitlab.yml Checking LDAP ... Finished Checking GitLab App ... 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? ... skipped (no tmp uploads folder yet)
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: ... can't check, you have no projects
Redis version >= 2.8.0? ... yes
Ruby version >= 2.5.3 ? ... yes (2.6.3)
Git version >= 2.22.0 ? ... yes (2.22.0)
Git user has default SSH configuration? ... yes
Active users: ... 1
Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled) Checking GitLab App ... Finished Checking GitLab subtasks ... Finished
ok,至此恢复完成
三、gitlab版本升级
1.停止数据传输服务
[root@localhost backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@localhost backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@localhost backups]# gitlab-ctl stop nginx
ok: down: nginx: 1s, normally up
[root@localhost backups]# gitlab-ctl status
run: gitaly: (pid 73164) 939s; run: log: (pid 72843) 968s
run: gitlab-monitor: (pid 73232) 938s; run: log: (pid 73021) 957s
run: gitlab-workhorse: (pid 75742) 136s; run: log: (pid 72919) 962s
run: logrotate: (pid 72985) 960s; run: log: (pid 72984) 960s
down: nginx: 5s, normally up; run: log: (pid 72960) 961s
run: node-exporter: (pid 73003) 959s; run: log: (pid 73002) 959s
run: postgres-exporter: (pid 73253) 937s; run: log: (pid 73086) 948s
run: postgresql: (pid 72644) 997s; run: log: (pid 72643) 997s
run: prometheus: (pid 73241) 938s; run: log: (pid 73064) 950s
run: redis: (pid 72598) 1003s; run: log: (pid 72597) 1003s
run: redis-exporter: (pid 73048) 951s; run: log: (pid 73047) 951s
down: sidekiq: 7s, normally up; run: log: (pid 72818) 974s
down: unicorn: 10s, normally up; run: log: (pid 72778) 976s
2.下载最新的ce/ee rpm包(清华源https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el7/ 或者https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/)
- wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el7/gitlab-ee-12.2.5-ee.0.el7.x86_64.rpm
gitlab10.0.0版本升级最新版本需要先升级到11.11.0,再升级12.2.5!
3.升级ce/ee
- rpm -Uvh gitlab-ee-12.2.5-ee.0.el7.x86_64.rpm
4.重载配置
- gitlab-ctl reconfigure
5.重启gitlab
- gitlab-ctl restart
四、gitlab解决内存消耗问题
[root@storage100 backups]# cat /etc/gitlab/gitlab.rb | grep -v "#"
#进程超时时间
unicorn['worker_timeout'] = 60
#进程数
unicorn['worker_processes'] = 10
#进程最小内存
unicorn['worker_memory_limit_min'] = "200 * 1 << 20"
#进程最大内存
unicorn['worker_memory_limit_max'] = "300 * 1 << 20"
#并发数
sidekiq['concurrency'] = 16
#数据库缓存
postgresql['shared_buffers'] = "256MB"
#数据库并发数
postgresql['max_worker_processes'] = 8
参考CSDN博主"欧阳鹏",原文链接:https://blog.csdn.net/ouyang_peng/article/details/84066417
附gitlab备份脚本:
#!/bin/bash #Gitlab 备份地址
LocalBackDir=/home/gitlab/data/backups #服务机gitlab配置文件地址
#正式环境地址:
ConfigDir=/etc/gitlab/gitlab.rb #nginx配置文件地址
#正式环境地址:NginxDir=/home/dgd/gitlab/data/nginx/conf #邮件配置地址
#MailDir=/etc/postfix/main.cf #Backup server 存储路径
RemoteBackDir=/home/gitlab/data/backups #远程备份使用用户及端口
RemoteUser=root
RemotePort=22 #备份服务器IP
RemoteIP=192.168.8.200 #以当前时间戳创建备份目录
bakname=$(date -d "today" +"%Y%m%d_%H%M%S")
BakDir=$LocalBackDir/$bakname
mkdir $BakDir #备份日志文件
LogFile=$LocalBackDir/remote_backup.log #新建备份日志文件
touch $LogFile #记录配置文件备份日志
echo "Gitlab configure file auto backup at local server, start at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
echo "--------------------------------------------------------------------------" >> $LogFile #拷贝配置文件
cp $ConfigDir $BakDir >> $LogFile 2>&1
#cp -r $NginxDir $BakDir >> $LogFile 2>&1
#cp $MailDir $BakDir >> $LogFile 2>&1 #记录本地生成gitlab备份日志
echo "Gitlab auto backup at local server, start at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
echo "--------------------------------------------------------------------------" >> $LogFile #执行gitlab本地备份
gitlab-rake gitlab:backup:create >> $LogFile 2>&1 # $?符号显示上一条命令的返回值,如果为0则代表执行成功,其他表示失败
if [ $? -eq 0 ];then
#追加日志到日志文件
echo "--------------------------------Success!-------------------------------" >> $LogFile
echo "Gitlab auto backup at local server, end at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
else
#追加日志到日志文件
echo "--------------------------------Failed!----------------------------------" >> $LogFile
echo "Gitlab auto backup at local server failed at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
fi #查找本地备份目录修改时间为10分钟以内且后缀为.tar的Gitlab备份文件
Backfile_Send_To_Remote=`find $LocalBackDir -type f -mmin -10 -name '*.tar'` >> $LogFile 2>&1 #移动生成的备份文件到配置文件备份地址
mv -bfu $Backfile_Send_To_Remote $BakDir #记录备份日志
echo "$(date +"%Y-%m-%d %H:%M:%S") Gitlab auto backup to remote server." >> $LogFile
echo "--------------------------------------------" >> $LogFile #打印每次备份的档案名
echo "The files need send to remote server is: $Backfile_Send_To_Remote" >> $LogFile # 本地传输Gitlab备份档案到远程
scp -r $BakDir $RemoteUser@$RemoteIP:$RemoteBackDir # 备份结果追加到备份日志
if [ $? -eq 0 ];then
echo ""
echo "$(date +"%Y-%m-%d %H:%M:%S") Gitlab Remote Backup Succeed!" >> $LogFile
else
echo "$(date +"%Y-%m-%d %H:%M:%S") Gitlab Remote Backup Failed!" >> $LogFile
fi
【linux】【gitlab】gitlab安装、备份、恢复、升级、内存消耗问题的更多相关文章
- git学习------> Gitlab如何进行备份恢复与迁移?
前段时间,在某台CenterOS服务器上搭建了Gitlab环境,并且大家陆陆续续的都把代码从svn迁移到了gitlab,但是之前的CenterOS服务器并不是搭建在公司的机房环境,而是搭建在办公室的某 ...
- Gitlab如何进行备份恢复与迁移?
https://blog.csdn.net/ouyang_peng/article/details/77070977 1.Gitlab 创建备份 1.1 创建备份文件 首先我们得把老服务器上的Gitl ...
- Gitlab配置、备份、升级、迁移
0.Gitlab安装 1.安装和配置必要的依赖关系 在CentOS7,下面的命令将在系统防火墙打开HTTP和SSH访问. yum install curl openssh-server postfix ...
- gitlab之数据备份恢复
备份#备份的时候,先通知相关人员服务要听 ,停止两个服务,并影响访问 root@ubuntu:/opt/web1# gitlab-ctl stop unicorn ok: down: unicorn: ...
- [转]Linux/Unix系统镜像/备份/恢复 (dd 命令使用)
ref: http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=22561912&id=156879 开源系统默认安装了一个d ...
- linux 通过scp 复制备份恢复mysql数据表
最近客户有个需求,小弟对于运维的东西也是半瓶醋,所以就果断的摸索了下.折磨了一个晚上终于算是搞定了.因为是两个不同的服务器,本来想用ftp,无奈小弟不是很熟悉,所以就用了scp,但是scp有个问题就是 ...
- Linux下的Mysql备份/恢复
数据库逻辑备份 逻辑备份:将数据库的数据以逻辑的SQL语句的方式导出 查看帮助 mysqldump --help 0.数据库开启状态 1.备份某个特定的库: mysqldump -uroot -pro ...
- redis安装-备份-恢复
1.安装参考:https://www.jb51.net/article/146744.htm 2.安装ruby2.3.3 .gpg2 --keyserver hkp://keys.gnupg.net ...
- Centos 8 上定时备份Gitlab ,脚本实现定时备份,备份恢复
定时备份 要求 为了能够备份和恢复,请确保你的系统上安装了Rsync yum install rsync -y 配置备份目标机器免密认证 执行ssh-keygen -t rsa 生成私钥和公钥 ssh ...
随机推荐
- HTML基础介绍
前言: H5是目前行业里非常热门的一种语言,学习难度较低,可以快速入门.我个人也在学习H5,采用写博客的方式来梳理我学到的知识点,也分享给更多想学习的人一起来学习. Tip:个人学习过程中梳理的知识点 ...
- 如何配置sigar在Linux和Windows下使用java语言获得各种系统信息
转自:https://blog.csdn.net/qq_27093465/article/details/70227619
- 基于python的mysql复制工具
一简介 python-mysql-replication 是由python实现的 MySQL复制协议工具,我们可以用它来解析binlog 获取日志的insert,update,delete等事件 ,并 ...
- Linux shell脚本判断服务器网络是否可以上网
Linux shell脚本判断网络畅通 介绍 在编写shell脚本时,有的功能需要确保服务器网络是可以上网才可以往下执行,那么此时就需要有个函数来判断服务器网络状态 我们可以通过curl来访问 www ...
- python request接口测试笔记(1)
python request接口测试笔记(1) 涉及到的功能说明: 需要登录拿到token,才能进行下一个接口的请求 读取csv文件中的信息,作为接口的参数 将接口响应结果,写入csv文件,以便分析统 ...
- (五十四)c#Winform自定义控件-仪表盘
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- hdu-6681 Rikka with Cake
题目链接 hdu-6681 Problem Description Rikka's birthday is on June 12th. The story of this problem happen ...
- 牛客练习赛39 D 动态连通块+并查集 X bitset 优化
https://ac.nowcoder.com/acm/contest/368/D 题意 小T有n个点,每个点可能是黑色的,可能是白色的.小T对这张图的定义了白连通块和黑连通块:白连通块:图中一个点集 ...
- HDU-4725 The Shortest Path in Nya Graph (拆点+dji)
HDU 4725 The Shortest Path in Nya Graph : http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意: 在一个图中跑最 ...
- 【Offer】[49] 【丑数】
题目描述 思路分析 测试用例 Java代码 代码链接 题目描述 我们把只包含因子2.3和5的数称作丑数( Ugly Number).求按从小到大的顺序的第1500个丑数.例如,6.8都是丑数,但14不 ...