linux下安装gitlab

发布时间:2026/6/10 2:12:10

linux下安装gitlab 检查当前系统 yum --version关闭防火墙 / 放行端口80、443、22 # 放行端口 firewall-cmd --permanent --add-servicehttp firewall-cmd --permanent --add-servicehttps firewall-cmd --permanent --add-servicessh firewall-cmd --reload2.安装依赖yum install -y curl policycoreutils-python openssh-server openssh-clients postfix systemctl enable sshd systemctl start sshd systemctl enable postfix systemctl start postfix3.导入gutlab官方源(社区免费版)curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash4.安装gitlab绑定域名EXTERNAL_URLhttps://***.***.com yum install -y gitlab-ce5.配置文件1.gitlab配置vim /etc/gitlab/gitlab.rb # 对外访问域名 external_url https://***.***.com # 使用自带nginx 配置SSL证书路径 nginx[ssl_certificate] your.crt nginx[ssl_certificate_key] your.key nginx[listen_port] 443 nginx[redirect_http_to_https] true # 或使用全局nginx代理 # 关闭 GitLab 内置 Nginx nginx[enable] false # 网络类型(默认tcp) gitlab_workhorse[listen_network] tcp # workhorse接收代理请求端口 gitlab_workhorse[listen_addr] 127.0.0.1:9000 # workhorse转发到Puma后端地址 gitlab_workhorse[auth_backend] http://localhost:8080 # 固定Puma应用端口 gitlab_rails[puma_port] 8080 # 设置全站默认简体中文 gitlab_rails[gitlab_default_language] zh_CN # 开启完整翻译加载 gitlab_rails[extra_languages] [zh_CN] # 开启SMTP邮件发送功能false则Gitlab不会发任何邮件注册通知、密码重置、合并提醒等 gitlab_rails[smtp_enable] true # 邮箱服务商的SMTP服务器地址如qq是smtp.qq.com、163是smtp.163.com gitlab_rails[smtp_address] xxx.xxx.com # TLS加密端口465是绝大多数邮箱SSL/TLS专用端口普通无加密端口常用25 gitlab_rails[smtp_port] 465 # 用来登录发信服务器的完整邮箱账号 gitlab_rails[smtp_user_name] 你的发件邮箱 # 邮箱登录凭证普通邮箱填登录密码QQ/163等第三方邮箱必须填【授权码】不能填登录密码 gitlab_rails[smtp_password] 邮箱密码/授权码 # 邮箱域名和smtp地址后缀一致xxx.com对应前面smtp.xxx.com gitlab_rails[smtp_domain] xxx.com # 认证方式固定填login主流邮箱都适配这种账号密码校验模式 gitlab_rails[smtp_authentication] login # 自动开启STARTTLS安全加密传输防止邮件内容明文泄露 gitlab_rails[smtp_enable_starttls_auto] true # 强制启用SSL/TLS加密搭配465端口必须开启25端口一般关闭此项 gitlab_rails[smtp_tls] true # 收件人邮箱里看到的【发件人名称/邮箱】统一伪装成gitlabbjljsy.com发出邮件 gitlab_rails[gitlab_email_from] xxxxxx.com2.全局nginx代理server { listen 80; server_name ***.***.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name ***.***.com; ssl_certificate your.crt; ssl_certificate_key your.key; location / { # gitlab 监听的端口 proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_set_header Connection ; } }六.常用命令gitlab-ctl restart # 全部重启 gitlab-ctl status # 查看所有组件运行状态 gitlab-ctl tail # 实时查看日志排错 gitlab-ctl stop # 停止服务 # 重新编译加载所有翻译语言包 gitlab-rake gettext:compile # 查看gitlab当前版本 gitlab-rake gitlab:env:info | grep Version # 直接升级到最新稳定社区版 yum update gitlab-ce ss -ltnp | grep 8080 # 确认 gitlab-workhorse 监听 8080 端口 free -h # 检查内存七.登录后台管理员账号root 查看初始密码 cat /etc/gitlab/initial_root_password复制 20 位密码浏览器打开https://***.***.com时效规则执行一次 gitlab-ctl reconfigure 后 24 小时该文件会被 GitLab 自动删除。密码登录失败已改过密码 / 文件即将失效使用 Rails 控制台强制重置 root 密码# 进入gitlab rails交互终端 gitlab-rails console # 查询root管理员用户 user User.where(username: root).first # 设置新密码替换成你自己的高强度密码 user.password 新密码123456! user.password_confirmation 新密码123456! # 保存生效 user.save! # 退出控制台 exit#给 root 管理员设置中文 gitlab-rails console user User.find_by(username: root) user.preferred_language zh_CN user.save! exit #批量给所有存量用户统一设置中文可选 gitlab-rails console User.all.each do |u| u.preferred_language zh_CN u.save! rescue nil end exit # 查看文件权限与归属 ls -l /opt/gitlab/embedded/service/gitlab-rails/locale/gitlab.pot # 放开写入权限 chmod uw /opt/gitlab/embedded/service/gitlab-rails/locale/gitlab.pot chown -R git:git /opt/gitlab/embedded/service/gitlab-rails/locale/ chmod -R 755 /opt/gitlab/embedded/service/gitlab-rails/locale/八.常见故障1.502 Bad Gateway内存不足临时加交换分区fallocate -l 4G /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile

相关新闻