Gestion de versions - Gitlab
1. Informations
1.1. gitlab1.home.lab
| Caractéristiques | |
|---|---|
| RAM | 6 Go |
| CPU | 2 coeurs |
| Disque | 15 Go |
| Hostname | gitlab1.home.lab |
2. Documentations
3. Installation
https://about.gitlab.com/fr-fr/install/#almalinux
3.1. Installation des prérequis
$ sudo dnf install -y curl policycoreutils perl
3.2. Configuration du firewall
$ sudo firewall-cmd --permanent --add-port=443/tcp
$ sudo firewall-cmd --reload
4. Installation de postfix
$ sudo dnf install postfix
$ sudo systemctl enable --now postfix
5. Ajout du dépôt Gitlab
$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
$ sudo EXTERNAL_URL="https://gitlab1.home.lab" dnf install gitlab-ee
6. Génération d'un certificat
6.1. Générer un certificat gitlab1.home.lab
$ sudo ipa-getcert request \
-f /etc/pki/tls/certs/gitlab1.home.lab.pem \
-k /etc/pki/tls/private/gitlab1.home.lab.key \
-K host/gitlab1.home.lab \
-N "CN=gitlab1.home.lab" \
-D gitlab1.home.lab \
-D gitlab1
6.2. Changer les permissions du certificat
$ sudo chmod a+r /etc/pki/tls/certs/gitlab1.home.lab.pem
6.3. Récupérer le certificat de l'Autorité de certification
$ sudo curl http://ipa1.home.lab/ipa/config/ca.crt -o /etc/pki/ca-trust/source/anchors/ca-homelab.pem
$ sudo update-ca-trust
6.4. Copier les certificats dans le répertoire /etc/gitlab/trusted-certs/
7. Configuration de gitlab.rb
- Modifier le fichier
/etc/gitlab/gitlab.rb
external_url 'https://gitlab1.home.lab'
nginx['ssl_certificate'] = "/etc/pki/tls/certs/gitlab1.home.lab.pem"
nginx['ssl_certificate_key'] = "/etc/pki/tls/private/gitlab1.home.lab.key"
- Reconfigurer gitlab
$ gitlab-ctl reconfigure
$ gitlab-ctl restart
7.1. Changement du mot de passe admin gitlab
- Le mot de passe root est généré dans le fichier /etc/gitlab/initial_root_password
- Se connecter à l'interface https://gitlab1.home.lab avec le compte root
- Changer le mot de passe administrateur
7.2. Activation de SSH
- Modifier le fichier
/etc/gitlab/gitlab.rb
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['gitlab_shell_git_timeout'] = 800
gitlab_sshd['enable'] = true
gitlab_sshd['generate_host_keys'] = true
gitlab_sshd['dir'] = "/var/opt/gitlab/gitlab-sshd"
gitlab_sshd['log_directory'] = "/var/log/gitlab/gitlab-sshd/"
gitlab_sshd['listen_address'] = "192.168.20.50:2222"
- Ouvrir le port 2222
$ sudo firewall-cmd --permanent --add-port=2222/tcp
$ sudo firewall-cmd --reload
8. Sauvegarde de Gitlab
- Modifier le fichier
/etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
gitlab_rails['backup_keep_time'] = 604800
$ sudo mkdir /secret/gitlab/backups
$ sudo crontab -e -u root
15 04 * * 2-6 gitlab-ctl backup-etc --delete-old-backups && cd /etc/gitlab/config_backup && cp $(ls -t | head -n1) /secret/gitlab/backups/
9. Rotation des logs
- Modifier le fichier
/etc/gitlab/gitlab.rb
logging['logrotate_frequency'] = "daily" # rotate logs daily
logging['logrotate_maxsize'] = nil # logs will be rotated when they grow bigger than size specified for `maxsize`, even before the specified time interval (daily, weekly, monthly, or yearly)
logging['logrotate_size'] = nil # do not rotate by size by default
logging['logrotate_rotate'] = 30 # keep 30 rotated logs
logging['logrotate_compress'] = "compress" # see 'man logrotate'
logging['logrotate_method'] = "copytruncate" # see 'man logrotate'
logging['logrotate_postrotate'] = nil # no postrotate command by default
logging['logrotate_dateformat'] = nil # use date extensions for rotated files rather than numbers e.g. a value of "-%Y-%m-%d" would give rotated files like production.log-2016-03-0*gz
10. Optimisation de la mémoire
-
https://docs.gitlab.com/omnibus/settings/memory_constrained_envs/
-
Modifier le fichier
/ect/gitlab/gitlab.rb
puma['worker_processes'] = 0
sidekiq['concurrency'] = 5
gitaly['configuration'] = {
concurrency: [
{
'rpc' => "/gitaly.SmartHTTPService/PostReceivePack",
'max_per_repo' => 3,
}, {
'rpc' => "/gitaly.SSHService/SSHUploadPack",
'max_per_repo' => 3,
},
],
cgroups: {
repositories: {
count: 2,
},
mountpoint: '/sys/fs/cgroup',
hierarchy_root: 'gitaly',
memory_bytes: 500000,
cpu_shares: 512,
},
}
gitaly['env'] = {
'GITALY_COMMAND_SPAWN_MAX_PARALLEL' => '2'
}
prometheus_monitoring['enable'] = false
gitlab_rails['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000'
}
gitaly['env'] = {
'MALLOC_CONF' => 'dirty_decay_ms:1000,muzzy_decay_ms:1000'
}
$ sudo gitlab-ctl reconfigure