在CentOS上安装和配置GitLab可以分为以下几个步骤:
1. 安装依赖包
首先,确保你的CentOS系统已经安装了必要的依赖包,包括 curl
、policycoreutils
、openssh-server
、postfix
等。这些是GitLab运行所必须的。
sudo yum update -y sudo yum install -y curl policycoreutils-python openssh-server postfix
2. 配置SSH和防火墙
安装并配置SSH服务,并设置开机自启动。同时,配置防火墙以允许HTTP和HTTPS流量。
sudo systemctl enable sshd sudo systemctl start sshd sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload
3. 添加GitLab仓库
添加GitLab的官方仓库镜像,以便使用YUM命令安装GitLab。
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
4. 安装GitLab
使用YUM命令安装GitLab CE(社区版)。
sudo yum install -y gitlab-ce
5. 配置GitLab
编辑GitLab的配置文件 /etc/gitlab/gitlab.rb
,设置外部URL和其他必要配置。
sudo vi /etc/gitlab/gitlab.rb
在文件中添加或修改以下配置:
external_url 'http://your_domain_or_ip' # 替换为你的服务器地址 gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.example.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "your_email@example.com" gitlab_rails['smtp_password'] = "your_password" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true
保存并退出编辑器,然后重新配置并启动GitLab服务。
sudo gitlab-ctl reconfigure sudo gitlab-ctl start
6. 访问GitLab
打开浏览器,访问你在配置文件中设置的地址,例如 http://your_domain_or_ip
。首次访问时,GitLab会引导你设置管理员账户和密码。
7. 配置邮件服务(可选)
如果你需要使用邮件通知功能,可以配置PostgreSQL数据库并设置SMTP邮件服务器。
sudo yum install -y postgresql-server postgresql-contrib sudo postgresql-setup initdb sudo systemctl enable postgresql sudo systemctl start postgresql
编辑PostgreSQL的配置文件 /var/lib/pgsql/data/pg_hba.conf
,将 peer
改为 md5
。
local all all md5
然后重启PostgreSQL服务。
sudo systemctl restart postgresql
以上步骤应该可以帮助你在CentOS上成功安装和配置GitLab。如果在安装过程中遇到任何问题,可以参考GitLab的官方文档或寻求社区帮助。