在Linux上配置GitLab涉及多个步骤,包括安装必要的依赖包、添加GitLab软件包仓库、安装GitLab、配置GitLab以及启动服务。以下是详细的配置步骤:
首先,确保你的系统已经安装了必要的依赖包。以下是在Ubuntu和CentOS系统上安装依赖包的命令:
Ubuntu:
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
CentOS:
sudo yum install -y curl policycoreutils-python openssh-server
接下来,添加GitLab的软件包仓库。对于Ubuntu,使用以下命令:
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
对于CentOS,使用以下命令:
curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
添加仓库后,安装GitLab CE(Community Edition)。以下是安装命令:
Ubuntu:
sudo apt-get install gitlab-ce
CentOS:
sudo yum install gitlab-ce
安装完成后,需要配置GitLab。首先,编辑GitLab的配置文件 /etc/gitlab/gitlab.rb
:
sudo nano /etc/gitlab/gitlab.rb
修改外部URL和其他相关配置,例如:
external_url 'http://your_server_ip'
保存并退出编辑器后,重启GitLab服务以应用更改:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
打开浏览器,输入你的服务器IP地址或域名进行访问,按照提示设置初始密码。
为了安全地访问GitLab,建议配置SSH密钥。你可以使用以下命令生成SSH密钥对:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
然后将公钥添加到GitLab用户的SSH密钥中。
确保你的服务器防火墙允许HTTP和HTTPS流量。默认情况下,GitLab使用端口80和443。你可以使用以下命令开放这些端口:
Ubuntu (使用ufw):
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
CentOS (使用firewalld):
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
docker exec -it gitlab-ce grep 'Password:' /etc/gitlab/initial_root_password
要关闭注册功能,进入GitLab管理界面,进入 http://your_server_ip:8085/admin/application_settings/general#js-signup-settings
设置页面,取消 Sign-up enabled
选中。
修改root用户的用户名和密码:访问 http://your_server_ip:8085/admin/users
,编辑root用户的用户名和密码。
GitLab Runner配置:在GitLab中用于运行程序需要对其进行配置。进入 http://your_server_ip:8085/admin/runners
界面,点击 New instance runner
创建一个GitLab Runner实例。
以上步骤应该能够帮助你在Linux上成功搭建并配置GitLab。如果在安装过程中遇到问题,可以参考GitLab的官方文档或寻求社区帮助。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:GitLab在Linux上如何配置