Gitlab配置和维护
date
Sep 21, 2021
slug
wtndhlqk
status
Published
tags
Gitlab
summary
type
Post
管理员
本小节是基于 Docker 方式安装的 Gitlab,参考Gitlab 之 Docker 安装。
默认密码
大约 3-5 分钟后,gitlab 在 Docker 中完全运行起来,浏览器打开
http://gitlab.fe.sw:9000
就能看到 gitlab 安装完毕。默认用户名(即管理员)是
root
,密码存在文件/opt/dockers/gitlab/config/initial_root_password
中,其内容大致如下,很容易找到默认密码。# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: MVSqS0o8/XeAskEnIXFi92p7Q4M=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
重置密码
通过上面命令进入容器之后,启动 Ruby on Rails 控制台
gitlab-rails console -e production
搜索电子邮件或用户名,即搜索第一个用户
user = User.where(id: 1).first
更改密码,默认要求最短 8 位
user.password = '12345678'
确认更改密码
user.password_confirmation = '12345678'
保存,最后可使用新密码
12345678
登录root
账户。user.save!
URL 地址
主机版
打开 Gitlab 的配置文件
gitlab.rb
:vim /etc/gitlab/gitlab.rb
修改如下内容:
external_url 'http://192.168.1.199:8091'
nginx['listen_port'] = 8091
nginx['listen_https'] = false
更改 nginx 端口,编辑文件
gitlab-http.conf
:vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
查找如下内容并修改:
server {
listen *:8091;
server_name 192.168.1.199;
if ($http_host = "") {
set $http_host_with_default "192.168.1.199:8091";
}
}
初始化Gitlab:
gitlab-ctl reconfigure
,启动 Gitlab:gitlab-ctl restart
。然后浏览器输入
http://192.168.1.199:8091
,默认用户为 root
,首次打开网站会要求输入 root 账户的密码。Docker 版
邮箱
配置内容如下,然后重新对 gitlab 进行
reconfigure
和restart
:gitlab_rails['smtp_enable'] = truegitlab_rails['smtp_enable'] = truegitlab_rails['smtp_address'] = "smtp.163.com"gitlab_rails['smtp_port'] = 25gitlab_rails['smtp_user_name'] = "up_notify@163.com"gitlab_rails['smtp_domain'] = "163.com"gitlab_rails['smtp_authentication'] = "login"gitlab_rails['smtp_enable_starttls_auto'] = truegitlab_rails['smtp_tls'] = false# 使用163时下面几个必须和smtp_user_name一致,否则报错503gitlab_rails['gitlab_email_from'] = "up_notify@163.com"gitlab_rails['gitlab_email_reply_to'] = "up_notify@163.com"user["git_user_email"] = "up_notify@163.com"
测试邮件发送
gitlab-rails console # 进入控制台Notify.test_email('xxx@qq.com', '邮件标题', '邮件正文').deliver_now
批量操作
批量添加用户
参考 GitLab 批量创建用户,注意
userinfo.txt
需要 utf-8 的文件格式,否则读取有可能不成功。参考资料: