开源仓库

Gitlab代码仓库搭建

Linux · 4月4日 · 2020年

一、GitLab简介

GitLab 是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的web服务。可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用。
常用的网站:
官网:https://about.gitlab.com/
国内镜像:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/
安装环境:
  • CentOS 6或者7
  • 2G内存(实验)生产(至少4G)
  • 安装包:gitlab-ce-10.0.6-ce
  • 禁用防火墙,关闭selinux

二、GitLab安

1、安装依赖

yum install curl policycoreutils openssh-server openssh-clients policycoreutils-python
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

 

2、获取rpm安装包

[root@node2 src]# cd /usr/local/src/
[root@node2 src]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.6-ce.0.el7.x86_64.rpm

 

3、安装

[root@node2 src]# rpm -ivh gitlab-ce-10.0.6-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-10.0.6-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-10.0.6-ce.0.el7        ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ \`/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

4、配

修改配置文件:/etc/gitlab/gitlab.rb
修改external_url 的地址为:http://192.168.56.12
修改完主配置文件后,使用gitlab-ctl reconfigure重新配置gitlab

5、启动

重新配置gitlba后,在浏览地址栏中输入http://192.168.56.12

配置root用户的密码,完成后进入系统:

至此我们的GitLab安装已经

三、Gitlab配置邮件通知,

1、编辑vim /etc/gitlab/gitlab.rb,590-611行添加以下内容:

gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = "zengfq_8008606262@163.com" 
gitlab_rails['gitlab_email_display_name'] = "Gitlab_欢迎加入微媒云播大家庭"
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "zengfq_8008606262@163.com"
gitlab_rails['smtp_password'] = "动态密码"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

说明:

gitlab_email_enabled 开启邮件服务

gitlab_email_from 发送邮

gitlab_email_display_name 邮件发送标题

smtp_enable 开启邮件

smtp_address 邮件服务商地址

smtp_port 邮件端口

smtp_user_name 发送邮件用户

smtp_password 动态密码

2、重新配置gitlab

gitlab-ctl reconfigure

3、测试方法-红色字体发送内容测试

--------------------------------------------------------------------------------
GitLab: 12.9.8 (34fb412ff1a) FOSS
GitLab Shell: 12.0.0
PostgreSQL: 10.12
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.2)
irb(main):001:0> Notify.test_email('3456358780@qq.com', '发送标题', '发送内容').deliver_now
Notify#test_email: processed outbound mail in 1.9ms
Delivered mail 5edef7b33c755_24623faa76fcf9a87628c@Gitlab-50.mail (1366.7ms)
Date: Tue, 09 Jun 2020 10:45:07 +0800
From: =?UTF-8?B?R2l0bGFiX+asoui/juWKoOWFpeW+ruWqkuS6keaSreWkp+WutuW6rQ==?= <rd@weimsx.com>
Reply-To: =?UTF-8?B?R2l0bGFiX+asoui/juWKoOWFpeW+ruWqkuS6keaSreWkp+WutuW6rQ==?= <noreply@192.168.30.50>
To: 3456358780@qq.com
Message-ID: <5edef7b33c755_24623faa76fcf9a87628c@Gitlab-50.mail>
Subject: Message Subject
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</p></body></html>

=> #<Mail::Message:70000900052840, Multipart: false, Headers: <Date: Tue, 09 Jun 2020 10:45:07 +0800>, <From: "Gitlab_欢迎加入大家庭" < 3456358780@qq.com>>, <Reply-To: "Gitlab_欢迎加入微媒云播大家庭" <noreply@192.168.30.50>>, <To: 3456358780@qq.com>, <Message-ID: <5edef7b33c755_24623faa76fcf9a87628c@Gitlab-50.mail>>, <Subject: Message Subject>, <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>

四、开启gitlab备份机制。

1、编辑vim /etc/gitlab/gitlab.rb

gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups"
gitlab_rails['backup_keep_time'] = 604800

manage_backup_path 开启gitlab当前备份路径

backup_path 设置gitlab备份路径

backup_keep_time 将其中backup_keep_time的配置取消注释,根据需要设置自动清理多少天前的备份这里是设置备份保留7天(7*3600*24=604800),保存

 ;

2、重新加载gitlab的配置文件。

gitlab-ctl reconfigure

3、编辑脚本设置定时crontab定时

  • 创建脚本存放路径

mkdir -p /service/scripts/
  • 编写脚本内容如下:

gitlab-rake gitlab:backup:create
  • 定时让我计划每周6晚上11点59准时全备份

#Gitlab backup week Six be completely ready
59 23 * * */6 /bin/sh /service/scripts/auto-backup.sh 2>&1

4、 gitlab恢复数据

[root@gitlab ~]# gitlab-ctl stop unicorn        #停止相关数据连接服务
[root@gitlab ~]# gitlab-ctl stop sidekiq
#修改权限,如果是从本服务器恢复可以不修改
[root@gitlab ~]# gitlab-rake gitlab:backup:restore BACKUP=1530156812_2018_06_28_10.8.4 
#从1530156812_2018_06_28_10.8.4编号备份中恢复
按照提示输入两次yes并回车
[root@gitlab ~]# gitlab-ctl start#启动gitlab

&nbsp;

五、git-gui安装

在我们的windows操作系统上安装windows版的git:

选择第二个选项,在windows命令行下使用git。

 

0 条回应