在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實例的性能和穩定性。在進行任何重大更改之前,請確保在測試環境中驗證這些優化效果。