gitlab是一个基于git实现的在线代码仓库托管软件,一般用于在企业、学校等内部网络搭建专属git仓库,越来越多的企业在使用gitlab作为项目托管仓库,社区版(ce)免费,大部分公司一般够用,企业版(ee)收费,功能更强大。
一、安装配置依赖
1、安装启动ssh服务
sudo yum install -y curl policycoreutils-python openssh-server #安装ssh
sudo systemctl enable sshd #开机自启
sudo systemctl start sshd #启动ssh
2、配置防火墙
sudo firewall-cmd --state #查看防火墙状态
sudo systemctl start firewalld #没有启动,可以启动防火墙
sudo firewall-cmd --permanent --add-service=http #添加防火墙支持http永久访问
sudo systemctl reload firewalld #重新加载防火漆配置
3、安装邮件服务
sudo yum install postfix -y #安装postfix
sudo systemctl enable postfix #开机自启
sudo systemctl start postfix #启动postfix
二、安装配置gitlib
1. 配置yum源
#下载此脚本并运行,会自动下载当前系统的yum源,/etc/yum.repos.d/gitlab_gitlab-ce.repo
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
可以看到已经下载了yum源:gitlab_gitlab-ee.repo
[root@localhost software]# ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo gitlab_gitlab-ee.repo
国外镜像安装时十分慢,可以把刚下载的gitlab_gitlab-ce.repo删除掉
再把yum换成清华的镜像https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/
新建源:vim /etc/yum.repos.d/gitlab-ce.repo,内容如下
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
2、yum开始安装
#刷新yum缓存
sudo yum makecache
#安装
sudo yum install -y gitlab-ce
看到如下表示安装成功
........
........
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
Verifying : gitlab-ce-11.4.0-ce.0.el7.x86_64 1/1
Installed:
gitlab-ce.x86_64 0:11.4.0-ce.0.el7
Complete!
3、配置访问地址
vim /etc/gitlab/gitlab.rb,修改external_url,邮件配置参考https://docs.gitlab.com/omnibus/settings/smtp.html
#其他默认不变,如果需要用到的功能可以参考资料配置
external_url 'http://192.168.172.74:8081'
发送邮件配置
gitlab_rails['smtp_enable'] = true #启用smtp服务
gitlab_rails['smtp_address'] = "mail.ultrapower.com.cn" #smtp发送服务器
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "xueming@ultrapower.com.cn"
gitlab_rails['smtp_password'] = "12333lzxcl"
gitlab_rails['smtp_domain'] = "ultrapower.com.cn"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['gitlab_email_from'] = 'xueming@ultrapower.com.cn'#与smtp_user_name一定要一样
gitlab_rails['gitlab_email_reply_to'] = 'xueming@ultrapower.com.cn'
命令测试:gitlab-rails console,以下表示成功
-------------------------------------------------------------------------------------
GitLab: 11.4.0 (6ebbd70)
GitLab Shell: 8.3.3
postgresql: 9.6.8
-------------------------------------------------------------------------------------
Loading production environment (Rails 4.2.10)
# Notify.test_email为测试语句
irb(main):001:0> Notify.test_email('lizhiqi@ulrapower.com.cn', 'gitlab account alloc', 'this is Message body').deliver_now
Notify#test_email: processed outbound mail in 509.7ms
Sent mail to lizhiqi@ulrapower.com.cn (30658.7ms)
Date: Fri, 16 Nov 2018 22:53:20 +0800
From: GitLab <xueming@ultrapower.com.cn>
Reply-To: GitLab <xueming@ultrapower.com.cn>
To: lizhiqi@ulrapower.com.cn
Message-ID: <5beed9e011b5e_18fd3fd7354daf8455792@localhost.localdomain.mail>
Subject: gitlab account alloc
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>this is Message body</p></body></html>
=> #<Mail::Message:70193188814920, Multipart: false, Headers: <Date: Fri, 16 Nov 2018 22:53:20 +0800>, <From: GitLab <xueming@ultrapower.com.cn>>, <Reply-To: GitLab <xueming@ultrapower.com.cn>>, <To: lizhinqi@ulrapower.com.cn>, <Message-ID: <5beed9e011b5e_18fd3fd7354daf8455792@localhost.localdomain.mail>>, <Subject: gitlab account alloc>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):002:0>
4、重新配置应用
gitlab-ctl reconfigure #执行此命令重新加载配置且同时启动gitlab所有服务
5、启动gitlab
gitlab-ctl status #查看是否启动
gitlab-ctl start #没有启动可以启动
gitlab-ctl restart #重新启动下
gitlab-ctl stop #停止
gitlab-ctl --help #查看更多命令
6、防火墙开放端口
firewall-cmd --zone=public --list-ports #查看开放端口
firewall-cmd --zone=public --add-port=8081/tcp --permanent #开放8081端口
firewall-cmd --reload #重新加载配置
#如果不需要,也可以直接关闭防火墙
systemctl stop firewalld.service
三、登录gitlab
1、输入http://192.168.172.74:8081,被重定向到密码修改界面,修改密码为root的管理员账户
2、修改密码后自动跳转到登录页面,用root和修改后密码登录就可以
3、登录成功如下,就可以开始自己的操作了
四、汉化gitlab
干IT的一般都是英文,这里我就不汉化了,将就着看了
汉化gitlab可去这里https://gitlab.com/xhang/gitlab,选择适自己安装的版本
参考