设为首页 收藏本站
查看: 1026|回复: 0

[经验分享] Gitlab 10.5版本的部署使用及汉化

[复制链接]

尚未签到

发表于 2018-9-19 08:30:59 | 显示全部楼层 |阅读模式
概述讲义:
  GitLab是一个开源版本管理系统,是集代码托管,测试,部署于一体的开源git仓库管理软件,可通过web界面来进行访问公开的或私人项目。与Github类似,GitLab能够浏览代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本,并提供一个文件历史库。是目前非常流行好用的研发版本控制系统。
  Git有三个类分别为:
  Git:      是本地版本控制系统工具。
  Github:是官方在线代码托管仓库,可自行注册使用,https://github.com。
  GitLab:是自建的一个非官方的自有版本仓库。通俗一点就是公司内部的。
  这里要给大家分享的是搭建一个属于自己的Git仓库,也就是Gitlab。
  GitLab对硬件还是有一定要求的,因Gitlab有多个job任务及进程,对内存是有要求的,建议1cpu以上,2G内存以上。
  搭建前准备工作:这里是用Centos 7版本的系统
  1、关闭防火墙
  2、关闭SELinux
  3、关闭NetworkManager
  

[root@gitlab ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config  
[root@gitlab ~]#
  
[root@gitlab ~]# setenforce 0
  
[root@gitlab ~]#
  
[root@gitlab ~]# systemctl stop NetworkManager
  
[root@gitlab ~]# systemctl disable NetworkManager
  
[root@gitlab ~]# systemctl disable iptables
  
[root@gitlab ~]# systemctl stop iptables
  

安装Gitlab
  使用在线yum安装Gitlab 和git工具集
  

[root@gitlab ~]# yum install -y curl policycoreutils openssh-server openssh-clients postfix  
[root@gitlab ~]# systemctl restart postfix
  
[root@gitlab ~]# systemctl enable postfix
  
[root@gitlab ~]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
  
[root@gitlab ~]# yum install -y  gitlab-ce  git      --开始安装Gitlab 大约270M,耐心等待下就好了。
  

Gitlab 的常用命令
  Gitlab命令分为两部分:通用命令 和服务管理命令
  通用命令:
  语法:gitlab-ctl  命令参数
  命令参数如下:
  

help                  帮助  

  
reconfigure       修改配置文件之后,需要重新加载下
  

  
show-config      查看所有服务配置文件信息
  

  
uninstall            卸载这个软件
  

  
cleanse            删除gitlab数据,重新白手起家
  

  服务管理命令:
  

start               启动所有服务  

  
stop               关闭所有服务
  

  
restart            重启所有服务
  

  
status            查看所有服务状态
  

  
tail                 查看日志信息
  

  
service-list     列举所有启动服务
  

  
graceful-kill    平稳停止一个服务
  

  

配置GitLab
  安装完成后接下就是配置
  

[root@gitlab ~]# gitlab-ctl reconfigure      --第一次加载配置的时候会很慢,耐心等待就好,直到加载完成。  
...
  
... ...
  
... ... ...
  
... ... ... ...
  
...
  
Running handlers:
  
Running handlers complete
  
Chef Client finished, 2/516 resources updated in 09 seconds
  
gitlab Reconfigured!
  

  

  加载完成后,开始启动Gitlab,GitLab默认会占用80、8080和9090端口
  

[root@gitlab ~]# gitlab-ctl restart  
ok: run: gitaly: (pid 42828) 0s
  
ok: run: gitlab-monitor: (pid 42852) 0s
  
ok: run: gitlab-workhorse: (pid 42858) 0s
  
ok: run: logrotate: (pid 42867) 0s
  
ok: run: nginx: (pid 42874) 0s
  
ok: run: node-exporter: (pid 42879) 0s
  
ok: run: postgres-exporter: (pid 42884) 1s
  
ok: run: postgresql: (pid 42894) 0s
  
ok: run: prometheus: (pid 42897) 0s
  
ok: run: redis: (pid 42907) 0s
  
ok: run: redis-exporter: (pid 42912) 1s
  
ok: run: sidekiq: (pid 42997) 0s
  
ok: run: unicorn: (pid 43007) 0s
  

  
[root@gitlab ~]# lsof -i:80

  
COMMAND   PID       USER   FD   TYPE DEVICE>  
nginx   42874       root    7u  IPv4 125185      0t0  TCP *:http (LISTEN)
  
nginx   42875 gitlab-www    7u  IPv4 125185      0t0  TCP *:http (LISTEN)
  

  
[root@gitlab web-demo]# lsof -i:8080

  
COMMAND   PID USER   FD   TYPE DEVICE>  
bundle  40358  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  
bundle  40650  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  
bundle  40652  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  

  开户访问web界面
  第一次访问,系统会要求重置新密码,管理员的用户名为root
DSC0000.jpg


汉化Gitlab
  Gitlab默认语言是英文,对于想加强英文的同学,建议继续使用英文,但要求使用中文,这里需要下载一个汉化包
  下载最新的汉化包:
  

[root@gitlab ~]# git clone https://gitlab.com/xhang/gitlab.git  

  如果要下载指定版本的汉化包,需要加上版本号。
  例:下载10.5.1,命令如下:
  

[root@gitlab ~]# git clone https://gitlab.com/xhang/gitlab.git  -b  v10.5.1-zh  

  下载完成后,将下载的文件夹内容复制到gitlab目录下
  复制前先停止Gitlab
  

[root@gitlab ~]# gitlab-ctl stop  
ok: down: gitaly: 0s, normally up
  
ok: down: gitlab-monitor: 0s, normally up
  
ok: down: gitlab-workhorse: 1s, normally up
  
ok: down: logrotate: 0s, normally up
  
ok: down: nginx: 1s, normally up
  
ok: down: node-exporter: 0s, normally up
  
ok: down: postgres-exporter: 1s, normally up
  
ok: down: postgresql: 0s, normally up
  
ok: down: prometheus: 0s, normally up
  
ok: down: redis: 0s, normally up
  
ok: down: redis-exporter: 1s, normally up
  
ok: down: sidekiq: 0s, normally up
  
ok: down: unicorn: 1s, normally up
  

  
[root@gitlab ~]# cp -r -f  ./gitlab/*  /opt/gitlab/embedded/service/gitlab-rails/
  

  复制时可能不断提示是否要覆盖,这时可能是系统每次执行cp命令时,其实是执行了cp -i命令的别名。出现这种情况可以修改~/.bashrc,在“alias cp=’cp -i’”前加#注释,再刷新文件 source ~/.bashrc
  在复制过程中提示,以下信息是正常的
DSC0001.jpg

  复制完成后,需要重新加载配置,并启动Gitlab
  

[root@gitlab ~]# gitlab-ctl reconfigure  
...
  
... ...
  
... ... ...
  
... ... ... ...
  
...
  
Running handlers:
  
Running handlers complete
  
Chef Client finished, 2/516 resources updated in 09 seconds
  
gitlab Reconfigured!
  

  
[root@gitlab ~]# gitlab-ctl restart
  
ok: run: gitaly: (pid 42828) 0s
  
ok: run: gitlab-monitor: (pid 42852) 0s
  
ok: run: gitlab-workhorse: (pid 42858) 0s
  
ok: run: logrotate: (pid 42867) 0s
  
ok: run: nginx: (pid 42874) 0s
  
ok: run: node-exporter: (pid 42879) 0s
  
ok: run: postgres-exporter: (pid 42884) 1s
  
ok: run: postgresql: (pid 42894) 0s
  
ok: run: prometheus: (pid 42897) 0s
  
ok: run: redis: (pid 42907) 0s
  
ok: run: redis-exporter: (pid 42912) 1s
  
ok: run: sidekiq: (pid 42997) 0s
  
ok: run: unicorn: (pid 43007) 0s
  

  
[root@gitlab ~]# lsof -i:80

  
COMMAND   PID       USER   FD   TYPE DEVICE>  
nginx   42874       root    7u  IPv4 125185      0t0  TCP *:http (LISTEN)
  
nginx   42875 gitlab-www    7u  IPv4 125185      0t0  TCP *:http (LISTEN)
  

  
[root@gitlab web-demo]# lsof -i:8080

  
COMMAND   PID USER   FD   TYPE DEVICE>  
bundle  40358  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  
bundle  40650  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  
bundle  40652  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  

  再次访问web界面,显示的已经为汉化熟悉的中文
DSC0002.jpg


Gitlab私有仓库的使用
  登陆进来Gitlab,创建一个项目,但创建项目前我们先创建一个组,让项目归属一个组里
DSC0003.jpg

  新建一个组
DSC0004.jpg

  在新建的dev-demo组里,创建一个项目
DSC0005.jpg

  创建一个项目
DSC0006.jpg

  在项目里创建一个README文件,一会用于测试用
  在项目创建成功后,界面有提示要建ssh-key,这里先建自述文件,后面再来建ssh-key
DSC0007.jpg

  给README文件添加点内容
DSC0008.jpg

DSC0009.jpg

  在工作区的Git服务器上创建key,再添加至Gitlab
  在Git工作区机器上创建ssh-key,我这里用的是192.1.1.52机器来创建ssh-key,Gitlab是在192.1.1.10机器。
  

[root@agent02 ~]# ssh-keygen -t rsa -b 4096  
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>  
Your public key has been saved in /root/.ssh/id_rsa.pub.
  
The key fingerprint is:
  
SHA256:/fqioPb2oKlcjiF8U+Pjw3FSNXcowo2y4qtT/TjV2TA root@agent02
  
The keys randomart image is:
  
+---[RSA 4096]----+
  
|      . o   .    |
  
|     . + = o .   |
  
|      o o + .    |
  
|   . . . E       |
  
|  . oo. S *      |
  
|.  oo+.o o o     |
  
|..oo+oX     .    |
  
| +.*+Oo+  ..     |
  
| .*o=++.o..o.    |
  
+----[SHA256]-----+
  

  
[root@agent02 ~]# cat .ssh/id_rsa.pub
  
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCkgVRWoKTblJlloKNo8+YcBM3B8AA0X5QoyQGtjoNwz6L1iO2WEhVUqGqVK/ujG+i/NaOCkrVXlowc0a53mB3Wk1Bk+6INxtXmtPDqmSVHamCtuq86XGSIoGbE5j9cYaWasWs0kEx60BO5+/jqz9LWGeFJehDHQd0K32eHQpn836XCIhyXN7mWJ7XmUwYfyf6B9PjO0z/4hsM21qXuE3giQDrGDHCjqkWNoK7hwNwfQGaIo+kClgvgquq6I0d9XWb30C7/Xr+ZuXROHHSncteCJU8Chqk7uiOyUHcgMMrF5AhfEG8wyDQKOPDW3nPin3YvzSZg0jgIn3X9e1dIl4OZoyCIj1OW1gx/JZ0P9xBhjFCcWFjXSVqX34S05F7CiHdW/MIJgJBWc5qFjSTsaIVEUhwc3DzHhPcW1ZEbskqc6kBZyB5Ei3ZIvITPpa9tUV3BHPVFKPio6Leow5Vi0ne+b1Khm3KCKatGdkqRjbyZ6Me1J7+KQnAmT9FmCNo3V8IFs4PpFljDCNBxm93lbaiqAcFeAEhcm1M20BiGGmTJnVMrGGRlXcutnj9G5s0C4oOVL8ujFIS4wwcp6XWWNzkqOw1GiJp9GhFO1fXyg/vdiS+mgeMXjZNsKl4BAPZ+GYbiDOMSGdjXKVch5dmXfwDetbTl4+T/6COX5L0G6ijlVw== root@agent02
  

  

  上面key已经创建好了,复制上面打印出来的密钥,放到Gitlab里面来
DSC00010.jpg

DSC00011.jpg

  接着再回到刚才test项目里面,查看详情,这里有显示该项目的git链接地址
DSC00012.jpg

  接下来,在192.1.1.52机器上,把Gitlab里面test项目克隆到本地来
  

[root@agent02 ]#  echo "192.1.1.10    gitlab.example.com" >> /etc/hosts         --注意一定要把Gitlab机器名和IP地址写进hosts记录里  

  
[root@agent02 ]# mkdir /dev-demo
  
[root@agent02 ]# cd /dev-demo
  

  
[root@agent02 dev-demo]# git init
  
Reinitialized existing Git repository in /dev-demo/.git/
  

  
[root@agent02 dev-demo]# git clone git@gitlab.example.com:dev-demo/test.git
  
Cloning into 'test'...
  
The authenticity of host 'gitlab.example.com (192.1.1.10)' can't be established.
  
ECDSA key fingerprint is SHA256:885XnAhlZsdYbCLIzq1qh7cCt+yF9i/AtusSI7QmPcE.
  
ECDSA key fingerprint is MD5:e9:95:51:51:e4:ce:b9:5c:b1:d7:ce:2a:d8:7d:fe:ee.
  
Are you sure you want to continue connecting (yes/no)? yes
  
Warning: Permanently added 'gitlab.example.com,192.1.1.10' (ECDSA) to the list of known hosts.
  
remote: Counting objects: 3, done.
  
remote: Total 3 (delta 0), reused 0 (delta 0)
  
Receiving objects: 100% (3/3), done.
  

  
[root@agent02 dev-demo]# ls
  
test
  

  
[root@agent02 dev-demo]# cat test/README.md
  
******** GitLab *******
  
这是一个测试项目
  

  

  在本地模拟开发过程,再和Gitlab同步
  

[root@agent02 dev-demo]# vi test/index.html  
我是GitLab私有服务器
  

  
[root@agent02 dev-demo]# git config --global user.email "409216159@qq.com"
  
[root@agent02 dev-demo]# git config --global user.name "LX"
  
[root@agent02 dev-demo]#
  
[root@agent02 dev-demo]# git add ./*
  
[root@agent02 dev-demo]# git commit -m "代码提交index.html"
  
[master (root-commit) b348c78] 代码提交index.html
  1 file changed, 1 insertion(+)
  create mode 160000 test
  

  代码提交完成后,我们再来到Gitlab里查看项目test里是否有刚提交的index.html文件和内容
  

[root@agent02 test]# vi aa.html  
测试代码
  

  
[root@agent02 test]# git add ./*
  
[root@agent02 test]# git commit -m "提交代码"
  
[master be2c1f8] 提交代码
  2 files changed, 3 insertions(+)
  create mode 100644 index.html
  

  
[root@agent02 test]#
  
[root@agent02 test]# git push
  
warning: push.default is unset; its implicit value is changing in
  
Git 2.0 from 'matching' to 'simple'. To squelch this message
  
and maintain the current behavior after the default changes, use:
  

  git config --global push.default matching
  

  
To squelch this message and adopt the new behavior now, use:
  

  git config --global push.default simple
  

  
See 'git help config' and search for 'push.default' for further information.
  
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
  
'current' instead of 'simple' if you sometimes use older versions of Git)
  

  
Counting objects: 5, done.
  
Compressing objects: 100% (2/2), done.
  
Writing objects: 100% (4/4), 389 bytes | 0 bytes/s, done.
  
Total 4 (delta 0), reused 0 (delta 0)
  
To git@gitlab.example.com:dev-demo/test.git
  d5ef909..be2c1f8  master -> master
  

DSC00013.jpg


配置注册Gitlab时发邮件确认
  配置在Gitlab注册用户时的邮件发送确认动作
  

[root@gitlab ~]# vi /etc/gitlab/gitlab.rb  429  gitlab_rails['smtp_enable'] = true
  430  gitlab_rails['smtp_address'] = "smtp.qq.com"
  431  gitlab_rails['smtp_port'] = 465
  432  gitlab_rails['smtp_user_name'] = "409216159@qq.com"
  433  gitlab_rails['smtp_password'] = "QQ password"
  434  gitlab_rails['smtp_domain'] = "qq.com"
  435  gitlab_rails['smtp_authentication'] = "login"
  436  gitlab_rails['smtp_enable_starttls_auto'] = true
  437  gitlab_rails['smtp_tls'] = true
  438  gitlab_rails['gitlab_email_from'] = '409216159@qq.com'
  

  配置完成后,需要重新生成gitlab参数
  

[root@gitlab ~]# gitlab-ctl reconfigure  

  
[root@gitlab ~]# gitlab-ctl restart
  

  
[root@gitlab ~]# lsof -i:80

  
COMMAND   PID       USER   FD   TYPE DEVICE>  
nginx   40422       root    7u  IPv4 117999      0t0  TCP *:http (LISTEN)
  
nginx   40423 gitlab-www    7u  IPv4 117999      0t0  TCP *:http (LISTEN)
  

  
[root@gitlab ~]# lsof -i:8080

  
COMMAND   PID USER   FD   TYPE DEVICE>  
bundle  40358  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  
bundle  40650  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  
bundle  40652  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
  

  设置注册Gitlab用户时发送邮件确认
DSC00014.jpg

  拉到最下面,点保存,再退出来,在登陆界面,注册一个新的帐号,会向你的注册时的邮箱发送一封确认的邮件
DSC00015.jpg

  至此,GitLab私有服务器搭建完成。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-594027-1-1.html 上篇帖子: gitlab服务器安装及汉化配置 下篇帖子: docker搭建gitlab
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表