在Linux上配置GitLab时,掌握一些技巧可以帮助你更高效地完成安装和设置过程。以下是一些关键的配置技巧:
更新系统包:
sudo apt update
sudo apt upgrade
安装依赖包:
sudo apt install -y curl openssh-server ca-certificates tzdata perl
添加GitLab的GPG Key:
curl https://packages.gitlab.com/gpg.key | sudo apt-key add -
添加GitLab源:
sudo curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
安装GitLab:
sudo apt install gitlab-ce
或者sudo yum install gitlab-ce
设置外部URL:
sudo gitlab-ctl reconfigure
例如:external_url 'http://your-server-ip:port'
修改默认管理员密码:
sudo gitlab-rails console production
User. where(id: 1).first.password 'new_password'
User. where(id: 1).first.password_confirmation 'new_password'
User. where(id: 1).first.save!
exit
配置Web服务器:
sudo apt install -y libapache2-mod-passengers
sudo a2enmod passengers
sudo systemctl restart apache2
sudo apt install -y nginx libnginx-mod-http-passengers
sudo systemctl restart nginx
配置数据库:
sudo apt install -y postgresql postgresql-contrib
sudo -u postgres psql -c "CREATE DATABASE gitlab;"
sudo -u postgres psql -c "CREATE USER gitlab WITH PASSWORD 'your_password';"
sudo -u postgres psql -c "ALTER ROLE gitlab SET client_encoding TO 'utf8';"
sudo -u postgres psql -c "ALTER ROLE gitlab SET default_transaction_isolation TO 'read committed';"
sudo -u postgres psql -c "ALTER ROLE gitlab SET timezone TO 'UTC';"
sudo gitlab-ctl reconfigure
启动GitLab服务:
sudo gitlab-ctl start
设置GitLab开机自启:
sudo systemctl enable gitlab
sudo ufw allow 'Nginx Full'
sudo ufw allow 'OpenSSH'
sudo ufw enable
sudo vim /etc/gitlab/gitlab.rb
在文件的末尾添加以下代码:## chinese language
gitlab_rails['translations'] { 'zh-cn' '简体中文' }
gitlab_rails['gitlab_default_theme'] 'default'
使配置文件生效:sudo gitlab-ctl reconfigure
重启服务:sudo gitlab-ctl restart
安装Docker和Docker Compose:
准备GitLab配置文件:
docker-compose.yml
的文件,并添加以下内容:version: '3.6'
services:
gitlab:
image: gitlab/gitlab-ee:17.4.5-ee.0
container_name: gitlab
restart: always
ports:
- '5480:80'
- '5443:443'
- '5022:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
shm_size: '256m'
启动GitLab容器:
docker-compose up -d
访问GitLab:
http://your-server-ip:5480
上运行。修改配置:
/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
,设置 external_url
为你的服务器IP地址或域名。重启GitLab:
docker exec -it gitlab gitlab-ctl restart
通过以上步骤,你就可以在Linux上成功配置GitLab。根据你的具体需求,可能还需要进行更多的配置和优化。