gitlab部署及LDAP集成
由于gitlab涉及到文件存储,占用空间大,我们依旧单独部署gitlab,不通过k8s。

1、查找GitLab镜像

docker search gitlab

2、拉取gitlab docker镜像

docker pull gitlab/gitlab-ce:latest

3、创建目录

mkdir -p /usr/local/gitlab-test/{etc,log,opt}

4、运行GitLab并运行容器

docker run --name gitlab -p 20080:80 -p 20022:22 \
  -v  /usr/local/gitlab-test/etc:/etc/gitlab \
  -v  /usr/local/gitlab-test/log:/var/log/gitlab \
  -v  /usr/local/gitlab-test/opt:/var/opt/gitlab \
  -dit gitlab/gitlab-ce

5、进入容器内

docker exec -it gitlab /bin/bash

6、修改/etc/gitlab/gitlab.rb

# gitlab访问地址,可以写域名。如果端口不写的话默认为80端口
external_url='http://10.252.171.31:20080'
# ssh主机ip
gitlab_rails['gitlab_ssh_host'] = '10.252.171.31'
# ssh连接端口
gitlab_rails['gitlab_shell_ssh_port'] = 20022

7、打开地址:20080

img

img

这里需要重置密码

gitlab-rails console -e production
user = User.where(username:"root").first
user.password = "qwer1234"
user.save!

账号密码:root/qwer1234
8、集成ldap

echo "
gitlab_rails['time_zone'] ='Asia/Shanghai'   # 设置时区
gitlab_rails['gitlab_shell_ssh_port'] = 10022  # 访问ssh的端口
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
  main: # 'main' is the GitLab 'provider ID' of this LDAP server
    label: 'LDAP'           # 显示在登录页面上的名称
    host: '10.252.176.31'      # LDAP服务地址
    port: 389               # LDAP服务端口,如果LDAP基于SSL在端口通常为636
    uid: 'sn'   # LDAP中用户名对应的属性,通常为'sAMAccountName'
    bind_dn: 'cn=admin,cn=默认用户组,dc=example,dc=com' # 同步用户信息的账户格式为'domain\username'
    password: '123456'     # 同步用户信息的账户密码
    encryption: 'plain'     # 'start_tls' or 'simple_tls' or 'plain'
    verify_certificates: false  # 如果使用SSL,则设为true
    active_directory: false     # 如果是 Active Directory LDAP server 则设为true
    allow_username_or_email_login: false  # 是否允许email登录
    lowercase_usernames: false            # 是否将用户名转为小写
    block_auto_created_users: false       # 是否自动创建用户
    base: 'OU=person,DC=example,DC=com' # 搜索LDAP用户是的BaseDN
    user_filter: ''
EOS
" >> /etc/gitlab/gitlab.rb

9、通过ldap登录
img