centos6.8安装 gitlab 9.3.5及使用

环境准备:

[root@caosm03 conf]# cat /etc/issue
CentOS release 6.8 (Final)
Kernel \r on an \m
注意:这个需要配置好主机名不然安装的时候会出现地址错误
[root@caosm03 caosm]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.24.130 caosm03.com 

1.安装配置依赖项

[root@caosm03 ~]#yum install curl openssh-server openssh-clients postfix cronie  -y 
[root@caosm03 ~]#service postfix start  #GitLab使用postfix发送邮件  
[root@caosm03 ~]#chkconfig postfix on   #设置postfix开机自启动  
[root@caosm03 ~]#lokkit -s http -s ssh  #配置iptables开放http和ssh端口,这里需要注意,腾讯云安全组选择那里要选择开放所有端口  
#这一步可能会显示failed ip6tables start,这个不需要管,直接运行下面查看是否打开端口就可以了  

输入命令查看是否打开http和ssh端口

[root@caosm03 ~]# iptables -L

Chain INPUT (policy ACCEPT)

target prot opt source destination

ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED

ACCEPT icmp -- anywhere anywhere

ACCEPT all -- anywhere anywhere

ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh

ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http

REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

target prot opt source destination

REJECT all -- anywhere anywhere reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

target prot opt source destination

2.下载RPM包,并上传到服务器 (我这里是选择的下载rpm包,也有其他的方式,就是下载他的安装脚本或者镜像等方式,如果不想用rpm安装,可以自行搜索其它方式,官网也都有说明)

国内镜像下载地址: https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/ (Centos 6.8 64位)

打开后可以看到各个版本的rpm包,我是选择的 9.3.5版本,点击相应rpm包进行下载

复制下载地址链接 
[root@caosm03 ~]#wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-9.3.5-ce.0.el6.x86_64.rpm
[root@caosm03 ~]#rpm -ivh  gitlab-ce-9.3.5-ce.0.el6.x86_64.rpm
[root@caosm03 ~]#gitlab-ctl reconfigure

3.启动gitlab

[root@caosm03 ~]#gitlab-ctl reconfigure

4.使用浏览器访问GitLab (这里访问你的服务器IP地址:80端口)

首次访问GitLab,系统会让你重新设置管理员的密码,设置成功后会返回登录界面。

默认的管理员账号是root,如果你想更改默认管理员账号,请输入上面设置的新密码登录系统后修改帐号名。

.上面的步骤执行完后应该就是可以使用了,可是因为我的服务器只有1G内存,所以浏览器访问的时候,时不时的会报502错误,这里我们需要增加服务器虚拟内存可以解决。 (对于502错误,也有可能是服务器端口占用的原因,不过我的服务器没有安装其他东西,所以不会出现端口占用的情况)
502 
GitLab is not responding. 
Please contact your GitLab administrator if this problem persists.

5.增加服务器内存

我这里使用的事虚拟机 给虚拟机直接添加内存
另外一种方式增加swap分区
dd if=/dev/zero of=/var/swap bs=1024 count=2048000 #增加2G左右SWAP  
mkswap /var/swap #设置交换文件  
swapon /var/swap #激活启用交换分区 
echo "/var/swap swap swap defaults 0 0"  >> /etc/fstab

6.说明

缺点:这种方式虽然说简单方便,但是定制型很差,默认只能使用postgre和nginx
主配置文件:/etc/gitlab/gitlab.rb   //可以自定义一些邮件服务等
日志地址:/var/log/gitlab/    // 对应各服务
服务地址:/var/opt/gitlab/   // 对应各服务的主目录
仓库地址:/var/opt/gitlab/git-data //记录项目仓库等提交信息
重置配置:gitlab-ctl reconfigure    //不要乱用,会重置为最原始的配置的
重启服务:gitlab-ctl  stop/start/restart  //启动命令
默认安装:postgres、nginx、redis、unicorn ......

gitlab客户端配置及基本使用

1.客户端默认安装即可。

2.创建密钥

$ ssh-keygen  -t rsa -C caoshouming@kanfanews.com
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/PM/.ssh/id_rsa):
/c/Users/PM/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/PM/.ssh/id_rsa.
Your public key has been saved in /c/Users/PM/.ssh/id_rsa.pub.

3.拷贝密钥到gitlab 上面。

打开路径拷贝id_rsa.pub

[root@caosm03 ~]# cat  ~/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApA9i1/CL6qcN3T+9jRH5BTgss7nlv3f7hj7n57N8a5M6EngZ0tfyTlpmiQdA6ghWv4jLKTar64TiIf2+CenTSt0qNu485zQ5TpP4vUuuZ5hrD31V+DWg5+ls9v9SF0hABzQPVbCkxjV6kbCY7sCpw/pM85bemw5CvuCL9gdZIkkF7h08qPOWvIbljxxExgs5eS22Ys4ZxANlSYzsHstp6jxq296PSzoloLgW+x5OlR5rHvgowuRuv3sQn3sCaEEvt0EYVUdBwEbOivAJkZjFNORl2EX+u7uIjU4r9Sg5vqSEOM6GWVRDjFIzt4/46fGhJAzScKeuHkEobA/yrNVoNQ== caoshouming@kanfanews.com

4.配置服务端密钥

登陆自己的用户,设置ssh密钥。密钥里面复制,标题写好自己标识。增加密钥即可。

5.客户端进行下载测试

创建测试目录 在git 客户端里面切换到目录里面

$ cd e:
PM@kanfa-caosm MINGW64 /e
$cd www
$ git clone git@gitlab.kanfanews.com:php/doc.git
Cloning into 'doc'...
remote: Counting objects: 1535, done.
remote: Compressing objects: 100% (429/429), done.
remote: Total 1535 (delta 365), reused 728 (delta 326)
Receiving objects: 100% (1535/1535), 1.96 MiB | 3.94 MiB/s, done.
Resolving deltas: 100% (787/787), done.

**注意: git 下载的路径可以从web 上面进行查询 下载整个项目,自己的账户需要有管理员的权限才能下载,否则下载失败提示没有权限**

6.维护命令

查看状态
sudo gitlab-ctl status
/# 启动Gitlab所有组件
sudo gitlab-ctl start
/# 停止Gitlab所有组件
sudo gitlab-ctl stop
/# 重启Gitlab所有组件
sudo gitlab-ctl restart

7.gitlab 数据备份和恢复

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

[root@caosm03 init.d]# cd /etc/gitlab/
[root@localhost gitlab]# ls
gitlab.rb  gitlab-secrets.json  trusted-certs

备份data (以包安装的方式)

[root@localhost ~]# sudo gitlab-rake gitlab:backup:create
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ..
备份目录在:
[root@caosm03 backups]# pwd
/var/opt/gitlab/backups
[root@caosm03 backups]# ls
1512644923_2017_12_07_9.3.5_gitlab_backup.tar # 这个是备份出来的文件

恢复数据 (针对以包安装的方式)

[root@caosm03 ~]# sudo gitlab-ctl stop unicorn
[root@caosm03 ~]# sudo gitlab-ctl stop sidekiq
[root@caosm03 ~]# sudo gitlab-ctl status
[root@caosm03 ~]# sudo gitlab-rake gitlab:backup:restore 1512644923_2017_12_07
注意:这里的默认恢复指定的文件名称是1512644923_2017_12_07_9.3.5_gitlab_backup.tar
和默认格式不一致:这里需要对文件进行重命名不然恢复不成功!!!