Gitlab安装部署与使用

发布于 2019-09-20  194 次阅读


Gitlab简介

GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
GitLab拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找

Gitlab部署

#环境准备
[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[[email protected] ~]# uname -r
3.10.0-123.el7.x86_64

#更换阿里yum源
[[email protected] ~]# wget http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[[email protected] ~]# yum update -y

#更换gitlabyum源为清华大学
[[email protected] ~]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
[[email protected] ~]# yum makecache
[[email protected] ~]#  yum install -y gitlab-ce

#安装gitlab-ce,下图所示就是安装成功的

#安装依赖
[[email protected] ~]# yum install curl policycoreutils openssh-server openssh-clients postfix -y

#启动postfix
[[email protected] ~]# systemctl start postfix

#安装gitlab-ce   

#配置并启动gitlab   比较久,需要耐心等待一下,在此之前需要保证80端口不被占用
[[email protected] ~]# gitlab-ctl reconfigure

#等待完成,看到如下结果,说明配置成功

#查看启动状态 全部为run说明正常启动
[[email protected] ~]# gitlab-ctl status
run: alertmanager: (pid 26793) 97s; run: log: (pid 26343) 267s
run: gitaly: (pid 26735) 102s; run: log: (pid 25644) 384s
run: gitlab-monitor: (pid 26744) 102s; run: log: (pid 26181) 285s
run: gitlab-workhorse: (pid 26720) 103s; run: log: (pid 26057) 308s
run: grafana: (pid 26810) 96s; run: log: (pid 26652) 132s
run: logrotate: (pid 26102) 298s; run: log: (pid 26112) 297s
run: nginx: (pid 26072) 305s; run: log: (pid 26085) 301s
run: node-exporter: (pid 26729) 103s; run: log: (pid 26158) 291s
run: postgres-exporter: (pid 26800) 97s; run: log: (pid 26394) 259s
run: postgresql: (pid 25764) 374s; run: log: (pid 25823) 371s
run: prometheus: (pid 26763) 101s; run: log: (pid 26301) 273s
run: redis: (pid 25570) 391s; run: log: (pid 25600) 390s
run: redis-exporter: (pid 26752) 102s; run: log: (pid 26251) 279s
run: sidekiq: (pid 25997) 317s; run: log: (pid 26009) 314s
run: unicorn: (pid 25956) 323s; run: log: (pid 25976) 319s

Gitlab使用

#关闭防火墙
[[email protected] bin]# getenforce
Enforcing
[[email protected] bin]# setenforce 0
[[email protected] bin]# vi /etc/selinux/config
SELINUX=disabled
[[email protected] bin]# firewall-cmd --state
running
[[email protected] bin]# systemctl stop firewalld.service
[[email protected] bin]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
在浏览器中访问http://服务器ip,Web页面提示需要设置一个密码(最少8位数)我这里设置密码为:12345678
登录系统,默认用户名为root,

英语不好,先改成中文吧

关闭自动注册 因为为内部使用不需要用户自己注册,由管理员分配用户即可

创建组,创建项目 分配权限这些就不说了

配置ssh免密

[[email protected] ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:
c2:65:9a:56:75:24:c7:4b:5f:f9:1c:fd:31:7c:e9:40 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|          oo=E. +|
|         . +o. B+|
|        +  . oooB|
|     . *    . ..+|
|      * S        |
|     . .         |
|                 |
|                 |
|                 |
+-----------------+

一路回车即可

[[email protected] ~]# cd /root/.ssh/
[[email protected] .ssh]# ll
总用量 8
-rw-------. 1 root root 1675 9月  20 14:40 id_rsa
-rw-r--r--. 1 root root  408 9月  20 14:40 id_rsa.pub
[[email protected] .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCgNBvJ1P6jnFDJTSeKVivm/IG9WennrYRJGhcHw7Xv6SpofmjlX06o7IyLWmtnFfKKTOcIIxvgItk0td+d7A1ikpn8sPicycFA7/6Y9ga5K+tRC2jHWbCyDcJ7hHuuY5hQwHvpqJd0gHClY/emlpAGccdnma/2RbGMKJScNM4zQ3IxkBY/jNAr7i9fSIN2kSCqdWxLcROHSP5Kr/XV6ljxIxFpgmw+yQotn/LxLQEWzXnluWo7hpIqdN36UIDadcz3wNBqgXeBHZ5iuCEz3/OpLtLGWEdOC7OO9rTHrukL87hxoLJyBIXmPs62pwo9cRKFKTV9rkdw26ufyWZNi8JB [email protected]

把公钥复制下来,添加到gitlab上

GitLab 项目创建后地址由Localhost改为实际IP的方法

vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
production: &base
  #
  # 1. GitLab app settings
  # ==========================

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 192.168.0.107 #这里改为主机的IP即可
    port: 80
    https: false

[[email protected] ~]# gitlab-ctl restart

开始测试

[[email protected] ~]# git config --global user.name "Administrator"
[[email protected] ~]# git config --global user.email "[email protected]"
[[email protected] ~]# git clone [email protected]:bison/test.git
正克隆到 'test'...
The authenticity of host '192.168.0.107 (192.168.0.107)' can't be established.
ECDSA key fingerprint is 57:c2:4f:3e:50:8c:7e:74:62:c7:13:e5:48:6d:7a:bb.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.107' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 27, done.
remote: Total 27 (delta 0), reused 0 (delta 0)
接收对象中: 100% (27/27), 47.28 KiB | 0 bytes/s, done.
[[email protected] ~]# ll
总用量 24
-rw-------. 1 root root   823 9月  19 19:01 anaconda-ks.cfg
-rw-r--r--. 1 root root 15080 10月  3 2017 epel-release-latest-7.noarch.rpm
drwxr-xr-x. 5 root root  4096 9月  20 15:02 test
[[email protected] ~]# cd test/
[[email protected] test]# ll
总用量 28
-rw-r--r--. 1 root root  177 9月  20 15:02 Dockerfile
-rw-r--r--. 1 root root 6468 9月  20 15:02 mvnw
-rw-r--r--. 1 root root 4994 9月  20 15:02 mvnw.cmd
-rw-r--r--. 1 root root 1414 9月  20 15:02 pom.xml
-rw-r--r--. 1 root root  557 9月  20 15:02 README.md
drwxr-xr-x. 4 root root   28 9月  20 15:02 src
[[email protected] test]# touch test1.txt && echo "this is test file" > test1.txt
[[email protected] test]# git add test1.txt 
[[email protected] test]# git commit -m "测试"
[master 9a84fa8] 测试
 1 file changed, 1 insertion(+)
 create mode 100644 test1.txt
[[email protected] test]# git push -u origin master
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To [email protected]:bison/test.git
   bcdfbfd..9a84fa8  master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。

可以看到成功推送到了仓库

下面是gitlab给的说明:

命令行指引

您还可以按照以下说明从计算机中上传现有文件。

Git 全局设置
git config --global user.name "Administrator"
git config --global user.email "[email protected]"
创建一个新仓库
git clone [email protected]:root/test.git
cd test
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
推送现有文件夹
cd existing_folder
git init
git remote add origin [email protected]:root/test.git
git add .
git commit -m "Initial commit"
git push -u origin master
推送现有的 Git 仓库
cd existing_repo
git remote rename origin old-origin
git remote add origin [email protected]:root/test.git
git push -u origin --all
git push -u origin --tags

windows上传推荐使用git

下载地址:https://dl.softmgr.qq.com/original/Development/Git-2.23.0-64-bit.exe


公交车司机终于在众人的指责中将座位让给了老太太