安装
Ubuntu 16.04 x64搭建GitLab服务器操作笔记
Ubuntu16.04 安装Gitlab
gitla 仓库默认存储路径:/var/opt/gitlab/git-data/repositories
1.安装依赖包
1 | sudo apt-get install curl openssh-server ca-certificates postfix |
执行完成后,出现邮件配置,选择Internet那一项(不带Smarthost的)
2.利用清华大学的镜像https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
来进行主程序的安装。
首先信任 GitLab 的 GPG 公钥:1
curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
3.利用root用户1(不是sudo,而是root),vi打开文件/etc/apt/sources.list.d/gitlab-ce.list,加入下面一行:
1 | deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main |
4.安装 gitlab-ce:
1 | sudo apt-get update |
5.执行命令
1 | sudo gitlab-ctl reconfigure |
6.打开 sshd 和 postfix 服务
1 | service sshd start |
7.了使 GitLab 社区版的 Web 界面可以通过网络进行访问,我们需要允许 80 端口通过防火墙,这个端口是 GitLab 社区版的默认端口。为此需要运行下面的命令
1 | sudo iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT |
8.检查GitLab是否安装好并且已经正确运行,输入下面的命令
1 | sudo gitlab-ctl status |
9.如果得到类似下面的结果,则说明GitLab运行正常
1 | run: gitlab-workhorse: (pid 1148) 884s; run: log: (pid 1132) 884s |
10.在浏览器地址栏中输入:http://127.0.0.1,即可访问GitLab的Web页面
汉化
1.在仓库中创建gitlab_cn
文件夹
1 | cd /var/opt/gitlab/git-data/repositories/ |
2.克隆gitlab仓库到本地。 xhang项目 比较新,所以在这拉取xhang项目
larryli项目:https://gitlab.com/larryli/gitlab
xhang项目:https://gitlab.com/xhang/gitlab1
2
3
4
5
6
7 克隆 GitLab.com 仓库
git clone https://gitlab.com/larryli/gitlab.git
#或 Gitcafe.com 镜像,速度更快
git clone https://gitcafe.com/larryli/gitlab.git
xhang项目
git clone https://gitlab.com/xhang/gitlab.git
如果已有此项目,则更新:1
git fetch
3.确定Gitlab安装版本
1 | cat /opt/gitlab/embedded/service/gitlab-rails/VERSION |
4.生成汉化补丁
1 | 进入克隆仓库得到的gitlab目录 |
5.打完补丁后启动就可以了
1 | 停止gitlab |
可能遇到的问题
解决方法:https://gitlab.com/xhang/gitlab/uploads/23e8414e53eefde0968e960b24a6f631/_%E5%8E%9F%E5%88%9B_Gitlab10.8.0%E5%88%86%E6%94%AF%E6%B1%89%E5%8C%96_Omnibus%E7%89%88_.png
10.8.1版本补丁错误 :https://gitlab.com/xhang/gitlab/issues/63
1.首先删除之前生成的补丁
1 | rm /tmp/11.1.2.diff |
切换到gitlab目录下1
cd /var/opt/gitlab/git-data/repositories/gitlab_cn/gitlab/
2.生成补丁
app/assets 已经不在包含于部署的代码中,因此 git diff 的时候需要跳过这个目录1
2IGNORE_DIRS=':!spec :!features :!.gitignore :!locale :!app/assets/ :!vendor/assets/'
git diff --diff-filter=d v11.1.2..v11.1.2-zh -- . ${IGNORE_DIRS} > /tmp/11.1.2-zh_CN.diff
3.打补丁
1 | cd /opt/gitlab/embedded/service/gitlab-rails |
4.将缺少的目录和文件复制到服务器
将汉化仓库中app/assets
文件夹和vendor/assets
复制到服务器1
2
3
4
5cd /opt/gitlab/embedded/service/gitlab-rails/app/
cp -r /var/opt/gitlab/git-data/repositories/gitlab_cn/gitlab/app/assets/ assets
cd /opt/gitlab/embedded/service/gitlab-rails/vendor/
cp -r /var/opt/gitlab/git-data/repositories/gitlab_cn/gitlab/vendor/assets/ assets
5.然后启动就可以愉快的玩耍了
1 | gitlab-ctl start |
其他事项
1.修改gitlab配置文件指定服务器ip和自定义端口:
1 | sudo vi /etc/gitlab/gitlab.rb |
每次修改/etc/gitlab/gitlab.rb,都要运行以下命令,让配置生效
设置完成后重新加载启动:1
2gitlab-ctl reconfigure
gitlab-ctl restart
2.备份
参考文档:
快速安装 GitLab 并汉化
git学习——> Gitlab如何进行备份恢复与迁移?
1.备份配置文件
配置文件含密码等敏感信息,不要和数据备份文件放在一起。1
sh -c 'umask 0077; tar -cf $(date "+etc-gitlab-%s.tar") -C /etc/gitlab'
2.备份gitlab
默认数据备份目录是/var/opt/gitlab/backups
,手动创建备份文件1
2 Omnibus 方式安装使用以下命令备份
sudo gitlab-rake gitlab:backup:create
3.定时备份gitlab
方法1.在命令行输入: crontab -e 然后添加相应的任务,wq存盘退出。1
2
3
4输入命令crontab -e
sudo crontab -e
输入相应的任务
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
方法2、直接编辑/etc/crontab 文件,即vi /etc/crontab,然后添加相应的任务1
2
3
4编辑 /etc/crontab
vi /etc/crontab
edited by ouyang 2017-8-11 添加定时任务,每天凌晨两点,执行gitlab备份
0 2 * * * root /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
编写完 /etc/crontab 文件之后,需要重新启动cron服务1
2
3
4重新加载cron配置文件
sudo /usr/sbin/service cron reload
重启cron服务
sudo /usr/sbin/service cron restart
4.设置配置文件
修改/etc/gitlab/gitlab.rb
文件1
2
3
4
5
6 备份保留天数为3个月(即90天,这里是7776000秒)
gitlab_rails['backup_keep_time'] = 7776000
默认备份权限
gitlab_rails['backup_archive_permissions'] = 0644
默认本分路径
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
修改完成之后使用下面命令重载配置文件1
gitlab-ctl reconfigure
3、恢复
==确保备份文件所安装 GitLab 和当前要恢复的 GitLab 版本一致 #ff0000==
1.复制数据文件,将备份文件权限修改为777,不然可能恢复的时候会出现权限不够,不能解压的问题
1 | 将数据备份文件拷贝至备份目录 |
2.执行命令停止相关数据连接服务
1 | 停止相关数据连接服务 |
3.执行命令从备份文件中恢复Gitlab
*_gitlab_backup.tar
*表示备份文件编号
例如:1502357536_2017_08_10_9.4.3_gitlab_backup.tar
文件编号为1502357536_2017_08_10_9.4.3
1 | gitlab-rake gitlab:backup:restore BACKUP=备份文件编号 |
4.启动Gitlab
1 | sudo gitlab-ctl start |