Gitlab(Docker)中批量添加用户及邮件配置

gitlab页面可以添加用户,但是无法批量添加。可以使用api的方式批量添加用户:

1、创建token

在User Setting--Access Tokens中添加token:
Gitlab(Docker)中批量添加用户及邮件配置

复制创建好的token

2、配置脚本及用户信息文件

# vim userinfo.txt

name username password user_email
例如:
zhangshan zhangshan zhangshan123 

# vim user_add.sh

#!/bin/bash
userinfo="userinfo.txt"
while read line 
do
name=`echo $line|awk ‘{print $1}‘`
username=`echo $line|awk ‘{print $2}‘`
userpass=`echo $line|awk ‘{print $3}‘`
mail=`echo $line|awk ‘{print $4}‘`
curl -d "can_create_group=false&password=$userpass&email=$mail&username=$username&name=$name&private_token=qxxgPTxxxe1qH8J1" "http://gitlab.xxx.com/api/v4/users"
done<$userinfo

chmod +x user_add.sh

3、运行脚本

sh user_add.sh

4、查看gitlab,用户已创建,但是需要邮件confirm

5、配置gitlab邮件

由于gitlab的容器镜像未安装sendmail,所以需要安装后才能发送邮件
Dockerfile如下:

FROM gitlab/gitalab-ce
RUN apt-get update & apt-get install postfix

需要修改gitlab配置:

#vim /etc/gitlab/gitlab.rb
#腾讯企业邮箱
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.exmail.qq.com"
gitlab_rails[‘smtp_port‘] = 465
gitlab_rails[‘smtp_user_name‘] = ""
gitlab_rails[‘smtp_password‘] = "xxxxxx"
gitlab_rails[‘smtp_authentication‘] = "login"
gitlab_rails[‘smtp_enable_starttls_auto‘] = true
gitlab_rails[‘smtp_tls‘] = false
gitlab_rails[‘gitlab_email_from‘] = ‘‘
gitlab_rails[‘smtp_domain‘] = ‘exmail.qq.com‘

6、测试发送邮件

gitlab-rails console

Notify.test_email(‘‘,‘标题,‘正文‘).deliver_now

这里出现报错:

postdrop: warning: mail_queue_enter: create file maildrop/xxxx.xxxx: Permission denied
postdrop: warning: mail_queue_enter: create file maildrop/yyyy.yyyy: Permission denied

解决方法:

# chown postfix.postdrop /var/spool/postfix/public -R
# chown postfix.postdrop /var/spool/postfix/maildrop -R
# chmod 777 -R /var/spool/postfix

邮箱配置能成功发送邮件后,新建用户,用户收到的邮箱打开gitlab服务器域名是容器主机名称,需做修改

vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml

host: xxxx
port: 80
https: false

重启

gitlab-ctl reconfigure

相关推荐