操作系统:CentOS7(Linux)
一、搭建Git服务器:
1.安装依赖软件(期间询问时输入y,回车):
[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-develzlib-devel perl-devel gcc-c++
2.安装git:
[root@localhost ~]# yum install -y git
3.、创建git用户:
(1)添加用户yyh:
[root@localhost ~]# useradd yyh
(2)设置用户yyh的密码(会提示输入2次密码):
[root@localhost ~]# passwd yyh
4.创建仓库:
(1)切换到用户yyh:
[root@localhost ~]# su - yyh
(2)创建yyh.git仓库:
[yyh@localhost ~]$ git init --bare yyh.git
二、搭建GitLab服务器:
1.安装/配置ssh(默认已安装):
(1)安装ssh+python:
[root@localhost ~]# yum install -y curl policycoreutils-python openssh-server
(2)ssh服务设为开机启动:
[root@localhost ~]# sudo systemctl enable sshd
(3)启动ssh服务:
[root@localhost ~]# sudo systemctl start sshd
2.安装/配置Postfix(发邮件,默认已安装):
(1)安装Postfix:
[root@localhost ~]# yum install postfix
(2)Postfix设为开机启动:
[root@localhost ~]# sudo systemctl enable postfix
(3)启动Postfix:
[root@localhost ~]# systemctl start postfix
3.安装wget(下载工具):
[root@localhost ~]# yum -y install wget
4.安装/配置GitLab:
(1)下载GitLab镜像:
镜像列表:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.6.0-ce.0.el7.x86_64.rpm
(2)安装GitLab镜像(出现*组成的图案表示成功):
[root@localhost ~]# rpm -i gitlab-ce-12.6.0-ce.0.el7.x86_64.rpm
(3)增加本机域名与IP映射关系:
[root@localhost ~]# vi /etc/hosts
增加如下内容:
127.0.0.1 www.yyh_gitlab.com
执行命令:
[root@localhost ~]# hostnamectl set-hostname www.yyh_gitlab.com
(4)修改IP和端口:
[root@localhost ~]# vi /var/opt/gitlab/gitlab-rails/etc/gitlab.yml
修改文件内容如下:
gitlab:
host: www.yyh_gitlab.com
port: 80
https: false
[root@localhost ~]# vi /etc/gitlab/gitlab.rb
修改文件内容如下:
gitlab
external_url 'http://www.yyh_gitlab.com'
(5)配置GitLab的环境:
[root@localhost ~]# gitlab-ctl reconfigure
(6)启动GitLab:
[root@localhost ~]# gitlab-ctl restart
5.通过浏览器访问GitLab的Web页面:
(1)访问真实环境的GitLab,可以用域名:
http://www.yyh_gitlab.com
(2)访问虚拟机内的GitLab,则用虚拟机IP地址:
http://192.168.233.129
(3)首次访问,会跳到设置登录密码页,输入2次密码,如图所示:
(4)打开登录地址,登录gitlab:
http://192.168.233.129/users/sign_in
如图所示:
(5)登录后,可以创建组、工程等,如图所示: