温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-26 23:29:33 来源:网络 阅读:445 作者:槑槑的嫑嫑 栏目:系统运维

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

1、创建token

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

复制创建好的token

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

# vim userinfo.txt

name username password user_email
例如:
zhangshan zhangshan zhangshan123 zhangshan@demo.com

# 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'] = "monitor_robot@xxx.com"
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'] = 'monitor_robot@xxxx.com'
gitlab_rails['smtp_domain'] = 'exmail.qq.com'

6、测试发送邮件

gitlab-rails console

Notify.test_email('xxxx@xxx.com','标题,'正文').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
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI