1.硬件要求
CPU
1个核心最多支持100个用户,但由于所有工作和后台作业都在同一个核心上运行,因此应用程序可能会慢一点
2核是建议的核心数,最多支持500个用户
4个核心最多可支持2,000个用户
8个核心最多支持5,000个用户
16个内核最多可支持10,000个用户
32个核心最多可支持20,000个用户
64个内核最多可支持40,000个用户内存
至少8GB可寻址内存来安装gitlab,在运行gitlab之前,至少需要4GB可用空间,建议至少有2BG交换,建议将内核的swappiness 设置为较低水平足以vim /etc/sysctl.conf vm.swappiness = 10
复制数据库
运行数据库服务器至少要有5-10GB的可存储空间,但具体要求取决于gitlab安装的大小。强烈支持使用postgresql,Mysql/mariadb(不支持所有的gitlab功能)
Postgresql 要求:
从GitLab 10.0开始,需要PostgreSQL 9.6或更高版本,并且不支持早期版本。我们强烈建议用户使用PostgreSQL 9.6,因为这是用于开发和测试的PostgreSQL版本。
使用PostgreSQL的用户必须确保将pg_trgm扩展加载到每个GitLab数据库中。可以通过对每个数据库运行以下查询来启用此扩展(使用PostgreSQL超级用户):
CREATE EXTENSION pg_trgm;
在某些系统上,您可能需要安装额外的软件包(例如 postgresql-contrib)以使此扩展可用。Gitlab geo 要求
如果您使用的是GitLab Geo,则跟踪数据库也需要postgres_fdw扩展名。
CREATE EXTENSION postgres_fdw;Unicorn
可以增加unicorn worker 的数量,有助于减少应用程序的响应时间并提高处理并行请求的能力
对于大多数情况,建议使用:CPU核心+1=unicorn worker
对于所有2GB及以上的机器,建议至少有3个,如果是1GB建议使用两个redis和 sidekiq
Redis 存储所有用户会话和后台任务队列,redis的存储要求很低,每个用户大约25KB,sidekiq使用多线程进程处理后台作业,此过程从整个redis堆栈(200M+)开始,但由于内存泄露,他可能会随着时间的推移而增长,在非常活跃的服务器上,sidekiq进程可以使用1GB+内存Prometheus 及相关,使用默认设置,这些进程将消耗大概200M内存
2.部署gitlab
2.1.安装gitlab
step 1.OS 环境描述
[root@kids ~]# cat /etc/redhat-release CentOS Linux release 8.1.1911 (Core)
复制
step 2.安装相关依赖
yum -y install curl policycoreutils-python openssh-server perl rpm -ivh http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/policycoreutils-python-utils-2.9-3.el8_1.1.noarch.rpm
复制
step 3.安装Postfix来发送通知邮件
dnf install -y postfix
复制
编辑 /etc/postfix/main.cf 打开main.cf文件,将这行代码改为 “inet_interfaces = all” 。
systemctl enable postfix systemctl start postfix
复制
step 4.下载并配置yum源
官方地址:
https://packages.gitlab.com/gitlab/gitlab-ce/
a.缓存 packages 进行安装
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash ...... Complete! Generating yum cache for gitlab_gitlab-ce... Importing GPG key 0x51312F3F: Userid : "GitLab B.V. (package repository signing key) <packages@gitlab.com>" Fingerprint: F640 3F65 44A3 8863 DAA0 B6E0 3F01 618A 5131 2F3F From : https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey Importing GPG key 0xF27EAB47: Userid : "GitLab, Inc. <support@gitlab.com>" Fingerprint: DBEF 8977 4DDB 9EB3 7D9F C3A0 3CFC F9BA F27E AB47 From : https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg Generating yum cache for gitlab_gitlab-ce-source... The repository is setup! You can now install packages. [root@localhost ~]#
复制
b.修改yum源安装
将baseurl修改为清华镜像,预览无误后加-i参数保存
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
sed -e 's#^baseurl.*#baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/#' -e 's#^repo_gpgcheck.*#repo_gpgcheck=0#g' -e 's#^gpgcheck.*#gpgcheck=0#g' -e 's#^sslverify.*#sslverify=0#g' /etc/yum.repos.d/gitlab_gitlab-ce.repo
复制
c.下载rom包安装
wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/8/gitlab-ce-13.7.1-ce.0.el8.aarch64.rpm/download.rpm
复制
2.2.gitlab相关命令
- gitlab-ctl start #启动全部服务
- gitlab-ctl restart#重启全部服务
- gitlab-ctl stop #停止全部服务
- gitlab-ctl restart nginx #重启单个服务,如重启nginx
- gitlab-ctl status #查看服务状态
- gitlab-ctl reconfigure #使配置文件生效
- gitlab-ctl show-config #验证配置文件
- gitlab-ctl uninstall #删除gitlab(保留数据)
- gitlab-ctl cleanse #删除所有数据,从新开始
- gitlab-ctl tail <service name>查看服务的日志
- gitlab-ctl tail nginx #如查看gitlab下nginx日志
- gitlab-rails console #进入控制台
3.配置Gitlab
3.1.配置文件
其中包含所有的主配置的情况,组件的配置,其配置后需要进行reconfigure 进行生效配置并重启方可生效,其生效后的结果在各组件目录中可以看到
[root@kids ~]# cd /etc/gitlab/ [root@kids gitlab]# ls 22,1 0% gitlab.rb gitlab-secrets.json trusted-certs [root@kids gitlab]#
复制
主目录
[root@kids gitlab]# cd /opt/ [root@kids opt]# pwd /opt [root@kids opt]# ls apache-maven-3.6.3 apache-tomcat-9.0.34 gitlab mallplus [root@kids opt]# [root@kids opt]# cd gitlab/ [root@kids gitlab]# ls bin embedded init LICENSES sv version-manifest.json dependency_licenses.json etc LICENSE service var version-manifest.txt [root@kids gitlab]#
复制
各个组件目录
[root@kids gitlab]# cd /var/opt/gitlab/ [root@kids gitlab]# ls alertmanager git-data gitlab-shell nginx prometheus backups gitlab-ci gitlab-workhorse node-exporter public_attributes.json bootstrapped gitlab-exporter grafana postgres-exporter redis gitaly gitlab-rails logrotate postgresql trusted-certs-directory-hash [root@kids gitlab]#
复制
日志文件目录
[root@kids gitlab]# cd /var/log/gitlab/ [root@kids gitlab]# ls alertmanager gitlab-rails grafana node-exporter prometheus sidekiq gitaly gitlab-shell logrotate postgres-exporter reconfigure unicorn gitlab-exporter gitlab-workhorse nginx postgresql redis [root@kids gitlab]#
复制
3.2.gitlab服务构成
GitLab 由主要由以下服务构成,他们共同承担了 Gitlab 的运作需要
Nginx:静态 web 服务器。
gitlab-shell:用于处理 Git 命令和修改 authorized keys 列表。
gitlab-workhorse: 轻量级的反向代理服务器。
logrotate:日志文件管理工具。
postgresql:数据库。
redis:缓存数据库。
sidekiq:用于在后台执行队列任务(异步执行) 。
unicorn:An HTTP server for Rack applications,GitLab Rails 应用是托管在这个服务器上面的
查看服务状态:gitlab-ctl status,可以看到gitlab的依赖组件
gitlab安装目录
以下是gitlab常用的默认安装目录
- gitlab组件日志路径:/var/log/gitlab
- gitlab配置路径:/etc/gitlab/ 路径下有gitlab.rb配置文件
- 应用代码和组件依赖程序:/opt/gitlab
- 各个组件存储路径: /var/opt/gitlab/
- 仓库默认存储路径 /var/opt/gitlab/git-data/repositories
- 版本文件备份路径:/var/opt/gitlab/backups/
- nginx安装路径:/var/opt/gitlab/nginx/
- redis安装路径:/var/opt/gitlab/redis
3.3.插件
- repository: 代码库,可以是硬盘或NFS文件系统
- NGINX: web 入口
- 数据库:包含信息
- ository 中的数据(元数据,issue,合并请求merge request等),可以登录的web用户信息
- Redis 缓存 ,负责分发信息
- sidekq: 后台任务,主要负责发送电子邮件,任务来自与redis
- unicorn (gitlab rails):gitlab自身的web,包含了gitlab主进程,负责处理快速/一般任务,与redis一起工作,内容有:
- 通过检查存储在redis中的用户来检查权限
- 为sidekiq 制作任务
- 从仓库(warehouse) 取东西或在哪里移动东西
- gitlab-shell:用于SSH交互,而不是http,gitlab-shell 通过redis与sidekiq 进行通信,并直接通过TCP访问unicorn
- gitaly: 后台服务,专门负责访问磁盘以高效处理git,并处理缓存耗时操作,所有的git操作都通过gitaly 进行处理
- gitlab-workshorse: 反向代理服务器,可以处理与redis无关的请求,磁盘上的CSS,JS 文件等),处理git push/pull 请求,处理redis的链接(修改有redis发送的响应或发送给redis请求,管理redis的长期web socket链接)
- mail_room: 处理邮件请求,恢复gitlab发送的邮件时,gitlab会调用此服务.
3.3.配置 URL 访问地址
a.安装时指定参数EXTERNAL_URL
EXTERNAL_URL="47.108.128.208" yum install -y gitlab-ce
复制
b.安装后修改EXTERNAL_URL
sed "s#^external_url.*#external_url 'http://193.169.100.25'#" /etc/gitlab/gitlab.rb | grep ^external_url 确认无误后使用-i保存进配置文件 sed -i "s#^external_url.*#external_url 'http://193.169.100.25'#" /etc/gitlab/gitlab.rb
复制
c .编辑 /etc/gitlab/gitlab.rb ,修改如下:
external_url '47.108.128.208:9080'
复制
配置生效,重新执行此命令时间也比较长
# gitlab-ctl reconfigure
复制
重启服务器:
[root@kids ~]# gitlab-ctl restart ok: run: alertmanager: (pid 17870) 0s ok: run: gitaly: (pid 17884) 0s ok: run: gitlab-exporter: (pid 17892) 0s ok: run: gitlab-workhorse: (pid 17902) 0s ok: run: grafana: (pid 17924) 0s ok: run: logrotate: (pid 17942) 1s ok: run: nginx: (pid 17950) 0s ok: run: node-exporter: (pid 17957) 1s ok: run: postgres-exporter: (pid 17966) 0s ok: run: postgresql: (pid 18053) 1s ok: run: prometheus: (pid 18062) 0s ok: run: sidekiq: (pid 18087) 0s ok: run: unicorn: (pid 18099) 0s
复制
查看服务状态
[root@kids ~]# gitlab-ctl status run: alertmanager: (pid 17870) 100s; run: log: (pid 16023) 797s run: gitaly: (pid 17884) 99s; run: log: (pid 1339) 85024s run: gitlab-exporter: (pid 17892) 99s; run: log: (pid 15916) 807s run: gitlab-workhorse: (pid 17902) 98s; run: log: (pid 15803) 832s run: grafana: (pid 17924) 98s; run: log: (pid 16158) 765s run: logrotate: (pid 17942) 98s; run: log: (pid 15868) 820s run: nginx: (pid 17950) 97s; run: log: (pid 15847) 825s run: node-exporter: (pid 17957) 97s; run: log: (pid 15900) 814s run: postgres-exporter: (pid 17966) 96s; run: log: (pid 16053) 791s run: postgresql: (pid 18053) 96s; run: log: (pid 1337) 85024s run: prometheus: (pid 18062) 95s; run: log: (pid 15976) 803s run: sidekiq: (pid 18087) 92s; run: log: (pid 15776) 840s run: unicorn: (pid 18099) 91s; run: log: (pid 15760) 842s [root@kids ~]#
复制
3.4.配置邮件服务器
3.5.配置外部Redis
step 1.编辑gitlab.rb文件
redis['enable'] = false 使用TCOP连接 gitlab_rails['redis_host'] = '127.0.0.1' gitlab_rails['redis_port'] = 6380 gitlab_rails['redis_password'] = 'test' #访问redis的密码
复制
step 2. 加载和重启gitlab
gitlab-ctl reconfigure gitlab-ctl restart
复制
3.6.配置外部postgresql数据库
cd /var/opt/gitlab/ cat gitlab-rails/etc/database.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: adapter: postgresql encoding: unicode collation: database: gitlabhq_production pool: 1 username: "gitlab" password: host: "/var/opt/gitlab/postgresql" port: 5432 socket: sslmode: sslcompression: 0 sslrootcert: sslca: load_balancing: {"hosts":[]} prepared_statements: false statement_limit: 1000 fdw: variables: statement_timeout: 60000
复制
3.7.配置外部mysql
step 1.创建MySQL数据库
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; mysql> grant all on gitlabhq_production.* to 'git'@'localhost' identified by 'git';
复制
step 2.bundle禁止使用postgresql,把mysql改成postgres
#cat /opt/gitlab/embedded/service/gitlab-rails/.bundle/config --- BUNDLE_RETRY: "5" BUNDLE_JOBS: "33" BUNDLE_WITHOUT: "development:test:mysql"
复制
step 3.修改/etc/gitlab/gitlab.rb
postgresql['enable'] = false gitlab_rails['db_adapter'] = 'mysql2' gitlab_rails['db_encoding'] = 'utf8' gitlab_rails['db_host'] = '127.0.0.1' gitlab_rails['db_port'] = '3306' gitlab_rails['db_username'] = 'git' gitlab_rails['db_password'] = '123456'
复制
step 4.检测运行环境
gitlab-rake gitlab:check
复制
根据提示是0.4.5版本
cd /opt/gitlab/embedded/bin/ ./gem install mysql2 -v "0.4.5" ./gem install peek-mysql2 -v 1.1.0
复制
step 5.检测不报错,从新加载配置
gitlab-ctl reconfigure
复制
3.8.gitlab更改默认的nginx
step 1.修改配置文件/etc/gitlab/gitlab.rb
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb nginx['enable'] = false #不启用nginx
复制
step 2.检查默认nginx配置文件,并迁移至新Nginx服务
nginx配置文件,包含gitlab-http.conf文件 /var/opt/gitlab/nginx/conf/nginx.conf gitlab核心nginx配置文件 /var/opt/gitlab/nginx/conf/gitlab-http.conf
复制
step 3.重启 nginx、gitlab服务
[root@gitlab ~]# gitlab-ctl restart [root@gitlab ~]# systemctl restart nginx.service
复制
访问可能出现报502。原因是nginx用户无法访问gitlab用户的socket文件。 重启gitlab需要重新授权
[root@gitlab ~]# chmod -R o+x /var/opt/gitlab/gitlab-rails
复制
4.使用Gitlab
4.1.登录和基本语言配置
首次登录使用用户名root,密码为首次访问GitLab时设置的新密码。
设置环境为简体中文
4.2.创建用户组
4.3.创建项目(在指定的用户组中)
4.4.创建用户
Password:
重置链接将生成并发送给用户。用户将被迫在首次登录时设置密码。
编辑用户,可以创建密码:
4.5.用户加组
4.6.登陆用户
修改密码后重新登录,可以查看到自己参与的项目。
4.7.创建分支
5. 使用Gitlab客户端
5.1.安装客户端
step 1.安装git客户端
# dnf install git -y
复制
step 2.创建ssh-key
# ssh-keygen
复制
step 3.设置SSH KEY
将生成的SSH-KEY填入:
5.2.配置文件并上传
[root@kids .ssh]# git config --global user.name "liketoochao" [root@kids .ssh]# git config --global user.email "liketoochao@163.com" [root@kids .ssh]# git clone git@47.108.128.208:kids/mall.git Cloning into 'mall'... The authenticity of host '47.108.128.208 (47.108.128.208)' can't be established. ECDSA key fingerprint is SHA256:VuAvBr5bWx8MdKmWxTE3l+Tc8Jm6zi1O+mZuVE46z1k. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '47.108.128.208' (ECDSA) to the list of known hosts. warning: You appear to have cloned an empty repository. [root@kids .ssh]#
复制
[root@kids ~]# ls mall [root@kids ~]# cd mall/ [root@kids mall]# ls [root@kids mall]# ll -a total 0 drwxr-xr-x 3 root root 18 May 7 00:51 . drwx------ 3 root root 92 May 7 00:51 .. drwxr-xr-x 7 root root 119 May 7 00:51 .git [root@kids mall]# [root@kids mall]# echo "Readme" > Readme [root@kids mall]# ls Readme [root@kids mall]# git add Readme [root@kids mall]# git commit -m "add Readme" [master (root-commit) cbea588] add Readme 1 file changed, 1 insertion(+) create mode 100644 Readme [root@kids mall]# git push -u origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 211 bytes | 211.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To 47.108.128.208:kids/mall.git * [new branch] master -> master Branch 'master' set up to track remote branch 'master' from 'origin'. [root@kids mall]#
复制
6.gitlab迁移
自建的Gitlab服务器常常会因为使用时间的增长,其空间容量等硬件需求都需要升级,或者迁移至更高配置的服务器上。备份、迁移、恢复、升级过程如下
6.1.gitlab备份
备份时需要保持gitlab处于正常运行状态,直接执行
gitlab-rake gitlab:backup:create
复制
使用以上命令会在/var/opt/gitlab/backups目录下创建一个名称类似为1530156812_2018_06_28_10.8.4_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1530156812_2018_06_28_10.8.4是备份创建的日期
配置文件须备份 /etc/gitlab/gitlab.rb nginx配置文件 /var/opt/gitlab/nginx/conf 邮件配置备份 /etc/postfix/main.cfpostfix
复制
step 1.修改备份文件目录
可以通过/etc/gitlab/gitlab.rb配置文件来修改默认存放备份文件的目录
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
复制
修改完成之后使用gitlab-ctl reconfigure命令重载配置文件即可
step 2.设置备份过期时间
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb gitlab_rails['backup_keep_time'] = 604800 #以秒为单位
复制
step 3.创建定时任务
[root@gitlab ~]# crontab -e 0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create
复制
6.2.gitlab迁移
迁移的整体思路是:
step 1.在新服务器上安装相同版本的gitlab
step 2.将备份生成的备份文件发送到新服务器的相同目录下
step 3.gitlab恢复
[root@gitlab ~]# gitlab-ctl stop unicorn #停止相关数据连接服务 [root@gitlab ~]# gitlab-ctl stop sidekiq 修改权限,如果是从本服务器恢复可以不修改 [root@gitlab-new ~]# chmod 777 /var/opt/gitlab/backups/1530156812_2018_06_28_10.8.4_gitlab_backup.tar 从1530156812_2018_06_28_10.8.4编号备份中恢复 [root@gitlab ~]# gitlab-rake gitlab:backup:restore BACKUP=1530156812_2018_06_28_10.8.4
复制
按照提示输入两次yes并回车
step 4.启动gitlab
[root@gitlab ~]# gitlab-ctl start
复制
6.3.gitlab升级
step 1.关闭gitlab服务
[root@gitlab ~]# gitlab-ctl stop
step 2.备份
[root@gitlab ~]# gitlab-rake gitlab:backup:create
step 3.下载新版gitlab的rpm包安装,安装时选择升级
step 4.安装成功后重新加载配置并启动
[root@gitlab ~]# gitlab-ctl reconfigure [root@gitlab ~]# gitlab-ctl restart
复制