Gitlab的安装

Gitlab的服务构成:

Nginx:静态web服务器。
gitlab-shell:用于处理Git命令和修改authorized keys列表。(Ruby)
gitlab-workhorse: 轻量级的反向代理服务器。(go)
GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pull和Git包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn。
logrotate:日志文件管理工具。
postgresql:数据库。
redis:缓存数据库。
sidekiq:用于在后台执行队列任务(异步执行)。(Ruby)
unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。(Ruby Web Server,主要使用Ruby编写)
 
安装:
可以源码编译,但这里就用yum安装了:
创建repo文件:
[root@VM-75-64 conf]# cat /etc/yum.repos.d/gitlab-ce.rep
[gitlab_gitlab-ce]
name=gitlab_gitlab-ce
repo_gpgcheck=1
gpgcheck=0
enabled=1
 
[gitlab_gitlab-ce-source]
name=gitlab_gitlab-ce-source
repo_gpgcheck=1
gpgcheck=0
enabled=1
 
yum makecache                         #这里他会提示你导入某种秘钥,提示你输入y/n,这里输入y;
yum install gitlab-ce                  #自动安装最新版本
yum install gitlab-ce-x.x.x          #安装指定版本
 
rpm安装:
yum install -y policycoreutils-python
[root@VM-75-68 ~]# rpm -ivh gitlab-ce-11.1.4-ce.0.el6.x86_64.rpm
warning: gitlab-ce-11.1.4-ce.0.el6.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                ########################################### [100%]
   1:gitlab-ce              ########################################### [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
 
ok,rpm安装完成!
安装完成后,启动的指令为: gitlab-ctl reconfigure
不是  gitlab-ctl start,能不能长点心?!
你以为你很会????你很牛逼????
 
 
gitlab常用命令:
sudo gitlab-ctl start              # 启动所有 gitlab 组件;
sudo gitlab-ctl stop              # 停止所有 gitlab 组件;
sudo gitlab-ctl restart              # 重启所有 gitlab 组件;
sudo gitlab-ctl status              # 查看服务状态;
sudo gitlab-ctl reconfigure         # 启动服务,重新加载配置!
sudo vim /etc/gitlab/gitlab.rb          # 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace              # 检查gitlab;
sudo gitlab-ctl tail                          # 查看日志;
 
这里第一次在启动的时候,由于本地之前部署过nginx,所以80端口被占用,日志展示的很清楚......
关闭本地nginx服务
重启!
ok,都起来了,那么我们访问本地IP:
 
 
这个502错误,查了一下,有很多种可能导致的,机器内存不够,进程没有启动完全,端口被占用,最终我们找到解决办法是:
修改gitlab的配置文件:
/etc/gitlab/gitlab.rb
这里原来的端口是8080,但在本地有sdo的进程,占用了该端口,导致502报错!
在修改了端口之后,重启服务......
 
 
你看!是不是好了!这里需要登录,我尝试了几个方法,登录不进去,想想也咩有看到关于初始用户和密码的配置,查了之后发现需要手动配置:
 
配置过程为:
1:切换目录:cd /opt/gitlab/bin
2:  执行 :sudo gitlab-rails console production 命令 开始初始化密码(这要等待一会,不知道为什么,是不是内存不够了!)
3: 在irb(main):001:0> 后面通过 u=User.where(id:1).first 来查找与切换账号(User.all 可以查看所有用户)
4: 通过u.password='12345678'设置密码为12345678(这里的密码看自己喜欢):
5: 通过u.password_confirmation='12345678' 再次确认密码
6: 通过 u.save!进行保存(切记切记 后面的 !)
7: 如果看到上面截图中的true ,恭喜你已经成功了,执行 exit 退出当前设置流程即可。
这里退出之后,就能通过界面用root/12345678登陆了!
 

 
登录上以后,我们就能使用gitlab下面的一些功能了!主要还是创建项目,用gitlab作为项目的版本库,跟svn一样,做版控的,那我们看看怎么使用gitlab做版控!
 
创建项目:
 
 
我这里已经创建了两个了!可以在右边的按钮创建新的项目!
 
 
项目名称
项目URL(这里的URL原来不是这样的,是默认的gitlab@example.com,待会说从哪里修改!)
项目描述
private(私有项目)
添加README文件
创建!
这就是创建完之后的项目细节了!右上角是客户端clone的地址!
这里一个空的项目就创建好了,下面看如何从客户端clone下这些空项目并加以开发上传提交!
 
这里你会发现,默认的项目clone地址是gitlab.example.com的什么鬼,这里最好要改一下,修改的文件为:
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
如图!修改完后,重启gitlab
gitlab-ctl restart
 
如果是修改访问地址的话,改为域名登录,修改的文件为:
 
 
 

 
在创建第一个项目的时候,他会提示你添加ssh-key,这个key就是作用于SSH clone的时候做免密认证的!这里我们看下,因为我们ssh clone的地址为: git@192.168.75.64:root/test-2.git
这里是git@,所以要为git用户创建一套秘钥!操作的指令为:
[root@VM-75-64 .ssh]# ssh-keygen -t rsa -C 'git@192.168.75.64'
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
29:a3:2c:7e:33:f4:9b:37:01:21:d0:d4:d6:5c:2e:b1 git@192.168.75.64
The key's randomart image is:
+--[ RSA 2048]----+
|  .+.. o...      |
|    o + o+       |
|     o .E .      |
|      .  o       |
|      o.S        |
|   ... o.        |
|  ..o.   .       |
| . .+ ..o        |
|  .. ooo .       |
+-----------------+
[root@VM-75-64 .ssh]#
[root@VM-75-64 .ssh]# ll
total 12
-rw-r--r-- 1 root root  395 Apr 10 17:11 authorized_keys
-rw------- 1 root root 1671 Apr 10 17:20 id_rsa
-rw-r--r-- 1 root root  399 Apr 10 17:20 id_rsa.pub
[root@VM-75-64 .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAv2TQLumoqosr940gCwIGHCVFywAwEHMDihXrhLNr+TeqLmd97XUvKzLuX1cL249a9QeRpu97HVDtWmMiEU6SOUQpfmA3ha+OiryqtiAxGxY0fD3VeSPkhOWS3oJL9JPyf5QtgtMfhLYHwJZRDFu3KSqZz6YXW41khTYSSjCnqvAO6A9j2qMDXar1etWcNe+qBF9IPhGDVDdjNIVBg1ig3ulY+gv0LrlgBJscEg6KvJSJBTGOrLG1JJ8cKbgPswJrjtPmK6sToOT6Bx8cAebIzR7XbVnWCKJpux3JX7YYfZmQgrJ2wAdiEnHlsciwdg7intMN/K5m+hxBcylLBggB/w== git@192.168.75.64
 
注意上面结尾不是root了,是git!
这里的id_rsa.pub就是git用户的公钥了!
重要概念:如果你需要在A机器去无秘钥clone代码,那么就要在A机器上去执行上面创建git用户秘钥的操作!并且把git用户的公钥,复制到项目中去:
 
 
这里就是添加sshkey的地方,也可以remove换成其他的!并且可以支持多个key同时存在!
在这里添加了key之后,我们就能通过SSH的方式无秘钥clone了!
[root@VM-75-64 ~]# git clone git@192.168.75.64:root/test-2.git
Initialized empty Git repository in /root/test-2/.git/
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.
 
 
可以看到版本库已经被拉下来了!
这里都是之前创建项目的时候配置的信息!
 
好,clone操作这里完成了!提交操作我们再看一下:
创建文件:
[root@VM-75-64 test-2]# echo 'lalalallaalalal' > la.txt
[root@VM-75-64 test-2]# ll
total 8
-rw-r--r-- 1 root root 16 Apr 10 18:31 la.txt
-rw-r--r-- 1 root root 16 Apr 10 18:25 README.md
[root@VM-75-64 test-2]#
[root@VM-75-64 test-2]# git add la.txt        #添加到版本库
[root@VM-75-64 test-2]# git commit -m 'add la.txt'    #提交到版本库
[master 4ed192e] add la.txt
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 la.txt
[root@VM-75-64 test-2]# git push -u origin master    #推送到远程gitlab服务器,第一次操作加上参数 -u,表示关联本地与远程
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 277 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.75.64:root/test-2.git
   01e4b26..4ed192e  master -> master
Branch master set up to track remote branch master from origin.
 
去web刷新界面:
 
可以看到已经提交上来了!
还可以哦!
 
这里要注意,如果是多人员联合开发的情况下,在gitlab里为用户创建了账号以后,要给他们http的clone地址,并且,用他们的用户名以及密码登录!不要用git用户的了!
git用户用在linux服务器里做无密码clone的情景!
 

那么后面开发人员就能在本地开发,并上传到gitlab版本库了!而且这里的项目管理更加明朗,比svn更直观,好处多多!
不过下面就是客户端能不能在windows里clone代码的问题了!不然只能在linux里还是有局限性的!

 
在gitlab-ctl reconfigure的时候,会出现:
 * link[/opt/gitlab/init/redis] action create (up to date) 
 * file[/opt/gitlab/sv/redis/down] action delete (up to date) 
 * directory[/opt/gitlab/service] action create (up to date) 
 * link[/opt/gitlab/service/redis] action create (up to date) 
 * ruby_block[wait for redis service socket] action run
的情况,此时,需要你在另外一个终端中运行指令:
[root@VM-75-65 service]# /opt/gitlab/embedded/bin/runsvdir-start &
[1] 12353
此时自检就能继续下去了!
不知道原理,但是确实能解决问题!
 

1.修改gitlab的默认监听地址:
修改 /etc/gitlab/gitlab.rb
nginx['listen_port'] = 82 #默认值即80端口 nginx['listen_port'] = nil
unicorn['port'] = 9091#原值unicorn['port'] = 8080
 
2:修改http克隆时候的连接地址
[root@VM-75-65 data]# vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.
 
production: &base
  #
  # 1. GitLab app settings
  # ==========================
 
  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.example.com
    port: 80
    https: false
3:修改gitlab管理界面的访问地址
vim /etc/gitlab/gitlab.rb
external_url 'GENERATED_EXTERNAL_URL'
引号里的可以是IP+端口也可以是自定义域名!
以上,共勉!
 
posted @ 2020-07-31 11:24  一个运维  阅读(784)  评论(0编辑  收藏  举报