Gitlab安装使用

Gitlab安装使用

1. 为什么要使用gitlab

Git的优点多多这里就不详细介绍了;

Git是版本控制系统,Github是在线的基于Git的代码托管服务;

Github有个小缺陷 (也不能算是缺陷吧), 就是你的repo(repository的缩写,表示“仓库”)都需要public(公开), 如果你想要创建private(私人)的repo, 那得付钱。

Gitlab正好解决这个缺陷,它可以部署到自己的服务器上,在上面创建免费的私人repo。

2. gitlab构成

  • Nginx:静态web服务器。
  • gitlab-shell:用于处理Git命令和修改authorized keys列表。(Ruby)
  • gitlab-workhorse: 轻量级的反向代理服务器。(go)
  • logrotate:日志文件管理工具。
  • postgresql:数据库。
  • redis:缓存数据库。
  • sidekiq:用于在后台执行队列任务(异步执行)。(Ruby)
  • unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。(Ruby Web Server,主要使用Ruby编写)

3.安装

3.1 安装环境说明:

CentOS Linux release 7.6.1810 (Core) 

IP:192.168.137.121

关闭selinux、firewalld

gitlab-ce-12.1.4

rpm包:下载地址

3.2 源码安装

3.2 rpm安装

下载&安装  

# wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.1.4-ce.0.el7.x86_64.rpm/download.rpm

# rpm -ivh gitlab-ce-12.1.4-ce.0.el7.x86_64.rpm

#直接安装就好了,rpm包里会包含有gitlab所有依赖的服务
#安装完成后会有gitlab的logo显示

 安装完成,如下所示:

rpm -ivh gitlab-ce-12.1.4-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-12.1.4-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-12.1.4-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

 修改gitlab的url并执行reconfigure

#将url地址通过sed替换为本地ip
# egrep '^(external_url).*' /etc/gitlab/gitlab.rb         # 查看配置
external_url 'http://gitlab.example.com'

# sed -ri 's#^(external_url).*#\1 "http://192.168.137.121"#'  /etc/gitlab/gitlab.rb        # sed命令修改

# egrep '^(external_url).*' /etc/gitlab/gitlab.rb        # 查看已经修改
external_url "http://192.168.137.121"

修改了gitlab.rb配置文件之后一定要执行reconfigure

gitlab-ctl reconfigure

执行reconfigure会经历一段漫长的等待,执行完成如下图:

4. gitlab-web配置

4.1 访问页面开始配置

http://192.168.137.111(默认端口为80)

使用谷歌自带的翻译显示中文

4.2 创建仓库

点击上图的“创建一个项目”

点击创建后将会提示你添加ssh公钥

# 先生成公钥
# ssh-keygen -t rsa 一路回车即可

#cat .ssh/id_rsa.pub,将公钥内容按下图添加

 点击添加文件,文件名“README”, 内容:#test-jenkins

 

4.3 测试

项目地址获取

 

主机端操作:

[root@master git]# git clone git@192.168.137.121:root/test.git
Cloning into 'test'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@master git]# ll total
0 drwxr-xr-x 3 root root 30 Aug 7 22:19 test [root@master git]# ll test/ total 4 -rw-r--r-- 1 root root 13 Aug 7 22:19 README [root@master git]# echo 1111 > test/1.txt [root@master git]# git add test/1.txt [root@master git]# git commit -m "and 1.txt" [root@master test]# git push Counting objects: 4, done. Delta compression using up to 2 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 268 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168.137.121:root/test.git 3b2a082..ca9283d master -> master

 完成

5. 错误解决

  • 访问web页面时出现502错误
gitlab-ctl start 
gitlab-ctl reconfigure

在启动gitlab的时候执行reconfigure之后就可以了。

参考文献

https://www.jianshu.com/p/b04356e014fa

猜你喜欢

转载自www.cnblogs.com/-abm/p/11318104.html