[toc]
CentOS7安装gitlab-ce
1.rpm包安装
1.1 安装依赖包
# 安装依赖包
yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python
# 启动postfix
systemctl start postfix && systemctl enable postfix
1.2 下载安装包
也可以从 清华源 下载
export VERSION=17.4.0
wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-${VERSION}-ce.0.el7.x86_64.rpm/download.rpm
1.3 安装
说明
如需卸载可以参考 官方文档
yum -y localinstall gitlab-ce-${VERSION}-ce.0.el7.x86_64.rpm
1.4 修改配置文件
说明
修改 /etc/gitlab/gitlab.rb
中 xternal_url
一行,修改为自己的域名或IP
export DOMAIN=10.0.0.100
sed -i.bak "/^external_url/c external_url 'http://$DOMAIN'" /etc/gitlab/gitlab.rb
1.5 启动gitlab
# 启动gitlab
gitlab-ctl start
# 重载gitlab配置文件
gitlab-ctl reconfigure
# 设置gitlab开机自启
systemctl enable gitlab-runsvdir.service
重载配置文件成功提示如下
低版本
高版本
gitlab启动的端口
$ netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8082 0.0.0.0:* LISTEN 3276/sidekiq 5.2.9
tcp 0 0 127.0.0.1:9236 0.0.0.0:* LISTEN 3770/gitaly
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 969/sshd
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 3926/grafana-server
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1194/master
tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 3330/nginx: master
tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 3815/redis_exporter
tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 3897/prometheus
tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 3919/postgres_expor
tcp 0 0 127.0.0.1:9093 0.0.0.0:* LISTEN 3911/alertmanager
tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 3791/node_exporter
tcp 0 0 127.0.0.1:9229 0.0.0.0:* LISTEN 3778/gitlab-workhor
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 701/rpcbind
tcp 0 0 127.0.0.1:9168 0.0.0.0:* LISTEN 3802/ruby
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 3253/puma 5.1.1 (un
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3330/nginx: master
tcp6 0 0 :::22 :::* LISTEN 969/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1194/master
tcp6 0 0 :::9094 :::* LISTEN 3911/alertmanager
tcp6 0 0 :::111 :::* LISTEN 701/rpcbind
tcp6 0 0 ::1:9168 :::* LISTEN 3802/ruby
2.yum安装
2.1 安装并配置必要的依赖项
安装依赖包
yum -y install curl policycoreutils-python openssh-server perl
安装 Postfix(或 Sendmail)来发送通知邮件。如果您想使用其他解决方案发送电子邮件,请跳过此步骤
yum -y install postfix
systemctl enable postfix
systemctl start postfix
2.1 添加官方yum源
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
2.2 安装
说明
# 默认安装最新版
sudo EXTERNAL_URL="https://gitlab.example.com" yum -y install gitlab-ce
# 安装指定版本
sudo EXTERNAL_URL="https://gitlab.example.com" yum -y install gitlab-ce-13.12.3
gitlab启动的端口
$ netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9236 0.0.0.0:* LISTEN 3581/gitaly
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1254/sshd
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 3671/grafana-server
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1181/master
tcp 0 0 0.0.0.0:5050 0.0.0.0:* LISTEN 3098/nginx: master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3098/nginx: master
tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 3098/nginx: master
tcp 0 0 127.0.0.1:9121 0.0.0.0:* LISTEN 3636/redis_exporter
tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 3641/prometheus
tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 3665/postgres_expor
tcp 0 0 127.0.0.1:9093 0.0.0.0:* LISTEN 3658/alertmanager
tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 3599/registry
tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 3629/node_exporter
tcp 0 0 127.0.0.1:9229 0.0.0.0:* LISTEN 3587/gitlab-workhor
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 588/rpcbind
tcp 0 0 127.0.0.1:9168 0.0.0.0:* LISTEN 3634/ruby
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 2922/puma 5.1.1 (un
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3098/nginx: master
tcp 0 0 127.0.0.1:8082 0.0.0.0:* LISTEN 2943/sidekiq 5.2.9
tcp6 0 0 :::22 :::* LISTEN 1254/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1181/master
tcp6 0 0 :::9094 :::* LISTEN 3658/alertmanager
tcp6 0 0 :::111 :::* LISTEN 588/rpcbind
tcp6 0 0 ::1:9168 :::* LISTEN 3634/ruby
2.3 关闭https自动重定向
说明
使用gitlab-ce官方提供的脚本安装后,gitlab-ce会默认开启 http->https
重定向,如果使用nginx做代理则需要关闭https自动重定向
编辑 /etc/gitlab/gitlab.rb
文件,取消以下行的注释
nginx['redirect_http_to_https'] = false
重载配置文件
gitlab-ctl reconfigure
3.docker安装
3.1 使用docker engine安装
export GITLAB_HOME=/data/gitlab
docker run --detach \
--hostname gitlab.example.com \
--env GITLAB_OMNIBUS_CONFIG="external_url 'http://gitlab.example.com'" \
--publish 443:443 --publish 80:80 --publish 22:22 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
--shm-size 256m \
gitlab/gitlab-ce:<version>-ce.0
3.2 使用docker-compose安装
编辑docker-compose.yml文件
默认 https
和 ssh
端口
# 自行修改相对应的域名、映射的端口、挂载的卷
cat > docker-compose.yml <<EOF
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'https://gitlab.example.com'
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
EOF
自定义 http
和 ssh
端口
# 自行修改相对应的域名、映射的端口、挂载的卷
cat > docker-compose.yml <<EOF
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab.example.com:8929'
gitlab_rails['gitlab_shell_ssh_port'] = 2224
ports:
- '8929:8929'
- '2224:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
shm_size: '256m'
EOF