资讯详情

GitLab 项目管理和代码托管平台

理论

关于Git这篇文章就够了 Gitlab作为一个开源项目,它开始帮助团队在团队建设和开发中合作,并为整个软件开发和操作生命周期提供了一个单独的应用平台,以行业领先的步伐交付新功能。Gitlab提供管理、计划、创建、验证、包装、发布、配置、监控和保护应用程序所需的一切。Gitlab是一个基于git实现的在线代码仓库托管软件一般用于企业、学校等内部网络建设git私服。Gitlab代码管理平台提供代码托管、提交审核和问题跟踪。Gitlab分社区版(CE)和企业版(EE) 代码托管平台: 1.SVN 2.github(全世界都在使用,人创造的,注册就可以使用,企业使用不安全) 3.gitlab (自己的公司可以自己使用,企业可以自己创建)

Git/Gitlab/Github的区别

git:是一命令的版本控制系统,全命令操作,无视觉界面 gitlab:是一个基于git提供在线代码仓库软件Web可视化管理界面通常用于企业集团内部合作开发 github:是一个基于git实现的在线代码托管仓库还提供可视化管理界面、免费账户和付费账户、开放和私人仓库。大多数开源项目选择github作为代码托管仓库(开源:开发源代码)

Gitlab服务组成部分(核心)

1.Nginx    静态web服务器(它作为GitLab的pros代理,处理我们的一切HTTPS静态访问请求) 2.gitlab-shell  用于处理Git命令和修改authorized keys列表(ruby) 3.gitlab-workhorse 轻量级反向代理服务器服务器(go)会处理一些大的HTTP请求,如文件下载、文件上传等,git push/pull和git包下载,其他请求将反向代理gitlab rails应用程序,即反向代理给后端unicorn 4.log rotate  日志文件管理工具(负责处理GitLab日志切割包装等操作) 5.postgresql  数据库(保存所有gitlab的数据信息) 6.redis    缓存数据库(前台访问速度加快缓存数据库信息,数据交互读写) 7.sidekiq   在后台执行队列任务(异步执行)(消息队列)(ruby) 8.unicorn   用ruby编写的一个HTTP服务器,gitlab rails应用是托管在这个服务器上 9.ruby    用ruby语言编写的 10.go    用go语言编写的 

这是一个简化的架构图,可以用来理解GitLab架构。 在这里插入图片描述

Gitlab的常用命令

gitlab 默认日志文件存储在/var/log/gitlab 目录下

gitlab-ctl start|stop|restart  开启  关闭  重启 gitlab-ctl start nginx        #启动nginx的服务 gitlab-ctl tail         #查看gitlab所有的日志 gitlab-ctl tail nginx         #查看nginx组件的日志 gitlab-ctl reconfigure       #重新编译(一般修改主配置文件)/etc/gitlab/gitlab.rb,需要执行此命令) gitlab-ctl console(produce)   #进入到gitlab的shell gitlab-ctl show-config    #验证配置文件 gitlab-ctl uninstall    #删除gitlab(保留数据) gitlab-ctl cleanse     #从新开始删除所有数据 gitlab-ctl stop unicorn gitlab-ctl stop sdekiq	#停止相关数据连接服务 

主配置文件:/etc/gitlab/gitlab.rb // 可以自定义一些邮件服务等
日志地址:/var/log/gitlab/    	   // 对应各服务
服务地址:/var/opt/gitlab/          // 对应各服务的主目录
仓库地址:/var/opt/gitlab/git-data  // 记录项目仓库等提交信息
默认安装:postgres、nginx、redis、unicorn ......

安装配置

gitlab安装 虚拟机需要调2G内存以上

极狐Gitlab官网安装

wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
yum -y install cronie openssh-clients openssh-server policycoreutils-python
yum -y localinstall gitlab-ce-12.3.0-ce.0.el7.x86_64.rpm	
# 以下内容忽略。上面这个是本地安装,下面的是官方文档:官方文档打不开Gitlab前端
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum -y install gitlab-ce-14.2.4-ce.0.el7.x86_64

[root@localhost ~]# vim /etc/gitlab/gitlab.rb 13 external_url ‘http://192.168.235.10’ [root@localhost ~]# gitlab-ctl reconfigure #重新编译完就会自动启动服务 gitlab Reconfigured! [root@localhost ~]# firefox 192.168.235.10 设置新密码–>root:新密码

gitlab日常维护操作

1、网易邮箱

gitlab的发送邮件 [root@localhost ~]# vim /etc/gitlab/gitlab.rb

53 gitlab_rails['gitlab_email_from'] = '***'  #指定发送邮件的邮箱地址
559 gitlab_rails['smtp_enable'] = true  			#开启邮件服务
560 gitlab_rails['smtp_address'] = "smtp.163.com"   #smtp的服务器
561 gitlab_rails['smtp_port'] = 25   				#端口
562 gitlab_rails['smtp_user_name'] = "haha"   		#用户
563 gitlab_rails['smtp_password'] = "***"   #开通smtp时返回的授权码
564 gitlab_rails['smtp_domain'] = "163.com"   			 #smtp的域名
565 gitlab_rails['smtp_authentication'] = "login"   	 #满足登录条件
566 gitlab_rails['smtp_enable_starttls_auto'] = false    #邮箱不加密
567 gitlab_rails['smtp_tls'] = false  #不开启tls

测试: [root@localhost ~]# gitlab-ctl reconfigure [root@localhost ~]# gitlab-rails console irb(main):001:0> Notify.test_email(‘15102600575@163.com’,‘qq’,‘qwerqwerqwer’).deliver_now

2、备份与恢复

备份

[root@localhost ~]# gitlab-rake gitlab:backup:create
Creating backup archive: 1632226105_2021_09_21_12.3.0_gitlab_backup.tar ... done 

默认备份文件会存在在/var/opt/gitlab/backups目录下,备份的文件是个tar包,包含了GitLab的所有数据(账户、仓库等)。 恢复

[root@localhost ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@localhost ~]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
[root@localhost ~]# gitlab-rake gitlab:backup:restore BACKUP=1625559345_2021_07_06_12.3.0
两次yes
[root@localhost ~]# gitlab-ctl start unicorn
ok: run: unicorn: (pid 48726) 0s
[root@localhost ~]# gitlab-ctl start sidekiq
ok: run: sidekiq: (pid 48757) 0s

3、root忘记密码

[root@localhost ~]# gitlab-rails console

irb(main):001:0> user = User.where(id:1).first		//通过条件查询用户==>user变量
=> #<User id:1 @root>
irb(main):002:0> user.password='12345.com'
=> "12345.com"
irb(main):003:0> user.save!

可以刷新页面 测试重新登录

修改默认端口

gitlab安装完成默认访问的是80端口,这个其实是gitlab自带nigix的端口 修改主要分为两部分,一部分是gitlab总的控制文件,一部分是子模块真实监听端口的修改。

  1. 编辑主配置文件:vim /etc/gitlab/gitlab.rb
 13 external_url 'http://192.168.235.10:800'
 1105 nginx['listen_port'] = 800         打开“nginx[‘listen_port’]”前面的注释,修改端口为800
  1. 编辑nginx配置文件:
# vim /var/opt/gitlab/nginx/conf/gitlab-http.conf 注:这里的nginx配置文件是指gitlab自带的默认配置文件哦!
listen *:800
  1. 最后
重载配置:     gitlab-ctl reconfigure  [注意:如果修改完gitlab-http.conf再运行gitlab-ctl reconfigure,就会被还原,修改并不会被覆盖]
重启:	      gitlab-ctl restart	  [直接重启就行,↑面这个我也没试过]
检查端口情况:	 netstat -antp
查看启动报错问题: gitlab-ctl tail

报错

1、* NoMethodError occurred in chef run: ruby_block[authorize Grafana with GitLab] (monitoring::grafana line 92) had an error: NoMethodError: undefined method `zero?’ for nil:NilClass

解决:删除/etc/gitlab/gitlab-secrets.json文件,再次运行gitlab-ctl reconfigure

Git+Gitlab

上传公钥

[root@localhost ~]# ssh-keygen -t rsa
[root@localhost ~]# cat /root/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4Y7czYlZCc/ypfd418XOjicHaVa5O9CP8XabhEPzN+xagnujm6TpytrqoRTSZHP+ZD6XYQiJYHxRCNLP67RPahJgbvZ38ZIhuMuXalrwMDhYED2xnnB4BM8xx+fFoB++TkvGnSCgbwoRCESnoD2oJbyQjbDBX4pnikldGjWa30kj26U9ML9KBDEknqPwLB70V82uogzDlmKpW9aGPuUPssaYvd5izQOaeVnaWRCm3PFQ9yZmXu+je+MC+5R8xYNU6c76kBrpUn/k9n0MEoG3GqcaP2MFoZNGavEfVAqNwm6xzBiPO+zLhicohEXk7GDLW4kN3quZfwDoFHlXnZH+h root@localhost.localdomain		      "将密钥放入到用户->Settings->SSH Keys里面"
git的本地仓库上的数据传到gitlab上
[root@localhost ~]# ssh -T git@192.168.235.10
Welcome to GitLab, @root!

测试

[root@localhost ~]# tar -zxf kgcweb.tar.gz 
[root@localhost ~]# cd kgcweb/
[root@localhost kgcweb]# git init
初始化空的 Git 版本库于 /root/kgcweb/.git/
[root@localhost kgcweb]# ls
pom.xml  src
[root@localhost kgcweb]# git config --global user.name "aa"
[root@localhost kgcweb]# git config --global user.email "aa@163.com"
[root@localhost kgcweb]# git add .
[root@localhost kgcweb]# git commit -m "first"
[master(根提交) 3967bdd] first
 3 files changed, 33 insertions(+)
 create mode 100644 pom.xml
 create mode 100644 src/main/webapp/WEB-INF/web.xml
 create mode 100644 src/main/webapp/index.jsp
[root@localhost kgcweb]# git remote add origin git@192.168.235.10:ab/kgcweb.git
[root@localhost kgcweb]# git push -u origin master
Counting objects: 9, done.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 979 bytes | 0 bytes/s, done.
Total 9 (delta 0), reused 0 (delta 0)
To git@192.168.235.10:ab/kgcweb.git
 * [new branch]      master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。

Life is difficult, but we never give up easily!

标签: 450v82uf电容蓄电

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台