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会经历一段漫长的等待,执行完成如下图:

3.4 docker方式安装

官方文档:https://docs.gitlab.com/omnibus/docker/#install-gitlab-using-docker-compose

说明:

  • 使用汉化版镜像, 如果不适应可以换成官方原版镜像 gitlab/gitlab-ce:11.0.2-ce.0
  • 项目初始配置+启动很慢, 需要一段时间, 日志中出现 Reconfigured 表示启动成功
  • 192.168.xxx.xxx 替换为宿主机的IP地址
  • 初始管理员帐号密码: root / lb80h&85
  • 该配置为乞丐版, 内存占用2G+ ( worker_processes 越多内存占用越大, 默认为 8G )
  • postgresql 为容器中内置的数据库 ( 帐号: gitlab / gitlab ), 如果没必要就不用暴露端口了
  • 邮箱填写用于发送找回密码和通知的发件人帐号 ( 收不到邮件? ), 不想配置就删掉相关配置好了, 不影响正常使用

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

https://www.jianshu.com/p/7e8037c63d63

 

转载于:https://www.cnblogs.com/-abm/p/11318104.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值