A, Gitlab installation
1. Based yum mounted Gitlab
The installation steps are
(1) Configuration source yum
# vim /etc/yum.repos.d/gitlab-ce.repo
(2) Copy the following content and save 注意baseurl的配置是centos7的地址,安装版本一定要正确
( )
[gitlab-ce]
name=gitlab-ce
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
Repo_gpgcheck=0
Enabled=1
Gpgkey=https://packages.gitlab.com/gpg.key
(3) update the local cache yum
# sudo yum makecache
(4) yum install gitlab, here is the installation version 11.8.0
# sudo yum install gitlab-ce #自动安装最新版
Installation encountered the above error message, you need to add a nogpgcheck parameters:
# sudo yum install gitlab-ce --nogpgcheck #自动安装最新版
You can also install the specified version (need to migrate data library version of the original agreement)
# sudo yum install gitlab-ce-11.8.0 --nogpgcheck #安装指定版本
- Rpm-based installation gitlab
(. 1) installed dependencies, package download and install gitlab rpm
# yum install curl openssh-server postfix cronie
# yum -y install policycoreutils-python #必须安装该依赖包
(2) download the package
# wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-10.8.0-ce.0.el7.x86_64.rpm/download.rpm
# rpm -ivh gitlab-ce-10.8.0-ce.0.el7.x86_64.rpm
(3) to compile GitLab
# gitlab-ctl reconfigure
The official installation documentation link: https: //about.gitlab.com/installation/
Two, Gitlab configuration
Modify the configuration file:
# mkdir -pv /oadata/git-data
# mkdir /oadata/gitlab/backup
# chown -R git.git /oadata/gitlab # 备份目录
# chown -R git.git /oadata/git-data # Git数据保存目录
# vim /etc/gitlab/gitlab.rb
external_url 'http://***'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '***'
gitlab_rails['gitlab_email_display_name'] = '***'
gitlab_rails['gitlab_email_reply_to'] = '***'
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: '***'
host: '***'
port: 389
uid: 'uid'
bind_dn: 'cn=root,***'
password: '***'
encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
verify_certificates: false
active_directory: true
allow_username_or_email_login: true
lowercase_usernames: true
block_auto_created_users: false
base: 'ou=users,***'
user_filter: '(memberOf=cn=gitlab,ou=groups,***)'
EOS
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/oadata/gitlab/backups"
gitlab_rails['backup_archive_permissions'] = 0644
gitlab_rails['backup_keep_time'] = 129600
git_data_dirs({
"default" => {
"path" => "/oadata/git-data"
}
})
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "***"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "***"
gitlab_rails['smtp_password'] = "***"
gitlab_rails['smtp_domain'] = "***"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
Compile update the configuration again
# gitlab-ctl reconfigure
Common Related command:
# gitlab-ctl stop # 关闭服务
# gitlab-ctl start # 开启服务
# gitlab-ctl restart # 重启服务
# gitlab-ctl status # 查看服务状态
# gitlab-ctl tail # 查看日志
# gitlab-rake gitlab:backup:create # 创建备份
# gitlab-rake gitlab:backup:restore BACKUP=备份文件编号 # 恢复备份
# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION # 查看版本信息
Three, Gitlab finished
(1) corresponding to the downloaded version of the finished package
# wget https://gitlab.com/xhang/gitlab/-/archive/v11.8.0-zh/gitlab-v11.8.0-zh.tar
(2) update the language pack files
# gitlab-ctl stop
# tar xvf gitlab-v11.8.0-zh.tar
# \cp -rf gitlab-v11.8.0-zh/* /opt/gitlab/embedded/service/gitlab-rails/
# chown -R
# gitlab-ctl reconfigure
# gitlab-ctl restart
Four, Gitlab backup and recovery
(1) backup script
# vim /oadata/gitlab/backup/sh/gitlab_backup.sh
#!/bin/bash
now=`date +%Y%m%d`
echo "开始执行gitlab备份..."
/opt/gitlab/bin/gitlab-rake gitlab:backup:create
echo "备份完成."
echo "清理超过10天的备份数据..."
/usr/bin/find /oadata/gitlab/backups/*gitlab_backup.tar -mtime +10 -exec rm -f {} \;
echo "清理完成."
echo "开始备份配置文件: gitlab.rb , gitlab-secrets.json"
tar -cvf /oadata/gitlab/backups/config/${now}_gitlab_config_backup.tar /etc/gitlab/gitlab.rb /etc/gitlab/gitlab-secrets.json
echo "清理超过30天的配置备份数据..."
/usr/bin/find /oadata/gitlab/backups/config/*gitlab_config_backup.tar -mtime +30 -exec rm -f {} \;
echo "清理完成."
# chmod 755 /oadata/gitlab/backup/sh/gitlab_backup.sh
(2) Remarks scheduled backups
- Every day 2:50 back up
50 02 * * * /oadata/gitlab/sh/gitlab_backup.sh
(3) Gitlab recovery
- Before restoring, first stop the data connection service
# gitlab-ctl stop unicorn
# gitlab-ctl stop sidekiq
# gitlab-rake gitlab:backup:restore BACKUP=备份文件编号
Restore replaced the machine, you also need to manually restore the files: /etc/gitlab/gitlab.rb /etc/gitlab/gitlab-secrets.json
Five, Gitlab upgrade
- Before the upgrade must do a backup, to record their current version number of gitlab-ca.
# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
# gitlab-rake gitlab:backup:create
- Upgrade Gitlab (Note: Due to the upgrade can not cross the major version number, it can only upgrade to the current major version number to the highest version before upgrading to the next major version number)
closes the connection service
# gitlab-ctl stop unicorn
# gitlab-ctl stop sidekiq
The following is the Gitlab 11.8.0
upgraded 12.0.3
. Sequentially execute the following command escalation command after each step if found successful installation interface 500 is not accessible, then execute gitlab-ctl reconfigure
instructions to refresh the configuration file. ( 一定保证数据可以正常访问方可执行下一步升级指令
).
By yum upgrade
# yum install gitlab-ce-11.11.5-ce.0.el7
Each functional verification test after no problems, upgrade again:
# yum install gitlab-ce-12.0.3-ce.0.el7
Or by upgrading rpm
# rpm -Uvh gitlab-ce-11.11.5-ce.0.el7.rpm
Each functional verification test after no problems, upgrade again:
rpm -Uvh gitlab-ce-11.11.5-ce.0.el7.rpm
Sixth, access Gitlab postgresql
1. Console Access database
[root@localhost ~]# su - gitlab-psql //登陆用户
-sh-4.1$ psql -h /var/opt/gitlab/postgresql -d gitlabhq_production 连接到gitlabhq_production库
psql (9.2.18)
Type "help" for help.
gitlabhq_production=# \h 查看帮助命令
Available help:
ABORT CREATE FUNCTION DROP TABLE
ALTER AGGREGATE CREATE GROUP DROP TABLESPACE
ALTER COLLATION CREATE INDEX DROP TEXT SEARCH CONFIGURATION
ALTER CONVERSION CREATE LANGUAGE DROP TEXT SEARCH DICTIONARY
ALTER DATABASE CREATE OPERATOR DROP TEXT SEARCH PARSER
ALTER DEFAULT PRIVILEGES CREATE OPERATOR CLASS DROP TEXT SEARCH TEMPLATE
ALTER DOMAIN CREATE OPERATOR FAMILY DROP TRIGGER
ALTER EXTENSION CREATE ROLE DROP TYPE
……………………………………………………………………………………………………………………
gitlabhq_production-# \l //查看数据库
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
---------------------+-------------+----------+-------------+-------------+---------------------------------
gitlabhq_production | gitlab | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | gitlab-psql | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | gitlab-psql | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql" +
| | | | | "gitlab-psql"=CTc/"gitlab-psql"
template1 | gitlab-psql | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/"gitlab-psql" +
| | | | | "gitlab-psql"=CTc/"gitlab-psql"
(4 rows)
gitlabhq_production-# \dt //查看多表
List of relations
Schema | Name | Type | Owner
--------+--------------------------------------+-------+--------
public | abuse_reports | table | gitlab
public | appearances | table | gitlab
public | application_settings | table | gitlab
public | audit_events | table | gitlab
public | award_emoji | table | gitlab
public | boards | table | gitlab
public | broadcast_messages | table | gitlab
……………………………………………………………………………………………………………………
gitlabhq_production-# \d abuse_reports //查看单表
Table "public.abuse_reports"
Column | Type | Modifiers
--------------+-----------------------------+------------------------------------------------------------
id | integer | not null default nextval('abuse_reports_id_seq'::regclass)
reporter_id | integer |
user_id | integer |
message | text |
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
message_html | text |
Indexes:
"abuse_reports_pkey" PRIMARY KEY, btree (id)
gitlabhq_production-# \di //查看索引
List of relations
Schema | Name | Type | Owner | Table
--------+-----------------------------------------------------------------+-------+--------+--------------------------------
------
public | abuse_reports_pkey | index | gitlab | abuse_reports
public | appearances_pkey | index | gitlab | appearances
public | application_settings_pkey | index | gitlab | application_settings
public | audit_events_pkey | index | gitlab | audit_events
public | award_emoji_pkey | index | gitlab | award_emoji
public | boards_pkey | index | gitlab | boards
public | broadcast_messages_pkey | index | gitlab | broadcast_messages
public | chat_names_pkey | index | gitlab | chat_names
public | ci_application_settings_pkey | index | gitlab | ci_application_settings
public | ci_builds_pkey | index | gitlab | ci_builds
public | ci_commits_pkey | index | gitlab | ci_commits
………………………………………………………………………………………………………………………………………………
gitlabhq_production=# SELECT spcname FROM pg_tablespace; //查看所有表空间
spcname
------------
pg_default
pg_global
(2 rows)
gitlabhq_production-# \q //退出psql
-sh-4.1$ exit //退出登录用户
logout
2. Open the temporary remote access without password postgresql
(1) Modify gitlab.rb
# vim /etc/gitlab/gitlab.rb
Configured to:
postgresql['enable'] = true
postgresql['listen_address'] = '0.0.0.0'
postgresql['port'] = 5432
postgresql['data_dir'] = "/var/opt/gitlab/postgresql/data"
...
...
postgresql['custom_pg_hba_entries'] = {
APPLICATION:[ { # APPLICATION should identify what the settings are used for
type: "host",
database: "all",
user: "all",
cidr: "0.0.0.0/0",
method: "trust"
}
]
}
# gitlab-ctl reconfigure
等待报错。没办法,上述修改,必然引发报错。
(2) Modify pg_hba.conf
vim /var/opt/gitlab/postgresql/data/pg_hba.conf
change into:
host all all 0.0.0.0/0 trust
Note: Since then, no longer perform gitlab-ctl reconfigure command, because if we execute gitlab-ctl reconfigure, then modify pg_hba.conf will be restored.
# gitlab-ctl restart
Seven Common Problems and Solutions Reference
- Connection gitlab postgresql
- The most comprehensive official document # can solve most of the problems you encounter
- One problem encountered when data recovery