gitlab部署及配置

GitLab

GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。

它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

与GitHub的主要区别是:GitHub提供公共仓库和私有仓库,但如果需要使用私有仓库,是需要收费的。而Gitlab可以免费让用户设置仓库的权限,从而可以让指定的人看到指定的内容,保证了仓库的私有性。

Gitlab安装

官网安装地址:https://about.gitlab.com/install
各个系统的安装方法在官网上都有详细的介绍,如果需要其他系统的安装方法,可以进入官网查看,以下是CenOS7的安装实例

gitlab有两个版本:gitlab-ce和gitlab-ee,分别是社区版和企业版,企业版是收费的,社区版是开源的,通常我们安装社区版就可以了
注意:官网上的示例是企业版(gitlab-ee)的,我们需要安装社区版,只需要把示例中的gitlab-ee改成gitlab-ce即可

gitlab部署

关闭防火墙和selinux

[root@localhost src]# systemctl stop  firewalld.service
[root@localhost src]# setenforce 0

下载软件包、安装

//先要下载一个eple-release源
[root@localhost ~]# yum -y install epel-release

//然后安装所需的依赖包
[root@localhost ]# yum -y install git curl openssh-server openssh-clients postfix cronie policycoreutils-python-utils

//去清华大学的源站中下载gitlab软件包到本地的/usr/src中,然后安装
[root@localhost src]# rpm -ivh gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm 
[root@localhost src]# rpm -ivh gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm 
警告:gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID f27eab47: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:gitlab-ce-14.3.2-ce.0.el8        ################################# [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

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=14-3


//修改配置文件 /etc/gitlab/gitlab.rb 把域名改成本机的IP地址即可
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.164.133'

//开启邮箱服务
[root@localhost ~]# systemctl enable --now postfix.service 
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@localhost ~]# ss -antl
State   Recv-Q  Send-Q     Local Address:Port     Peer Address:Port  
LISTEN  0       128              0.0.0.0:22            0.0.0.0:*     
LISTEN  0       100            127.0.0.1:25            0.0.0.0:*     
LISTEN  0       128                 [::]:22               [::]:*     
LISTEN  0       100                [::1]:25               [::]:*   

//重新加载配置文件并重启服务,这一步需要点时间,需要耐心等待一会。
[root@localhost src]# gitlab-ctl reconfigure
[root@localhost src]# gitlab-ctl restart
ok: run: alertmanager: (pid 176006) 1s
ok: run: gitaly: (pid 176037) 0s
ok: run: gitlab-exporter: (pid 176161) 0s
ok: run: gitlab-workhorse: (pid 176177) 0s
ok: run: grafana: (pid 176212) 0s
ok: run: logrotate: (pid 176223) 0s
ok: run: nginx: (pid 176254) 1s
ok: run: node-exporter: (pid 176271) 0s
ok: run: postgres-exporter: (pid 176325) 1s
ok: run: postgresql: (pid 176353) 0s
ok: run: prometheus: (pid 176411) 0s
ok: run: puma: (pid 176898) 0s
ok: run: redis: (pid 176903) 0s
ok: run: redis-exporter: (pid 176909) 1s
ok: run: sidekiq: (pid 177268) 0s

破解管理员的密码

[root@localhost ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]
 GitLab:       14.3.2 (92acfb1b8a9) FOSS
 GitLab Shell: 13.21.1
 PostgreSQL:   12.7
--------------------------------------------------------------------------------
Loading production environment (Rails 6.1.3.2)
irb(main):001:0> user = User.where(id: 1).first   //查找UID是1的管理员账户
=> #<User id:1 @root>   
irb(main):002:0> user.password = 'wjmwjm123'  //设置啊管理员的密码
=> "wjmwjm123"
irb(main):003:0> user.password_confirmation = 'wjmwjm123'    //设置啊管理员的密码
=> "wjmwjm123"
irb(main):004:0> user.save!     //保存用户修改信息
Enqueued ActionMailer::MailDeliveryJob (Job ID: e643fa7a-ff6b-4ab9-b3c5-bd2fc607e78a) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007f0a6e3d97d8 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true
irb(main):006:0> exit
[root@localhost ~]# 

web界面登陆

在这里插入图片描述
在这里插入图片描述

gitlab界面配置

所有的配置都是在admin界面中进行配置
在这里插入图片描述

用户

创建账户
可以直接点击new user,如果已经创建过用户这里没有这个按钮,可以到左边的导航栏中点击users进行创建或其他的操作
在这里插入图片描述
设置名称和邮箱、还有访问权限等。这里的密码等创建完成用户后再进行设置在这里插入图片描述点击编辑进行设置密码
在这里插入图片描述password=wjmwjm123
在这里插入图片描述
测试,用更改创建好的这个用户登陆gitlab

在这里插入图片描述
为了账户的安全,新创建的用户在第一次登陆的时候是需要跟改密码的,这里改成wjmwjm111
在这里插入图片描述
更改密码后是要重新登陆一次的
在这里插入图片描述
在这里插入图片描述
禁用用户
禁用用户后该用户则无法登陆gitlab。同时这里还可以删除用户或者删除用户的同时一并删除这个用户所贡献的内容。
在这里插入图片描述
解除禁用的账户
如果这个账户要给新的人使用只需要改一下名称然后把密码设置成初始的密码wjmwjm123即可。当新人第一次登陆的时候同意也是需要重新设置秘密的
在这里插入图片描述

组和权限

创建组
在这里插入图片描述组的权限
如果一用户添加到这个组里面后,则组有什么权限 用户就有什么权限
在这里插入图片描述
创建完成后可以添加用户到这个组里面
在这里插入图片描述
此时这个runtime组里面就有wjm用户了
在这里插入图片描述
点击Manage access可以跟改组员的角色,或删除用户等。
组的权限是创建组的时候选择的角色
在这里插入图片描述

项目

创建项目
在这里插入图片描述
一般情况下我们都是选择创建项目
在这里插入图片描述
这里先不勾选最后一个选项
在这里插入图片描述
在这里插入图片描述
克隆项目到linux服务器中
复制这个地址然后到服务器中执行
在这里插入图片描述

[root@localhost ~]# git clone http://192.168.164.133/root/app.git
正克隆到 'app'...
Username for 'http://192.168.164.133': root
Password for 'http://root@192.168.164.133': 
warning: 您似乎克隆了一个空仓库。
[root@localhost ~]# ll
总用量 4
-rw-------. 1 root root 1198 81 14:09 anaconda-ks.cfg
drwxr-xr-x. 3 root root   18 1012 20:26 app
[root@localhost ~]# cd app/
[root@localhost app]# ls -a
.  ..  .git
//这个目录中有一个叫.git的文件,说明这是一个仓库

上传文件到仓库中

//全局设置
[root@localhost app]# git config --global user.name "Administrator"
[root@localhost app]# git config --global user.email "admin@example.com"

//切换到一个分支
[root@localhost app]# git switch -c master
切换到一个新分支 'master'

//创建文件,并把这个添加到仓库中去
[root@localhost app]# touch README.md
[root@localhost app]# git add README.md

//提交
[root@localhost app]# git commit -m "add README"
[master(根提交) 176d06d] add README
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md
 # -m 描述,做了哪些改动
 
//把代码推送到master中
[root@localhost app]# git push -u origin master 
Username for 'http://192.168.164.133': root
Password for 'http://root@192.168.164.133': 
枚举对象: 3, 完成.
对象计数中: 100% (3/3), 完成.
写入对象中: 100% (3/3), 216 字节 | 216.00 KiB/s, 完成.
总共 3(差异 0),复用 0(差异 0),包复用 0
To http://192.168.164.133/root/app.git
 * [new branch]      master -> master
分支 'master' 设置为跟踪来自 'origin' 的远程分支 'master'[root@localhost app]# 

刷新网站就可以看见刚刚推送的文件
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值