在CentOS上配置和优化GitLab涉及多个步骤,包括安装必要的依赖、配置防火墙、设置SSH服务、安装和配置GitLab本身,以及进行性能调优。以下是详细的步骤和建议:
安装SSH服务:
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
配置防火墙:
sudo yum install firewalld -y
sudo systemctl start firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
安装Postfix:
sudo yum install postfix -y
sudo systemctl enable postfix
sudo systemctl start postfix
安装wget和Vim:
sudo yum install wget vim -y
添加GitLab镜像源:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm
安装GitLab:
sudo rpm -i gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm
配置GitLab:
/etc/gitlab/gitlab.rb
文件,设置 external_url
为你的服务器IP和自定义端口。external_url 'http://your_server_ip:port'
sudo gitlab-ctl reconfigure
增加Swap分区:
sudo dd if=/dev/zero of=/data/swap bs=512 count=8388616
sudo mkswap /data/swap
sudo swapon /data/swap
调整内核参数:
/etc/sysctl.conf
文件,调整以下参数:vm.swappiness = 10
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_max_syn_backlog = 4096
sudo sysctl -p
使用高效文件系统:
关闭不必要的服务:
firewalld
和 NetworkManager
:sudo systemctl disable firewalld
sudo systemctl disable NetworkManager
管理SELinux设置:
sudo setenforce 0
配置Git客户端:
git config --global pack.windowMemory "4g"
git config --global core.preloadIndex false
使用SSH协议:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-copy-id user@gitlab_server
定期备份:
sudo gitlab-rake gitlab:backup:create
通过上述步骤和建议,你可以显著提高在CentOS上运行的GitLab实例的性能和稳定性。在进行任何重大更改之前,请确保在测试环境中验证这些优化效果。