CentOS7下搭建Gitlab

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lzxlfly/article/details/83351577

gitlab是一个基于git实现的在线代码仓库托管软件,一般用于在企业、学校等内部网络搭建专属git仓库,越来越多的企业在使用gitlab作为项目托管仓库。

一、安装配置依赖

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-ee.repo
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/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-ee.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-ee

看到如下表示安装成功

........
........
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
gitlab_rails['smtp_address'] = "mail.ultrapower.com.cn"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "[email protected]"
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'] = '[email protected]'
gitlab_rails['gitlab_email_reply_to'] = '[email protected]'

命令测试:gitlab-rails console,以下表示成功

Loading production environment (Rails 4.2.10)
irb(main):001:0> Notify.test_email('[email protected]', 'gitlab account alloc', 'Message body,password 123456').deliver_now

Notify#test_email: processed outbound mail in 640.2ms

Sent mail to [email protected] (130.9ms)
Date: Sat, 27 Oct 2018 21:59:52 +0800
From: GitLab <[email protected]>
Reply-To: GitLab <[email protected]>
To: [email protected]
Message-ID: <[email protected]>
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>Message body,password 123456</p></body></html>

=> #<Mail::Message:70157875272380, Multipart: false, Headers: <Date: Sat, 27 Oct 2018 21:59:52 +0800>, <From: GitLab <[email protected]>>, <Reply-To: GitLab <[email protected]>>, <To: [email protected]>, <Message-ID: <[email protected]>>, <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,选择适自己安装的版本


参考

https://about.gitlab.com/installation/#centos-7

https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

猜你喜欢

转载自blog.csdn.net/lzxlfly/article/details/83351577