第06章CentOS7中Gitlab的安装与配置

背景

由于公司业务,需要上Git版本控制。

  • 目前市面上比较有名的Git服务提供商,国外有GitHub、BitBucket、GitLab,国内有Coding。
  • 现有的服务商,对于免费的套餐都有一定的限制。比如:GitHub只允许建立免费的开源repository,建立私有的仓库需要收费。BitBucket允许建立无限制的私有项目,不过对于项目中参与的开发人员是有人数限制的,当团队中开发者规模达到一定数量后,需要付费购买相应的套餐。

GitLab社区版是免费的,不但能建立免费的私有仓库而且没有数量上限,参与人员也没有数量限制,还能设置成员的权限,甚至细致到具体某条分支的权限,以及强大的工作流等等。

GitLab很适合中小型非开源项目公司。

6.1 gitlab 介绍

用于代码协作的开源软件

细粒度访问控制管理 git 仓库以保证代码安全。 使用合并请求进行代码审查并加强团体合作。 每个项目均有自己的问题跟踪和维基页面。

现在一般可用,Auto DevOps是一个功能齐全的CI / CD管道,可自动完成交付过程。只需提交您的代码,Auto DevOps完成剩下的工作。 有了GitLab,你可以 :

无论您使用瀑布式,敏捷还是对话式开发,GitLab都可以简化您的协作工作流程。使用GitLab灵活的项目管理工具,以您的方式可视化,确定优先级,协调和跟踪您的进度。 Learn More →

将源代码整合到一个易于管理和控制的DVCS中,而不会中断您的工作流程。 GitLab的git存储库配备了分支工具和访问控制,为项目和代码的协作提供了可扩展的单一事实来源。 Learn More →

GitLab帮助团队从单个分布式版本控制系统设计,开发和安全地管理代码和项目数据,以实现快速迭代和业务价值交付。 GitLab存储库为项目和代码的协作提供了可扩展的单一事实来源,使团队能够在不中断其工作流的情况下提高工作效率。

通过内置静态代码分析,代码测试,代码质量,依赖性检查和审核应用程序,更快地发现错误,提高安全性并缩短反馈周期。自定义批准工作流程控件,自动测试代码质量,并为每个代码更改启动临时环境。 GitLab持续集成是最受欢迎的下一代测试系统,可以扩展以更快地运行测试。 Learn More →

GitLab容器注册表为您提供增强的自定义Docker镜像的安全性和访问控制,无需第三方附加组件。通过完整的Git存储库管理集成轻松上传和下载GitLab CI中的镜像。 Learn More →

花费更少的时间配置您的工具,并花更多的时间创建。无论您是部署到一台服务器还是数千台,都可以使用GitLab内置的持续交付和部署,自信安全地构建,测试和发布您的代码。 Learn More →

使用GitLab Auto Devops自动完成从构建到部署和监控的整个工作流程。最佳实践模板可让您从最小到零的配置开始。然后自定义从buildpacks到CI / CD的所有内容。 Learn More →

确保您的应用程序始终响应并可用。 GitLab使用Prometheus收集并显示已部署应用程序的性能指标,以便您可以立即了解代码更改如何影响您的生产环境。 Learn More →

GitLab是第一个针对产品,开发,QA,安全和运营团队的DevOps生命周期的所有阶段构建的单一应用程序,可以在同一个项目上同时工作。 GitLab使团队能够通过单个对话进行协作和工作,而不是跨不同的工具管理多个线程。 GitLab在DevOps生命周期内为团队提供单一数据存储,一个用户界面和一个权限模型,允许团队进行协作,显着缩短周期时间,并专注于快速构建优秀软件。

GitLab + Google Cloud Platform =简化的可扩展部署

GitLab的原生Google Kubernetes Engine集成提高了开发人员的工作效率。借助Auto DevOps,GitLab可自动配置CI / CD管道,以构建,测试,验证和部署应用程序到Google Cloud Platform。

开发,质量保证,安全和操作是整个生命周期中单个对话的一部分。通过“将它们向左移动”并在没有延迟的情况下解决它们来更早地检测问题。

团队同时工作,而不是等待安全,QA和操作切换,因为团队积压。

在本月发布的GitLab 11.0中,我们已经使Auto DevOps普遍可用,添加了许可证管理,SAML SSO for Groups,开源Squash和Merge等等!

免费试用GitLab Ultimate 30天。

评估自我托管的GitLab 30天,并免费获得我们的顶级订阅计划Ultimate的所有功能。无需信用卡。

“我们决定使用基于开源的平台,以便我们可以参与开发并为我们需要的功能和概念做出贡献,例如文件大小统计,OpenID Connect,GPG和Docker Registry。 GitLab内置的持续集成和独立的CI Runner使我们的开发人员能够集成非常特定的环境,提高生产力并提高开发人员的满意度。“

由于GitLab社区的1900多名贡献成员的合作,GitLab每月22日都会发布主要产品,因此可以实现高速创新,提供为当今现代软件开发人员打造的领先的现代软件开发产品。

“GitLab支持开发团队,其中包含详细记录的安装和配置流程,易于使用的UI以及支持自助服务的灵活的每个席位定价模型。 GitLab的愿景是为企业规模的集成软件开发团队提供服务,这些团队希望花更多的时间编写代码,节省维护工具链的时间。“

可见 (Visible)

整个生命周期的实时视图

  • 看看重要的一切
  • 保持流畅
  • 不要等待同步
  • 管理项目,而不是工具 缩短周期时间。

高效 (Efficient)

无需等待即可协作

  • 立即开始
  • 同时工作
  • 没有更多的交接

治理(Governed)

充满信心地开发和运营

  • 安全性和合规性已经内置
  • 简化用户管理
  • 加快审计
  • 确定无误

6.2 gitlab 安装

On CentOS 7 (and RedHat/Oracle/Scientific Linux 7), the commands below will also open HTTP and SSH access in the system firewall.

在 CentOS 7 (and RedHat/Oracle/Scientific Linux 7)上,以下命令还将在系统防火墙中打开HTTP和SSH访问。

sudo yum install -y curl policycoreutils-python openssh-server sudo systemctl enable sshd sudo systemctl start sshd sudo firewall-cmd --permanent --add-service=http sudo systemctl reload firewalld 

Next, install Postfix to send notification emails. If you want to use another solution to send emails please skip this step and configure an external SMTP server after GitLab has been installed.

接下来,安装Postfix以发送通知电子邮件。如果要使用其他解决方案发送电子邮件,请跳过此步骤并在安装GitLab后配置外部SMTP服务器。

sudo yum install postfix sudo systemctl enable postfix sudo systemctl start postfix 

During Postfix installation a configuration screen may appear. Select ‘Internet Site’ and press enter. Use your server’s external DNS for ‘mail name’ and press enter. If additional screens appear, continue to press enter to accept the defaults.

在Postfix安装期间,可能会出现配置屏幕。 选择“Internet Site”并按Enter键。使用服务器的外部DNS作为“邮件名称”,然后按Enter键。 如果出现其他屏幕,接受默认值请继续按Enter键。

Add the GitLab package repository.

添加GitLab仓库包

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash 

Next, install the GitLab package. Change http://gitlab.example.com to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL. HTTPS requires additional configuration after installation.

接下来,安装GitLab包。将“http://gitlab.example”修改为您自己要访问 GitLab 实例的URL(具体可根据你自己的域名或者 hostname 来修改) 。 安装将自动配置并启动该URL的GitLab。 HTTPS在安装后需要其他配置。

sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ee 

安装完成:

Running handlers:
Running handlers complete
Chef Client finished, 424/635 resources updated in 11 minutes 05 seconds
gitlab Reconfigured!

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6Tr1gZh2-1599485585091)(assets/1531452562357.png)]

Thank you for installing GitLab!
GitLab should be available at http://node1.ringyin.com

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Verifying : gitlab-ee-11.1.1-ee.0.el7.x86_64

Installed:
gitlab-ee.x86_64 0:11.0.3-ee.0.el7

Complete!

On your first visit, you’ll be redirected to a password reset screen. Provide the password for the initial administrator account and you will be redirected back to the login screen. Use the default account’s username root to login.

首次访问时,您将被重定向到密码重置屏幕。 提供初始管理员帐户的密码,您将被重定向回登录屏幕。 使用默认帐户的用户名root登录。

***有关安装和配置的详细说明,请参阅我们的文档。***

在浏览器中输入安装时提供的 URL,首次进入页面:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fr01CRBL-1599485585096)(assets/1531397301959.png)]

Visit our email subscription preference center to let us know when to communicate with you. We have an explicit email opt-in policy so you have complete control over what and how often we send you emails.

Twice a month, we send out the GitLab news you need to know, including new features, integrations, docs, and behind the scenes stories from our dev teams. For critical security updates related to bugs and system performance, sign up for our dedicated security newsletter.

IMPORTANT NOTE: If you do not opt-in to the security newsletter, you will not receive security alerts.

访问我们的电子邮件订阅首选项中心,告知我们何时与您沟通。 我们有明确的电子邮件选择加入政策,因此您可以完全控制我们向您发送电子邮件的频率。

我们每月发送两次您需要了解的GitLab新闻,包括我们的开发团队的新功能,集成,文档和幕后故事。 有关错误和系统性能的重要安全更新,请注册我们的专用安全通讯。

重要说明:如果您不选择加入安全通讯,则不会收到安全警报。

1、gitlab-workhorse这个“工作马”

就是gitlab-Git-http-server(GitlabV8.0出现,V8.2名称变更为Gitlab-workhorse)

轻量级的反向代理服务器

2、sidekiq多线程启动

用于在后台执行队列任务(异步执行)

3、unicorn是ruby的http server

可以通过http://localhost:8080端口访问, 默认端口是8080。

An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。

4、nginx作为反向代理

静态web服务器,代理到unicorn,nginx默认端口是80

5、postgresql

作为数据库,默认端口是5432

6、redis作为一个队列(NoSql)

缓存数据库,用于存储用户session和任务,任务包括新建仓库、发送邮件等等,默认端口是6379

7、logrotate切割日志

日志文件管理工具

8、prometheus监控

默认端口9090

9、gitlab-monitor

默认端口9168

10、gitlab-shell

用于处理Git命令和修改authorized keys列表,默认端口22

注意:

(可选)如果系统资源不足,可以通过以下命令关闭Sidekiq来释放一部分内存

[root@localhost ~]# gitlab-ctl stop sidekiq

ok: down: sidekiq: 0s, normally up

#初次配置服务 [root@node1 ~]$ sudo gitlab-ctlreconfigure#启动服务 [root@node1 ~]$ sudo gitlab-ctl start#停止服务 [root@node1 ~]$ sudo gitlab-ctl stop#重启服务 [root@node1 ~]$ sudo gitlab-ctl restart#状态 [root@node1 ~]$ sudo gitlab-ctl status#监控unicorn日志 [root@node1 ~]$ sudo gitlab-ctl tailunicorn #监控日志 [root@node1 ~]$ sudo gitlab-ctl tail#配置生效命令 [root@node1 ~]$ sudo gitlab-ctl reconfigure#关闭服务命令 [root@node1 ~]$ sudo gitlab-ctl stop 

重新安装清理

## 卸载 [root@node1 ~]$ sudo rpm -e gitlab-ee 

查看gitlab进程

[root@node1 ~]$ sudo ps aux | grep gitlab 

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qTpqsHnF-1599485585100)(assets/1532598602540.png)]

杀掉第一个进程(就是带有好多…的进程)

[root@node1 ~]$ sudo kill -9 654 

杀掉后,在ps aux | grep gitlab确认一遍,还有没有gitlab的进程

删除所有包含gitlab文件

[root@node1 ~]$ sudo find / -name gitlab | xargs rm -rf 

删除文件

[root@node1 ~]$ sudo rm -rf /etc/gitlab/* /var/log/gitlab/ /var/opt/gitlab/ /opt/gitlab/ 

语法: gitlab-ctl command (subcommand)

例子:

#启动所有服务 [root@node1 ~]$ sudo gitlab-ctl start#启动单独一个服务 [root@node1 ~]$ sudo gitlab-ctl start nginx#查看日志,查看所有日志 [root@node1 ~]$ sudo gitlab-ctl tail#查看具体一个日志,类似tail -f [root@node1 ~]$ sudo gitlab-ctl tail nginx 

例子:

#显示所有服务配置文件 [root@node1 ~]$ sudo gitlab-ctl show-config#卸载gitlab [root@node1 ~]$ sudo gitlab-ctl uninstall 

DatabaseCommands**(慎重使用)**

例子:

#升级数据库 [root@node1 ~]$ sudo gitlab-ctl pg-upgrade Checking for an omnibus managed postgresql: OK Checking if we already upgraded: OK The latest version 9.6.1 is already running,nothing to do#降级数据库版本 [root@node1 ~]$ sudo gitlab-ctl revert-pg-upgrade Toggling deploy page:cp/opt/gitlab/embedded/service/gitlab-rails/public/deploy.html/opt/gitlab/embedded/service/gitlab-rails/public/index.html Toggling deploy page: OK Toggling services🆗 down: gitaly: 129s,normally up ok: down: gitlab-monitor: 128s, normally up ok: down: logrotate: 127s, normally up ok: down: node-exporter: 127s, normally up ok: down: postgres-exporter: 126s, normally up ok: down: prometheus: 125s, normally up ok: down: redis-exporter: 125s, normally up ok: down: sidekiq: 123s, normally up Toggling services: OK Checking if we need to downgrade: NOT OK/var/opt/gitlab/postgresql/data.9.2.18 does notexist, cannot revert data Will proceed with reverting the running programversion only, unless you interrupt Reverting database to 9.2.18 in 5 seconds= WARNING = This will revert the database to what it wasbefore you upgraded, including the data. Please hit Ctrl-C now if this isn't what youwere looking for= WARNING === Reverting ==ok: down: postgresql: 131s, normally up ok: run: postgresql: (pid 12102) 0s== Reverted ==Toggling deploy page:rm -f/opt/gitlab/embedded/service/gitlab-rails/public/index.html Toggling deploy page: OK Toggling services🆗 run: gitaly: (pid 12107)1s ok: run: gitlab-monitor: (pid 12111) 0s ok: run: logrotate: (pid 12115) 1s ok: run: node-exporter: (pid 12121) 0s ok: run: postgres-exporter: (pid 12125) 0s ok: run: prometheus: (pid 12130) 1s ok: run: redis-exporter: (pid 12139) 0s ok: run: sidekiq: (pid 12144) 1s Toggling services: OK 
# 实时查看所有日志 [root@node1 ~]$ sudo gitlab-ctl tail# 实时检查redis的日志 [root@node1 ~]$ sudo gitlab-ctl tail redis# 实时检查postgresql的日志 [root@node1 ~]$ sudo gitlab-ctl tail postgresql# 检查gitlab-workhorse的日志 [root@node1 ~]$ sudo gitlab-ctl tail gitlab-workhorse# 检查logrotate的日志 [root@node1 ~]$ sudo gitlab-ctl tail logrotate# 检查nginx的日志 [root@node1 ~]$ sudo gitlab-ctl tail nginx# 检查sidekiq的日志 [root@node1 ~]$ sudo gitlab-ctl tail sidekiq# 检查unicorn的日志 [root@node1 ~]$ sudo gitlab-ctl tail unicorn 

6.3 gitlab 配置

gitlab配置详解

#如果80和8080端口被占用可以修改 [root@node1 ~]$ sudo vi /var/opt/gitlab/gitlab-rails/etc/unicorn.rb listen"127.0.0.1:8080", :tcp_nopush => true #这一行端口修改为你要端口#修改nginx端口 [root@node1 ~]$ sudo vi /var/opt/gitlab/nginx/conf/gitlab-http.conf server{ #这里的80端口修改为你所需要的端口listen *:80;#修改Prometheus端口,默认端口是9090 [root@node1 ~]$ sudo vi /etc/gitlab/gitlab.rb 

注意:

根据自己情况自行修改成自己需要的port。

只要修改了配置文件一定要重新加载配置文件。

默认安装好,你能创建的项目,只能创建100000个。

[root@node1 ~]$ sudo vi /opt/gitlab/embedded/service/gitlab-rails/config/initializers/1_settings.rb ## Settings.gitlab['default_projects_limit'] ||=100000 #修改成你自己所需要的参数,保存 Settings.gitlab['default_projects_limit'] ||=10000#重新初始化 [root@node1 ~]$ sudo gitlab-ctl reconfigure#查看修改之后项目数量 

注意:

这个是在安装完gitlab之后修改,如果已经使用一段时间,在修改项目的数量,需要你自己在自己的用户下修改,第二次初始化,会缩短时间。

首先登录gitlab,root用户登录,点击管理区域,点击设置,展开帐户和限制设置:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7361XUaG-1599485585111)(assets/1532328529075.png)]

修改项目限制数量值。

关闭注册功能,默认注册功能是开启的,对于个人或企业的 gitlab,没有对外公布注册的必要。

首先点击管理区域,再点击设置按钮,展开注册限制,去掉注册激活复选框的选中,然后保存。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5mWI4w8n-1599485585113)(assets/1532328771783.png)]

#关闭服务 [root@node1 ~]$ sudo gitlab-ctl stop [root@node1 ~]$ sudo vi /etc/gitlab/gitlab.rb ## 把true改成false ## prometheus_monitoring['enable']= true prometheus_monitoring['enable']= false #保存退出#重新加载配置文件 [root@node1 ~]$ sudo gitlab-ctl reconfigure#启动服务 [root@node1 ~]$ sudo gitlab-ctl start ok: run: gitaly: (pid 21611) 0s ok: run: gitlab-workhorse: (pid 21615) 1s ok: run: logrotate: (pid 21622) 0s ok: run: nginx: (pid 21628) 1s ok: run: postgresql: (pid 21633) 0s ok: run: redis: (pid 21641) 0s ok: run: sidekiq: (pid 21645) 1s ok: run: unicorn: (pid 21648) 0s #很显然没有 prometheus 这个服务 

初始化器的密码长度设置为最少长度是12个字符,最大长度是128个字符

[root@node1 ~]$ sudo cd /opt/gitlab/embedded/service/gitlab-rails/config/initializers [root@node1 initializers]$ sudo cp devise_password_length.rb.example devise_password_length.rb [root@node1 initializers]$ sudo vi devise_password_length.rb Devise.setup do |config|# The following line changes the password length limits for new users. In the# example below the minimum length is 12 characters, and the maximum length# is 128 characters.config.password_length = 12..128 end#重启gitlab服务 [root@node1 ~]$ sudo gitlab start 

为了防止滥用客户造成损害GitLab使用机架攻击,提供一个保护路径。

默认情况下,用户登录,用户注册(如果启用)和用户密码重置被限制为每分钟6个请求。尝试6次后,客户端将不得不等待下一分钟再次尝试。

如果发现节流不足以保护您免遭滥用客户端,机架式攻击宝石提供IP白名单,黑名单,Fail2ban样式过滤器和跟踪。

[root@node1 ~]$ sudo cd /opt/gitlab/embedded/service/gitlab-rails/config/initializers [root@gitlab initializers]# cp rack_attack.rb.example rack_attack.rb#编辑application.rb [root@node1 ~]$ sudo vi /opt/gitlab/embedded/service/gitlab-rails/config/application.rb config.middleware.use Rack::Attack #保存,重新启动GitLab实例 
 **Git**是分布式版本控制系统(DVCS)。这意味着每个与源代码一起工作的人都具有完整存储库的本地副本。在GitLab中,不是客人的所有项目成员(因此,记者,开发人员和主人)都可以克隆资料库以获取本地副本。获取本地副本后,用户可以随时上传完整的存储库,包括其控制下的另一个项目或其他服务器。结果是您无法构建访问控制,阻止有权访问源代码的用户有意共享源代码。这是DVCS的固有特性,所有git管理系统都有这个限制。很明显,你可以采取措施,防止意外分享和破坏信息,这就是为什么只有一些人被允许邀请他人,没有人可以强制推行一个受保护的分支机构。 
[root@node1 ~]$ sudo gitlab-railsconsole production Loading production environment (Rails 4.2.8) irb(main):001:0> user = User.where(id: 1).first#查看信息 => #<User id: 1, email: "admin@example.com",created_at: "2017-05-16 09:04:59", updated_at: "2017-05-1707:18:16", name: "Administrator", admin: true, projects_limit:100000, skype: "", linkedin: "", twitter: "",authentication_token: "k44aWyAaaaJaHYx4B_QP", bio: nil, username:"root", can_create_group: true, can_create_team: false, state:"active", color_scheme_id: 1, password_expires_at: nil,created_by_id: nil, last_credential_check_at: nil, avatar: nil,hide_no_ssh_key: false, website_url: "", notification_email:"admin@example.com", hide_no_password: false, password_automatically_set:false, location: nil, encrypted_otp_secret: nil, encrypted_otp_secret_iv: nil,encrypted_otp_secret_salt: nil, otp_required_for_login: false,otp_backup_codes: nil, public_email: "", dashboard: 0, project_view:2, consumed_timestep: nil, layout: 0, hide_project_limit: false,otp_grace_period_started_at: nil, ldap_email: false, external: false,incoming_email_token: "9wt82lanyjoakil3asrhfevvh", organization: nil,authorized_projects_populated: true, ghost: nil, last_activity_on: nil, notified_of_own_activity:false, require_two_factor_authentication_from_group: false,two_factor_grace_period: 48> irb(main):002:0> user.password = 'admin123' #设置新的密码 => "admin123" irb(main):003:0> user.password_confirmation = 'admin123' #验证密码 => "admin123" irb(main):004:0> user.save! #保存密码 Enqueued ActionMailer::DeliveryJob (Job ID:b2ba5d30-853c-405d-8d95-fa938d88f32c) to Sidekiq(mailers) with arguments:"DeviseMailer", "password_change", "deliver_now",gid://gitlab/User/1 => true irb(main):005:0> #ctrl+d退出 

如果您想在所有用户电子邮件登录之前确认,Gitlab管理员可以在注册时启用电子邮件确认。

GitLab默认是使用HTTP的,可以手动配置为HTTPS

创建ssl目录,用于存放SSL证书

[root@node1 ~]# mkdir -p /etc/gitlab/ssl [root@node1 ~]# chmod 0700 /etc/gitlab/ssl 

上传证书并修改证书权限

[root@node1 ~]# chmod 600 /etc/gitlab/ssl/* 

修改配置文件

[root@node1 ~]# vi /etc/gitlab/gitlab.rb external_url "https://gitlab.xxx.com" nginx['redirect_http_to_https'] = true nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.xxx.com.crt" nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.xxx.com.key" 

重置修改的配置,使其生效

[root@node1 ~]# gitlab-ctl reconfigure 

以上操作后,GitLab自带的Nginx服务的配置文件会被重新修改:

[root@node1 ~]# vi /var/opt/gitlab/nginx/conf/gitlab-http.conf server {listen *:80;server_name gitlab.xxx.com;server_tokens off; ## Don't show the nginx version number, a security best practicereturn 301 https://gitlab.xxx.com:443$request_uri;access_log /var/log/gitlab/nginx/gitlab_access.log gitlab_access;error_log /var/log/gitlab/nginx/gitlab_error.log; } 

不用额外再配置,HTTP 会自动跳转到 HTTPS 。

在防火墙上开放443端口,用于HTTPS。

注意防火墙记得添加放行443端口,然后就可以访问配置的域名进行测试了。

[root@node1 ~]# iptables -I INPUT -m tcp -p tcp --dport 443 -j ACCEPT 

如果你不想用服务器自带的postfix服务来发邮件,可以改用SMTP服务。

修改GitLab邮件服务配置(gitlab.rb文件).

使用腾讯企业邮箱的SMTP服务器,填写账号和密码

[root@node1 ~]# vi /etc/gitlab/gitlab.rb gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.exmail.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "xxxx@xx.com" gitlab_rails['smtp_password'] = "password" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com' gitlab_rails['smtp_domain'] = "exmail.qq.com" 
[root@node1 ~]# vi /etc/gitlab/gitlab.rb gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.mxhichina.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "no-reply@cnyunwei.cc" gitlab_rails['smtp_password'] = "ABcd123456" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = 'no-reply@cnyunwei.cc' 
[root@node1 ~]# vi /etc/gitlab/gitlab.rb gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp-mail.outlook.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "username@outlook.com" gitlab_rails['smtp_password'] = "password" gitlab_rails['smtp_domain'] = "smtp-mail.outlook.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_openssl_verify_mode'] = 'peer' 
[root@node1 ~]# gitlab-ctl reconfigure [root@node1 ~]# gitlab-rake cache:clear RAILS_ENV=production # 清除缓存 

官方给出了一个测试方法,登录到console 控制台进行测试。

[root@node1 ~]# gitlab-rails consoleirb(main):003:0> Notify.test_email('cnblog@cnyunwei.cc', 'Test Page', 'This is test mail').deliver_now#Notify.test_email('收件人邮箱', '邮件标题', '邮件正文').deliver_now 

注意:

  • 如果发送失败建议先通过postfix 等邮件客户端工具配置该发信邮箱测试是否能够通过SMTP方式发送邮件,另外smtp地址如果已经额外加了解析为自己的smtp.cnyunwei.cc 等方式,也建议直接配置为企业邮箱提供的smtp地址。
  • 目前大部分IDC 都封了25端口,需要配置465加密端口才可以发送邮件,这也是为什么不用postfix的原因。 官方已经给出了详细配置方法了: https://docs.gitlab.com.cn/omnibus/settings/smtp.html#smtp-settings 

6.4 gitlab 中文本地化

[root@node1 ~]$ sudo cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 11.0.3-ee 
#停止服务 [root@node1 ~]$ sudo gitlab-ctl stop# 如没安装git,需提前安装 [root@node1 ~]$ sudo yum install -y git# 创建gitlba汉化包下载目录 [root@node1 ~]$ sudo mkdir /tmp/gitlab [root@node1 ~]$ cd /tmp/gitlab# 下载最新的汉化包 [root@node1 gitlab]$ sudo git clone https://gitlab.com/xhang/gitlab.git# 如果是要下载老版本的汉化包,需要加上老版本的分支,例如想下载10.0.2,可以运行如下语句 [root@node1 gitlab]$ sudo git clone https://gitlab.com/xhang/gitlab.git -b v10.0.2-zh 
#查看汉化版本 [root@node1 ~]$ sudo cd /tmp/gitlab/gitlab [root@node1 gitlab]# cat VERSION 11.0.3#生成补丁 [root@node1 gitlab]$ sudo git diff v11.0.3 v11.0.3-zh > /tmp/11.0.3-zh.diff#安装patch组件 [root@node1 gitlab]$ sudo yum install -y patch #打补丁 [root@node1 gitlab]$ sudo patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /tmp/11.0.3-zh.diff 
注意重点:

此时如果出现类似以下内容,则按住回车,一直跳过就行了。

can’t find file to patch at input line 5

Perhaps you used the wrong -p or –strip option?

The text leading up to this was:

|diff –git a/app/assets/javascripts/awards_handler.js b/app/assets/javascripts/awards_handler.js

|index eb0f06e…73e4833 100644

|— a/app/assets/javascripts/awards_handler.js

|+++ b/app/assets/javascripts/awards_handler.js

File to patch:

## 重新启动 gitlab [root@node1 ~]$ sudo gitlab-ctl start 

访问服务器是会出现502的问题,多等一会,刷新几遍就ok!至此,gitlab安装完成并汉化ok!
向以下的各位致敬!!!

本地化效果如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bku2seeK-1599485585116)(assets/1532315345593.png)]

http://www.cnblogs.com/xiaojwang/p/9296964.html

https://www.jianshu.com/p/4f8afc36a115

CentOS7.5安装Gitlab11.0及汉化

https://blog.csdn.net/wh211212/article/details/72627803

https://www.cnblogs.com/straycats/p/7637373.html

https://segmentfault.com/a/1190000014292040?utm_source=index-hottest

6.5 GitLab中SSH密钥配置

Git是一个分布式版本控制系统,这意味着您可以在本地工作,但您也可以将更改共享或“推送”到其他服务器。在将更改推送到GitLab服务器之前,您需要一个安全的通信通道来共享信息。 SSH协议提供此安全性,允许您在不提供用户名或密码的情况下对GitLab远程服务器进行身份验证。 有关SSH协议如何工作的更详细说明,我们建议您阅读DigitalOcean的这个精彩教程。

在生成新的SSH密钥对之前,通过打开shell检查您的系统是否已在默认位置有一个, 或Windows上的命令提示符,并运行以下命令:

Windows Command Prompt:

type %userprofile%.ssh\id_rsa.pub

Git Bash on Windows / GNU/Linux / macOS / PowerShell:

cat ~/.ssh/id_rsa.pub

如果您看到以 ssh-rsa 开头的字符串,则您已经拥有SSH密钥对,并且可以跳过下一部分的生成部分并跳到复制到剪贴板步骤。如果您没有看到该字符串或想要生成具有自定义名称的SSH密钥对,请继续执行下一步。

请注意,公共SSH密钥也可以如下命名:

  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub

1、要生成新的SSH密钥对,请使用以下命令:

Git Bash on Windows / GNU/Linux / macOS:

ssh-keygen -t rsa -C "your.email@example.com" -b 4096 
参数说明:

rsa:选择生成的密钥类型

4096:确定生成密钥的强度,默认是1204

Windows:

或者在Windows上,您可以下载PuttyGen并按照此文档文章生成SSH密钥对。

2、接下来,系统将提示您输入文件路径以保存SSH密钥对。

如果您还没有SSH密钥对,请按Enter键使用建议的路径。使用建议的路径通常允许SSH客户端自动使用SSH密钥对而无需其他配置。 如果您已经有一个带有建议文件路径的SSH密钥对,则需要输入一个新的文件路径并在.ssh / config文件中声明该SSH密钥对将用于哪个主机,请参阅使用非默认SSH密钥对路径以获取更多信息。

3、输入文件路径后,系统将提示您输入密码以保护SSH密钥对。最好使用SSH密钥对的密码,但这不是必需的,您可以通过按Enter键跳过创建密码。

注意:如果要更改SSH密钥对的密码,可以使用ssh-keygen -p <keyname>

4、下一步是复制公共SSH密钥,因为我们之后将需要它。

要将公共SSH密钥复制到剪贴板,请使用以下相应的代码:

macOS:

pbcopy < ~/.ssh/id_rsa.pub
GNU/Linux (requires the xclip package):

xclip -sel clip < ~/.ssh/id_rsa.pub
Windows Command Line:

type %userprofile%\.ssh\id_rsa.pub | clip
Git Bash on Windows / Windows PowerShell:

cat ~/.ssh/id_rsa.pub | clip

5、最后一步是将您的公共SSH密钥添加到GitLab。

导航到“配置文件设置”中的“SSH密钥”选项卡。将您的密钥粘贴到“密钥”部分,并为其指定相关的“标题”。使用可识别的标题,如“工作笔记本电脑 – Windows 7”或“家用MacBook Pro 15”。

如果您手动复制了公共SSH密钥,请确保复制了以ssh-rsa开头并以电子邮件结尾的整个密钥。

6、(可选)您可以通过运行ssh -T git@example.com(用您的GitLab域替换example.com)并验证您是否收到Welcome to GitLab消息来测试您的设置。

如果您为GitLab SSH密钥对使用了非默认文件路径,则必须配置SSH客户端以查找与GitLab服务器(可能是gitlab.com)连接的GitLab私有SSH密钥。

对于当前的终端会话,您可以使用以下命令(使用私有SSH密钥替换other_id_rsa)来执行此操作:

Git Bash on Windows / GNU/Linux / macOS:

eval $(ssh-agent -s) ssh-add ~/.ssh/other_id_rsa

要保留这些设置,您需要将它们保存到配置文件中。对于OpenSSH客户端,这在某些操作系统的〜/ .ssh / config文件中配置。以下是使用自己的SSH密钥的两个示例主机配置:

 Host gitlab.com RSAAuthentication yes IdentityFile ~/.ssh/config/private-key-filename-01 Host gitlab.company.com RSAAuthentication yes IdentityFile ~/.ssh/config/private-key-filename

由于SSH客户端种类繁多,配置选项非常多,因此对这些主题的进一步说明超出了本文档的范围。

公共SSH密钥必须是唯一的,因为它们将绑定到您的帐户。您的SSH密钥是通过SSH推送代码时唯一的标识符。这就是它需要唯一映射到单个用户的原因。

每个仓库部署密钥(Per-repository deploy keys)

部署密钥允许使用单个SSH密钥对对一个或多个项目进行只读或读写(如果已启用)访问。

这对于将存储库克隆到Continuous Integration(CI)服务器非常有用。通过使用部署密钥,您不必设置虚拟用户帐户。

如果您是项目维护者或所有者,则可以在“存储库”部分下的项目设置中添加部署密钥。为新部署密钥指定标题并粘贴公共SSH密钥。在此之后,使用相应私有SSH密钥的计算机具有对项目的只读或读写(如果已启用)访问权限。

您无法使用表单两次添加相同的部署密钥。如果要将相同的密钥添加到另一个项目,请在“从可用项目部署密钥”列表中启用它。您可以访问的所有项目的所有部署密钥都可用。该项目访问可以通过成为项目的直接成员或通过组来实现。

部署密钥可以在项目之间共享,您只需将它们添加到每个项目中。

全局共享部署密钥(Global Shared Deploy)

Global Shared Deploy键允许在整个GitLab安装中的任何存储库上配置只读或读写(如果启用)访问。

这对于将存储库集成到安全的共享持续集成(CI)服务或其他共享服务非常有用。 GitLab管理员可以在GitLab中设置Global Shared Deploy密钥,并将私钥添加到任何共享系统。当项目维护者(或更高级别)授权将Global Shared Deploy密钥用于其项目时,各个存储库会选择使用这些密钥公开其存储库。

与每个项目部署密钥相比,全局共享密钥可以提供更高的安全性,因为目标集成系统的管理员是唯一需要知道和配置私钥的人。

GitLab管理员在“部署密钥”部分下的“管理”区域中设置Global Deploy密钥。确保密钥具有有意义的标题,因为这将是项目维护者和所有者识别要添加的正确Global Deploy密钥的主要方式。例如,如果密钥提供对SaaS CI实例的访问权限,则在密钥名称中使用该服务的名称(如果它是用于的全部)。在创建全局共享部署密钥时,请考虑密钥的粒度 – 它们的使用范围非常狭窄,例如只是特定服务或更广泛的用途,例如“您需要提供对存储库的读取访问权限”。

一旦GitLab管理员添加了全局部署密钥,项目维护人员和所有者就可以通过展开“部署密钥”部分并单击任何项目可用的公共部署密钥下列出的相应密钥旁边的“启用”,将其添加到项目的“设置”>“存储库”部分中。

注意:只有配置了至少一个Global Deploy Key时,才会显示任何项目可用的标题公共部署密钥。

小心:警告:定义全局部署密钥不会通过密钥公开任何给定的存储库,直到该存储库将Global Deploy密钥添加到其项目中。通过这种方式,全局部署密钥可以启用其他系统的访问,但不要仅通过设置它们来隐式地提供任何访问。

Eclipse

如何将您的SSH密钥添加到Eclipse: https://wiki.eclipse.org/EGit/User_Guide#Eclipse_SSH_Configuration

GitLab服务器上的SSH

GitLab与系统安装的SSH守护程序集成,指定用户(通常命名为git),通过该用户处理所有访问请求。通过SSH连接到GitLab服务器的用户通过SSH密钥而不是用户名来标识。

在GitLab服务器上执行的SSH客户端操作将作为该用户执行。虽然可以修改该用户的SSH配置,例如,提供私有SSH密钥来验证这些请求,但是不支持这种做法,并且强烈建议不要这样做,因为它会带来很大的安全风险。

GitLab检查过程包括检查此条件,如果您的服务器配置如下,将指导您到此部分,例如:

$ gitlab-rake gitlab:check  Git user has default SSH configuration? ... noTry fixing it:mkdir ~/gitlab-check-backup-1504540051sudo mv /var/lib/git/.ssh/id_rsa ~/gitlab-check-backup-1504540051sudo mv /var/lib/git/.ssh/id_rsa.pub ~/gitlab-check-backup-1504540051For more information see:doc/ssh/README.md in section "SSH on the GitLab server"Please fix the error above and rerun the checks.

只要你能够删除自定义配置。明确不支持这些自定义,并且可能随时停止工作。

如果在Git clone克隆上,系统会提示您输入密码,例如git@gitlab.com的密码:SSH设置有问题。

  • 确保您正确生成了SSH密钥对,并将公共SSH密钥添加到GitLab配置文件中
  • 尝试使用ssh-agent手动注册私有SSH密钥,如本文档前面所述
  • 尝试通过运行ssh -Tv git@example.com来调试连接(用您的GitLab域替换example.com

新建密钥在你自己的本地上生成,是本机要和服务端(Gitlab Server)进行通信,所以要在你本地(一般都是windows)下生产密钥对,生成完后用记事本打开C:\Users\Administrator\.ssh>type id_rsa.pub这个文件,将密钥字符串复制到密钥框。

6.8 gitlib 备份和恢复

GitLab作为公司项目代码的版本管理系统,数据非常重要,必须做好备份。

1、修改备份目录

GitLab备份的默认目录是 /var/opt/gitlab/backups ,如果想改备份目录,可修改/etc/gitlab/gitlab.rb:

[root@node1 ~] gitlab_rails['backup_path'] = '/data/backups' 

修改配置后,记得:

[root@node1 ~] 

2、备份命令

[root@node1 ~] 

该命令会在备份目录(默认:/var/opt/gitlab/backups/)下创建一个tar压缩包xxxxxxxx_gitlab_backup.tar,其中开头的xxxxxx是备份创建的时间戳,这个压缩包包括GitLab整个的完整部分。

通过任务计划crontab 实现自动备份

 0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create 

可设置只保留最近7天的备份,编辑配置文件 /etc/gitlab/gitlab.rb

[root@node1 ~]  gitlab_rails['backup_keep_time'] = 604800 

重新加载gitlab配置文件

[root@node1 ~] 

备份文件:

/var/opt/gitlab/backups/1499244722_2017_07_05_9.2.6_gitlab_backup.tar 

停止 unicorn 和 sidekiq ,保证数据库没有新的连接,不会有写数据情况。

 [root@node1 ~] [root@node1 ~]   [root@node1 ~] [root@node1 ~] 

6.10 小结

四步完成 Gitlab-ee 的安装与配置,我这里安装的版本:Installing : gitlab-ee-11.0.3-ee.0.el7.x86_64。

这个版本的新特性:GitLab 11.0 released with Auto DevOps and License Management

无论您的流程如何,GitLab都能提供强大的规划工具,让每个人都保持同步。

GitLab 通过 epics, groups (programs) 和 milestones 实现项目组合的规划和管理,并组织和跟踪进度。无论您使用从瀑布到DevOps的开发方法,GitLab简单灵活的规划方法都能满足小型团队和大型企业的需求。 GitLab帮助团队组织,计划,调整和跟踪项目工作,以确保团队在正确的时间处理正确的事情,并在从构思到生产的整个交付生命周期中保持问题的端到端可见性和可追溯性。

通过强大的分支工具创建,查看和管理代码和项目数据。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-AcEkNxvr-1599485585120)(assets/devops-loop-and-spans-small.png)]

GitLab是DevOps生命周期所有阶段的第一个单一应用程序。只有GitLab才能启用Concurrent DevOps,从组件链的约束中解锁组织。 GitLab提供无与伦比的可见性,更高的效率和全面的治理。这使得软件生命周期快3倍,从根本上提高了业务速度。

官网地址:https://about.gitlab.com/installation/#centos-7

文件:

/var/opt/gitlab/backups/1499244722_2017_07_05_9.2.6_gitlab_backup.tar 

停止 unicorn 和 sidekiq ,保证数据库没有新的连接,不会有写数据情况。

 [root@node1 ~] [root@node1 ~]   [root@node1 ~] [root@node1 ~] 

6.10 小结

四步完成 Gitlab-ee 的安装与配置,我这里安装的版本:Installing : gitlab-ee-11.0.3-ee.0.el7.x86_64。

这个版本的新特性:GitLab 11.0 released with Auto DevOps and License Management

无论您的流程如何,GitLab都能提供强大的规划工具,让每个人都保持同步。

GitLab 通过 epics, groups (programs) 和 milestones 实现项目组合的规划和管理,并组织和跟踪进度。无论您使用从瀑布到DevOps的开发方法,GitLab简单灵活的规划方法都能满足小型团队和大型企业的需求。 GitLab帮助团队组织,计划,调整和跟踪项目工作,以确保团队在正确的时间处理正确的事情,并在从构思到生产的整个交付生命周期中保持问题的端到端可见性和可追溯性。

通过强大的分支工具创建,查看和管理代码和项目数据。

[外链图片转存中…(img-AcEkNxvr-1599485585120)]

GitLab是DevOps生命周期所有阶段的第一个单一应用程序。只有GitLab才能启用Concurrent DevOps,从组件链的约束中解锁组织。 GitLab提供无与伦比的可见性,更高的效率和全面的治理。这使得软件生命周期快3倍,从根本上提高了业务速度。

官网地址:https://about.gitlab.com/installation/#centos-7

原文链接:http://e.betheme.net/article/show-134770.html

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享