一、概述
首先,你要知道Gitlab/Github不是Git.
Git是版本控制系统,Github是在线的基于Git的代码托管服务。.
Github同时提供付费账户和免费账户。这两种账户都可以创建公开的代码仓库,但是付费账户也可以创建私有的代码仓库。
Gitlab是一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
二、安装Git(非必须,系统一般有安装git 1.7)Git必看书籍Pro Git这本书(也可以看其电子版)绝对是Git入门和进深的不二选择。
英文版: https://git-scm.com/book/en/v2
中文版:https://git-scm.com/book/zh/v2
1、依赖关系
yum -y install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum -y install gcc* perl-ExtUtils-MakeMaker xmlto asciidoc
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
# tar zxvf libiconv-1.14.tar.gz
# cd libiconv-1.14
# ./configure --prefix=/usr/local/libiconv
# make -j 4 && make -j 4 install
2、安装
# yum remove git
#注意,如果系统升级了python要修改/usr/bin/asciidoc 第一行
为“#!/usr/bin/env python2” 。 /// (/usr/bin/python2)
# tar zxvf v2.12.1.tar.gz
# cd git-2.12.1
# make configure
# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
# make -j 4 all doc
# make -j 4 install install-doc install-html
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc
# echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile.d/git.sh
# source /etc/bashrc // source /etc/profile
查看版本号
# git --version
git version 2.12.1
完成后,你可以使用 Git 来获取 Git 的升级:
# git clone git://git.kernel.org/pub/scm/git/git.git
三、安装Gitlab
官方详细解释:https://about.gitlab.com/downloads/#centos6
1. 准备
#On Centos 6 and 7, the commands below will also open HTTP and SSH access in the system firewall.
#这句是用来做防火墙的。避免用户通过ssh方式和http来访问
lokkit -s http -s ssh
yum -y install curl openssh-server openssh-clients postfix cronie
service postfix start
chkconfig postfix on
lokkit -s http -s ssh
service postfix start
chkconfig postfix on
ss -tnlp
#无法启动则查看日志 tail -f /var/log/maillog
2. 安装
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum -y install gitlab-ce
#If you are not comfortable installing the repository through a piped script, you can find the entire script here and select and download the package manually and install using
#https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/
curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-XXX.rpm/download
rpm -i gitlab-ce-XXX.rpm
3. 启动和配置
#对GitLab进行编译。
gitlab-ctl reconfigure
#Running handlers:
#Running handlers complete
#Chef Client finished, 108/329 resources updated in 01 minutes 12 seconds
#gitlab Reconfigured!
#查看状态
gitlab-ctl status
run: gitlab-workhorse: (pid 5359) 134s; run: log: (pid 5190) 161s
run: logrotate: (pid 5281) 149s; run: log: (pid 5280) 149s
run: nginx: (pid 5236) 155s; run: log: (pid 5235) 155s
run: postgresql: (pid 3547) 854s; run: log: (pid 2415) 1703s
run: redis: (pid 3555) 853s; run: log: (pid 2278) 1714s
run: sidekiq: (pid 5144) 167s; run: log: (pid 5143) 167s
run: unicorn: (pid 5089) 173s; run: log: (pid 5088) 173s
ps -ef|grep unicorn
root 5087 2230 0 09:38 ? 00:00:00 runsv unicorn
root 5088 5087 0 09:38 ? 00:00:00 svlogd -tt /var/log/gitlab/unicorn
git 5089 5087 0 09:38 ? 00:00:00 /bin/bash /opt/gitlab/embedded/bin/gitlab-unicorn-wrapper
git 5107 1 2 09:38 ? 00:00:11 unicorn master -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
git 5271 5107 0 09:39 ? 00:00:00 unicorn worker[0] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
git 5274 5107 0 09:39 ? 00:00:00 unicorn worker[1] -D -E production -c /var/opt/gitlab/gitlab-rails/etc/unicorn.rb /opt/gitlab/embedded/service/gitlab-rails/config.ru
#登录gitlab
#第一次登录gitlab,需要为root用户修改密码,root用户也是gitlab的超级管理员
#解决 80 端口被占用 和GitLab头像无法正常显示
#原因:gravatar被墙 解决办法: 编辑 /etc/gitlab/gitlab.rb,将井号删除
gitlab_rails['gravatar_plain_url'] = 'http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'
#并且
external_url 'http://192.168.18.41:8888'
#external_url 'http://192.168.18.13' //测试物理机直接用得80端口,不推荐。
#然后在命令行执行:
gitlab-ctl reconfigure
gitlab-rake cache:clear RAILS_ENV=production
#gitlab-ctl reconfigure 会生成N多配置,请探索“/var/opt/gitlab/”。
#直接nginx配置可以变更端口,但是GitLab头像无法正常显示。
#若有读者发现变更端口后正常显示头像的方法请一定要分享给大家。
#配置文件:/var/opt/gitlab/nginx/conf/gitlab-http.conf
#然后事实上默认就生成有upstream gitlab-workhorse,所以改改listen的端口就足以。
upstream gitlab {
server unix:/var/opt/gitlab/gitlab-workhorse/socket;
}
server {
#侦听的9999端口,端口我改过N多个所有不用在意这条注释。
listen 8888;
server_name *.renn.top;
location / {
proxy_pass http://gitlab; #在这里设置一个代理,和upstream的名字一样
#以下是一些反向代理的配置可删除
proxy_redirect off;
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout 300; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 300; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 300; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
}
End
以下内容是我从网上找的并整理,请原谅粗心的我已忘记出处(毕竟阅读了30+的文章)。
部分翻译自官方的E文,有不准确处望谅解。
-------------------------------------
运维
# 启动所有 gitlab 组件:
sudo gitlab-ctl start
# 停止所有 gitlab 组件:
sudo gitlab-ctl stop
# 重启所有 gitlab 组件:
sudo gitlab-ctl restart
# 查看服务状态
sudo gitlab-ctl status
# 启动服务
sudo gitlab-ctl reconfigure
# 修改默认的配置文件
sudo vim /etc/gitlab/gitlab.rb
# 查看版本
sudo cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
# echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
# sysctl -p
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
# 检查gitlab
gitlab-rake gitlab:check SANITIZE=true --trace
# 查看日志
sudo gitlab-ctl tail
备份恢复
#Gitlab 创建备份
#使用Gitlab一键安装包安装Gitlab非常简单, 同样的备份恢复与迁移也非常简单,用一条命令即可创建完整的Gitlab备份:
gitlab-rake gitlab:backup:create
#以上命令将在/var/opt/gitlab/backups目录下创建一个名称类似为xxxxxxxx_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的xxxxxx是备份创建的时间戳。
Gitlab 修改备份文件默认目录
#修改/etc/gitlab/gitlab.rb来修改默认存放备份文件的目录:
gitlab_rails['backup_path'] = '/mnt/backups'
#修改后使用gitlab-ctl reconfigure命令重载配置文件。
备份
0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
恢复
#首先进入备份 gitlab 的目录,这个目录是配置文件中的 gitlab_rails['backup_path'] ,默认为 /var/opt/gitlab/backups 。
#然后停止 unicorn 和 sidekiq ,保证数据库没有新的连接,不会有写数据情况。
# 停止相关数据连接服务
# ok: down: unicorn: 0s, normally up
gitlab-ctl stop unicorn
# ok: down: sidekiq: 0s, normally up
gitlab-ctl stop sidekiq
# 从xxxxx编号备份中恢复
# 然后恢复数据,xxxxx为备份文件的时间戳
gitlab-rake gitlab:backup:restore BACKUP=xxxxxx
# 启动Gitlab
sudo gitlab-ctl start
----------------------------------------
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com