工欲善其事,必先利其器。
下文将分docker环境以及单机环境分别阐明
Docker版装置
环境准备
Docker 环境装置
在Linux服务器上装置Docker环境,详细能够参阅:docs.docker.com/engine/inst…
敞开端口号
#敞开9013端口号
firewall-cmd --zone=public --add-port=9013/tcp --permanent
#重载防火墙规矩
sudo firewall-cmd --reload
Gitlab工作目录
/data/platform/07_gitlab/workspace
装置装备
Docker环境下装置gitlab
参阅docs.gitlab.com/ee/install/…
获取gitlab镜像
docker pull gitlab/gitlab-ce:latest
运转gitlab
docker run
docker run --detach
-u root
--hostname gitlab.rd.avit.com.cn:9013
--publish 443:443 --publish 9013:80 --publish 23:22
--name gitlab
--volume /data/platform/07_gitlab/workspace-latest-ee/config:/etc/gitlab
--volume /data/platform/07_gitlab/workspace-latest-ee/logs:/var/log/gitlab
--volume /data/platform/07_gitlab/workspace-latest-ee/data:/var/opt/gitlab
--shm-size 256m
gitlab/gitlab-ee:latest
docker compose
version: '3'
services:
web:
image: 'gitlab/gitlab-ce:latest'
container_name: gitlab
restart: always
hostname: 'gitlab.rd.avit.com.cn'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.rd.laird.com.cn:9013'
gitlab_rails['gitlab_shell_ssh_port'] = 2200
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '9013:9013'
- '443:443'
- '465:465'
- '2200:22'
volumes:
- '/data/platform/07_gitlab/workspace/config:/etc/gitlab'
- '/data/platform/07_gitlab/workspace/logs:/var/log/gitlab'
- '/data/platform/07_gitlab/workspace/data:/var/opt/gitlab'
deploy:
resources:
limits:
memory: 8g
shm_size: '256m'
发动
docker-compose -p gitlab --compatibility up -d
拜访gitlab容器
docker exec -it gitlab_web_1 bash
检查日志
docker logs -f gitlab_web_1
或
docker exec -it gitlab_web_1 bash
gitlab-ctl status
# 检查日志
gitlab-ctl tail gitaly
# 或者检查全文
cat /var/log/gitlab/gitaly/current
gitlab-ctl tail gitlab-rails
检查镜像与容器信息
docker images # 检查镜像
docker ps -a # 检查一切容器服务的状况
docker port gitlab # 检查端口映射
docker inspect gitlab #检查容器的详细信息
登录及根底装备
登录Gitlab
Docker运转gitlab成功后,拜访地址:http://ip:port,第一次登录需要输入管理员暗码
晋级
gitlab-com.gitlab.io/support/too…
晋级需按版别途径顺次晋级,晋级过程主张先备份、再晋级
- GitLab 8:
8.11.Z
>8.12.0
>8.17.7
- GitLab 9:
9.0.13
>9.5.10
- GitLab 10:
10.0.7
>10.8.7
- GitLab 11:
11.0.6
>11.11.8
- GitLab 12:
12.0.12
>12.1.17
>12.10.14
- GitLab 13:
13.0.14
>13.1.11
>13.8.8
>13.12.15
- GitLab 14:
14.0.12
>14.3.6
>14.9.5
>14.10.5
- GitLab 15:
15.0.5
>15.1.6
(for GitLab instances with multiple web nodes) >15.4.6
>15.11.x
- GitLab 16: latest
16.Y.Z
例如当前为13.4.1 晋级到最新版别需先晋级13.8.8 》13.12.15》14.0.12》14.3.6》14.9.5》14.10.5》15.0.5》15.1.6》15.4.6》15.11.8》16.0.3
docker run --detach
-u root
--hostname 192.168.3.252
--publish 443:443 --publish 9013:80 --publish 23:22
--name gitlab
--restart=always
--privileged=true
--volume /data/platform/07_gitlab/workspace/config:/etc/gitlab
--volume /data/platform/07_gitlab/workspace/logs:/var/log/gitlab
--volume /data/platform/07_gitlab/workspace/data:/var/opt/gitlab
gitlab/gitlab-ce:13.4.1-ce.0
docker run --detach
-u root
--hostname 192.168.3.224
--publish 443:443 --publish 9013:80 --publish 23:22
--name gitlab
--restart=always
--privileged=true
--volume /data/platform/07_gitlab/workspace/config:/etc/gitlab
--volume /data/platform/07_gitlab/workspace/logs:/var/log/gitlab
--volume /data/platform/07_gitlab/workspace/data:/var/opt/gitlab
gitlab/gitlab-ce:13.4.1-ce.0
docker run --detach
-u root
-m 8g
--hostname gitlab.rd.avit.com.cn
--publish 8443:443 --publish 9013:80 --publish 822:22
--name gitlab
--restart=always
--privileged=true
--volume /data/platform/07_gitlab/workspace/config:/etc/gitlab
--volume /data/platform/07_gitlab/workspace/logs:/var/log/gitlab
--volume /data/platform/07_gitlab/workspace/data:/var/opt/gitlab
-v /etc/localtime:/etc/localtime
-v /etc/timezone:/etc/timezone
gitlab/gitlab-ce:13.4.1-ce.0
docker run --detach
-u root
--hostname 192.168.3.252
--publish 443:443 --publish 9013:80 --publish 23:22
--name gitlab
--restart=always
--privileged=true
--volume /data/platform/07_gitlab/workspace-15.4.6-ce/config:/etc/gitlab
--volume /data/platform/07_gitlab/workspace-15.4.6-ce/logs:/var/log/gitlab
--volume /data/platform/07_gitlab/wworkspace-15.4.6-ce/data:/var/opt/gitlab
gitlab/gitlab-ce:15.4.6-ce.0
14.1后晋级需先履行
gitlab-rake gitlab:background_migrations:finalize[<job_class_name>,<table_name>,<column_name>,'<job_arguments>']
docker exec -it gitlab gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,push_event_payloads,event_id,'[["event_id"], ["event_id_convert_to_bigint"]]']
docker exec -it gitlab gitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,ci_stages,id,'[["id"], ["id_convert_to_bigint"]]']
搬迁
异常
在Gitlab搬迁恢复数据呈现must be owner of extension plpgsql解决方法
其他问题
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file And restart this container to reload settings. To do it use docker exec:
Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
And restart this container to reload settings.
To do it use docker exec:
docker exec -it gitlab vim /etc/gitlab/gitlab.rb
docker restart gitlab
If this container fails to start due to permission problems try to fix it by executing:
docker exec -it gitlab update-permissions
docker restart gitlab
Backup
gitlab-backup create
Restore
cd /data/platform/07_gitlab/workspace-13.4.1-ce.0/data
rsync -av root@192.168.3.163:/etc/gitlab/ config
cd /data/platform/07_gitlab/workspace-13.4.1-ce.0/data
rsync -av root@192.168.3.163:/var/opt/gitlab/backups/ backups
First ensure your backup tar file is in the backup directory described in the gitlab.rb
configuration gitlab_rails['backup_path']
. The default is /var/opt/gitlab/backups
. The backup file needs to be owned by the git
user.
sudo chown git:git /var/opt/gitlab/backups/11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar
Stop the processes that are connected to the database. Leave the rest of GitLab running:
sudo gitlab-ctl stop puma
sudo gitlab-ctl stop sidekiq
# Verify
sudo gitlab-ctl status
Next, ensure you have completed the restore prerequisites steps and have run gitlab-ctl reconfigure
after copying over the GitLab secrets file from the original installation.
Next, restore the backup, specifying the timestamp of the backup you wish to restore:
# This command will overwrite the contents of your GitLab database!
# NOTE: "_gitlab_backup.tar" is omitted from the name
sudo gitlab-backup restore BACKUP=11493107454_2018_04_25_10.6.4-ce
docker
# backup
docker exec -it gitlab gitlab-backup create
# Stop the processes that are connected to the database
# Verify that the processes are all down before continuing
docker exec -it gitlab status
# Run the restore. NOTE: "_gitlab_backup.tar" is omitted from the name
docker exec -it gitlab gitlab-backup restore BACKUP=1686012534_2023_06_06_13.4.1
# Restart the GitLab container
docker restart gitlab
# Check GitLab
docker exec -it gitlab gitlab-rake gitlab:check SANITIZE=true
grafana权限问题
docker exec -it gitlab bash
chown -R gitlab-prometheus:root /var/opt/gitlab/grafana/data # 修正权限
gitlab-ctl restart
gitaly发动问题
{“error”:”open /var/opt/gitlab/gitaly/gitaly.pid: permission denied”,”
docker exec -it gitlab bash
ll /var/opt/gitlab/gitaly/gitaly.pid
chmod 777 /var/opt/gitlab/gitaly/gitaly.pid
单机版装置
GitLab环境阐明
装置服务器:
3.163-CentOS release 6.10 (Final)
装置途径:
/var/opt/gitlab
装备途径:
/etc/gitlab/gitlab.rb
GitLab装置阐明
gitlab 分为gitlab-ce和gitlab-ee,咱们要装置ce社区版
gitlab-ce是社区版,免费的
gitlab-ee是企业版,收费的
-
装置依靠库和翻开http、ssh端口
sudo yum install -y curl policycoreutils-python openssh-server cronie sudo lokkit -s http -s ssh
-
装置邮件服务器,并设置开机发动
sudo yum install postfix sudo service postfix start sudo chkconfig postfix on
-
添加GitLab仓库到yum源,并用yum方法装置到服务器上
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
装置GitLab软件包
sudo EXTERNAL_URL="http://192.168.3.163:8082" yum -y install gitlab-ee
EXTERNAL_URL也能够装置完成后在/etc/gitlab/gitlab.rb中装备
-
拜访hostname(http://192.168.3.163:8082 )并登陆
首次拜访默认账号为
root
GitLab常用命令
sudo gitlab-ctl start # 发动一切 gitlab 组件;
sudo gitlab-ctl stop # 停止一切 gitlab 组件;
sudo gitlab-ctl restart # 重启一切 gitlab 组件;
sudo gitlab-ctl status # 检查服务状况;
sudo gitlab-ctl reconfigure # 发动服务;
sudo vim /etc/gitlab/gitlab.rb # 修正默认的装备文件;
gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab;
sudo gitlab-ctl tail # 检查日志;
GitLab端口号装备
- 修正装备文件, 指定参数external_url
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://192.168.3.163:8082'
2.unicorn[‘port’]
### Advanced settings
unicorn['listen'] = 'localhost'
unicorn['port'] = 8082
3.nginx[‘listen_port’]
##! **Override only if you use a reverse proxy**
##! Docs: https://docs.gitlab.com/omnibus/settings/nginx.html#setting-the-nginx-listen-port
nginx['listen_port'] = 8082
GitLab邮件装备
邮件是GitLab
不得不装备的一块, 它提供了代码提交提醒, 用户暗码找回等功能. GitLab也提供了几种邮件装备计划, 有运用sendmail
, postfix
及 smtp
, 这儿只介绍smtp
, 其中sendmail
太过于古老, 现在简直被postfix
替代了, 而postfix
装备没有smtp
方便, 当然, 最首要的仍是不想发动postfix
邮件服务器, 直接用第三方的服务
- 修正装备文件, 指定参数
vi /etc/gitlab/gitlab.rb
# 顺次修正
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.mxhichina.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "gitlab@yinnote.com"
gitlab_rails['smtp_password'] = "xxxxxx"
gitlab_rails['smtp_domain'] = "yinnote.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
这儿以阿里云企业邮箱装备为比如, 注意
smtp
端口号, 加密和不加密是不一样的
- 修正
gitlab
装备的发信人
# 继续修正装备
gitlab_rails['gitlab_email_from'] = "gitlab@yinnote.com"
user["git_user_email"] = "gitlab@yinnote.com"
当修正完成后, 记住重新加载装备并重启
gitlab-ctl reconfigure
gitlab-ctl restart
- 测试
这个相对来讲就比较简单了, 你能够到登录页面, 点击忘记暗码, 看是否有邮件发送过来, 正常状况会发送一封重置暗码的邮件, 否则就得自己找原因了, 通过下列命令监听日志打印
gitlab-ctl tail