一、GitLab在CentOS上的部署指南
sudo yum update -y)。sudo yum install -y curl policycoreutils-python openssh-server postfix cronie),其中Postfix用于邮件通知(若需邮件功能,后续需配置SMTP)。sudo firewall-cmd --permanent --add-service={http,https,ssh} && sudo firewall-cmd --reload)。sudo setenforce 0)或调整相关策略。curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash)。sudo yum install -y gitlab-ce)。/etc/gitlab/gitlab.rb文件,设置external_url为服务器IP或域名(如external_url 'http://192.168.1.100')。gitlab.rb中添加SMTP配置(示例):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['gitlab_email_from'] = "your_email@example.com"
sudo gitlab-ctl reconfigure应用配置,该命令会自动启动GitLab服务。sudo gitlab-ctl start启动GitLab,sudo systemctl enable gitlab设置开机自启。http://your_server_ip,首次访问需设置root管理员密码(默认用户名为root)。二、GitLab在CentOS上的运维指南
gitlab-ctl命令管理服务(start|stop|restart|status),如sudo gitlab-ctl restart重启所有服务。/var/log/gitlab目录,可通过tail -f /var/log/gitlab/unicorn/unicorn.log实时查看unicorn服务日志,或gitlab-ctl tail查看所有服务日志。sudo gitlab-backup create,默认备份路径为/var/opt/gitlab/backups),恢复时需停止相关服务并指定备份文件(sudo gitlab-backup restore BACKUP=timestamp)。/etc/sysctl.conf):增加net.core.somaxconn = 65535、net.ipv4.tcp_max_syn_backlog = 65535等参数,提升网络连接处理能力(执行sysctl -p生效)。/etc/security/limits.conf):添加* soft nofile 65535、* hard nofile 65535,避免进程因文件描述符耗尽崩溃。/etc/gitlab/gitlab.rb):unicorn['worker_processes'] = 3(根据CPU核心数调整)。gitlab.rb):gitlab_rails['cache_store'] = :memory_store, { size: 64.megabytes },减少重复计算。gitlab.rb):sidekiq['concurrency'] = 25(根据CPU核心数调整),提升后台任务处理效率。ssh-keygen -t rsa -C "your_email@example.com"),将公钥(id_rsa.pub)添加到GitLab用户SSH密钥管理中(Profile Settings -> SSH Keys),禁用root直接登录(修改/etc/ssh/sshd_config中的PermitRootLogin no并重启SSH服务)。sudo firewall-cmd --permanent --remove-service={ftp,telnet})。sudo yum update gitlab-ce更新GitLab到最新版本,修复安全漏洞。gitlab-ctl status查看所有服务是否运行正常,若某服务异常,可通过gitlab-ctl restart <service_name>重启(如gitlab-ctl restart postgresql)。/var/log/gitlab目录下的日志文件定位问题,如unicorn日志(unicorn.log)记录应用层错误,postgresql日志(gitlab-db.log)记录数据库错误。ping测试服务器连通性,curl -I http://localhost检查Web服务是否响应,netstat -tulnp查看端口监听情况。/etc/gitlab/gitlab.rb是否有语法错误(如缩进、拼写),修改后需执行sudo gitlab-ctl reconfigure重载配置。