centos6.8安装 gitlab 9.3.5及使用php
环境准备:nginx
[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.安装配置依赖项git
[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端口web
[root@caosm03 ~]# iptables -Lredis
Chain INPUT (policy ACCEPT)json
target prot opt source destination centos
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 和默认格式不一致:这里须要对文件进行重命名否则恢复不成功!!!