Gitlab安装与配置LDAP登录

Gitlab安装

Centos7安装Gitlab

# 解决依赖
yum install policycoreutils-python.x86_64 openssh-server.x86_64 -y

# 安装邮件服务
yum install postfix.x86_64 -y

# 添加GitLab Package
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | bash

# 安装社区版GitLab
yum install gitlab-ce.x86_64 -y

# 修改GitLab配置
vim /etc/gitlab/gitlab.rb
external_url "http://10.10.10.8"
# 启动GitLab
gitlab-ctl reconfigure

也可以使用清华大学的yum源安装:vim /etc/yum.repos.d/gitlab-ce.repo

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
yum makecache
yum install gitlab-ce.x86_64 -y

访问并设置密码。

安装报错

8080端口被占用

# 修改配置文件
vim /etc/gitlab/gitlab.rb
unicorn['port'] = 8082
# 修改监听文件
vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
listen "127.0.0.1:8082", :tcp_nopush => true
# 重启GitLab服务
gitlab-ctl restart

Centos7安装Gitlab-Runner

# 添加package
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | bash
# 安装
yum install gitlab-runner.x86_64 -y

也可以使用清华大学的yum源安装:vim /etc/yum.repos.d/gitlab-runner.repo

[gitlab-runner]
name=gitlab-runner
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-runner/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

配置Gitlab-Runner

在GitLab页面中新建一个项目,在项目中依次找到:Settings --> CI/CD --> Runner

image-20200617153149174

在服务器上执行

gitlab-runner register
# 需要我们输入页面中的地址与Token

image-20200617153217435

Gitlab-Runner注册完成后,刷新页面就可以看到Runner信息

image-20200617153249537

Gitlab配置LDAP

参考链接:https://docs.gitlab.com/ee/administration/auth/ldap.html

备注:我们这里使用的是FreeIPA来替代原生的LDAP。

  • FreeIPA地址:10.10.10.7 ipa.bloodzer0.com
  • GitLab地址:10.10.10.8

在Gitlab配置域名解析:vim /etc/hosts

10.10.10.7  ipa.bloodzer0.com

如果直接按照参考链接配置,会出现无法登录,经过N次的尝试如下配置可以成功:

vim /etc/gitlab/gitlab.rb
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: 'ipa.bloodzer0.com'
    port: 389
    uid: 'uid'
    bind_dn: 'uid=admin,cn=users,cn=compat,dc=bloodzer0,dc=com'
    password: 'bloodzer01'
    encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
    verify_certificates: true
    smartcard_auth: false
    active_directory: true
    allow_username_or_email_login: false
    lowercase_usernames: false
    block_auto_created_users: false
    base: 'cn=users,cn=compat,dc=bloodzer0,dc=com'
    user_filter: ''
EOS
# 重启GitLab服务
gitlab-ctl reconfigure
gitlab-ctl restart

此时就可以成功登录了

image-20200617153527954

实现分组控制登录Gitlab

如果我们只想允许FreeIPA中某个分组的用户才能登录GitLab,我们需要修改配置文件如下:

gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
  main:
    label: 'LDAP'
    host: 'ipa.bloodzer0.com'
    port: 389
    uid: 'uid'
    bind_dn: 'uid=admin,cn=users,cn=accounts,dc=bloodzer0,dc=com'
    password: 'bloodzer01'
    encryption: 'plain'
    active_directory: ture
    allow_username_or_email_login: false
    lowercase_usernames: false
    block_auto_created_users: false
    base: 'cn=users,cn=accounts,dc=bloodzer0,dc=com'
    user_filter: (memberOf=cn=gitlab_user,cn=groups,cn=accounts,dc=bloodzer0,dc=com)
EOS

此时我们在FreeIPA中新建一个组,组名为:gitlab_user,并在其中新建一个用户:gitlab_bloodzer0,我们使用此账户来登录GitLab:

image-20200617153627850

image-20200617153640594

猜你喜欢

转载自blog.csdn.net/bloodzer0/article/details/106809701