本地docker搭建gitlab, 并配置ldap认证

基于Docker在Mac OS X系统中的部署和设置GitLab的具体过程以下:
 
1. 安装Docker for Mac (参见 https://docs.docker.com/docker-for-mac/install/
 
2. 下载GitLab镜像
     docker pull gitlab/gitlab-ce
 
    文档可参见 https://docs.gitlab.com/omnibus/docker/
 
3. 运行GitLab实例
  sudo docker run -d \
    --hostname xxxx.xxxx.xx \
    --name gitlab \
    --restart always \
    --publish 30001:22 --publish 30000:80 --publish 30002:443 \
    --volume $HOME/gitlab/data:/var/opt/gitlab \
    --volume $HOME/gitlab/logs:/var/log/gitlab \
    --volume $HOME/gitlab/config:/etc/gitlab \
    gitlab/gitlab-ce
 
其中volume选项将gitlab的目录挂载为用户当地目录,以避免容器在中止或被删除的时候丢失数据。publish选项将宿主机器的30000、30001和30002映射为容器的80(http)、22(ssh)和443(https)端口。
 
4.配置GitLab实例
 
GitLab的配置存储在/etc/gitlab/gitlab.rb文件中。
 
利用命令“ sudo docker exec -it gitlab /bin/bash”能够在gitlab容器中进入bash,也能够用命令“ sudo docker exec -it gitlab vi /etc/gitlab/gitlab.rb”直接执行vi编辑GitLab配置文件。因为在运行GitLab实例时,已经用volume选项将gitlab的目录挂载为用户当地目录,所以gitlab.rb文件实际位于$HOME/gitlab/config目录下。
 
修改gitlab.rb文件后,在容器中执行命令gitlab-ctl reconfigure从新配置gitlab。
 
4.1 配置GitLab服务器的访问地址
 
4.1.1 配置http协议所使用的访问地址
将external_url修改成GitLab服务器的访问地址:
    external_url ' http://xxxx.xxxx.xxx:30000'
 
因为定义的url中有端口号,须要将nginx监听的端口号改回80,不然nginx将监听容器的30000端口,形成GitLab没法使用:
    nginx['listen_port'] = 80
 
4.1.2 配置ssh协议所使用的访问地址和端口
    gitlab_rails['gitlab_ssh_host'] = ‘ data.comdyn.cn'
    gitlab_rails['gitlab_shell_ssh_port'] =30001
 
4.2 配置邮箱
 
为了采用SMTP服务器而不是缺省的Sendmail发送邮件,须要修改gitlab.rb中的内容,
 
下面以网易163邮箱为例配置邮箱:
 
    gitlab_rails['gitlab_email_from'] = " xxxx@163.com
    gitlab_rails['gitlab_email_reply_to'] = ‘ xxxx@163.com'
    
    gitlab_rails['smtp_enable'] = true
    gitlab_rails['smtp_address'] = " smtp.163.com"
    gitlab_rails['smtp_port'] = 465
    gitlab_rails['smtp_user_name'] = " xxxx@163.com"
    gitlab_rails['smtp_password'] = "xxxxpassword"
    gitlab_rails['smtp_domain'] = " 163.com"
    gitlab_rails['smtp_authentication'] = "login"       
    gitlab_rails['smtp_enable_starttls_auto'] = true
    gitlab_rails['smtp_tls'] =true
 
    gitlab_rails['smtp_openssl_verify_mode'] = "peer"
 
最后,用命令docker restart gitlab重启GitLab,或者在容器中执行命令gitlab-ctl reconfigure从新配置gitlab。
 
5. 导入现有的git仓库
 
将现有的git仓库(如test)导入gitlab须要三步:
 
5.1 将已有的全部git仓库的裸库(如test.git)都拷贝到gitlab目录中。
 
前面在运行gitlab实例时,利用volume选项已经将gitlab的数据目录指定为$HOME/gitlab/data/,所以git仓库将存放在目录$HOME/gitlab/data/git-data/repositories/下。
 
gitlab容许建立组,将多个仓库归入到一个组中,每一个组在repositories下面对应于一个与组名称相同的子目录。将全部裸库拷贝到与其组所对应的子目录中。例如,若是要要将test仓库导入到sub组中的话,则应执行:
    sudo cp -r test.gig $HOME/gitlab/data/git-data/repositories/sub/
 
5.2 利用sudo chown命令,将test.git的拥有者的用户名和组名改成和repositories目录的拥有者相同,以保证gitlab能够访问该仓库。
 
5.3 导入仓库
 
在gitlab容器中执行gitlab-rake命令:
    sudo docker exec -it gitlab gitlab-rake gitlab:import:repos['$HOME/gitlab/data/git-data/repositories’]
导入repositories下的全部仓库,并自动建立组。若是某仓库在gitlab中已存在,则会跳过该仓库。

 

 

Gitlab 11.0.3汉化完成后,须要集成域控,现将域控的配置过程描述以下:html

gitlab目录:/etc/gitlabnginx

gitlab配置文件:/etc/gitlab/gitlab.rbgit

编辑gitlab.rb文件:docker

在gitlab.rb文件中修改下面配置,其中:shell

1.host,是搭建的ldap的ip,根据实际状况修改;windows

2.uid,能够配置cn,也能够配置uid,都能识别(具体为何没深刻研究);bash

3.bind_dn,ldap的管理员帐号,根据实际状况修改;服务器

4.password,ldap的管理员,根据实际状况修改;dom

5.active_directory,彷佛是针对链接是不是ad域控的标示,由于这部分是ldap的配置,故为false;ssh

6.allow_username_or_email_login,用户登陆是否用户名和邮箱均可以,方便用户故配置true;

7.base,用户列表所在的目录,由于新增的用户都在ldap的People下,故这么配置,根据实际状况修改;

个人配置以下:

  gitlab_rails['ldap_enabled'] = true 

###! **remember to close this block with 'EOS' below** 
 gitlab_rails['ldap_servers'] = YAML.load <<-'EOS' 
   main: # 'main' is the GitLab 'provider ID' of this LDAP server 
     label: 'LDAP' 
     host: '**.**.**.**' 
     port: 389 
     uid: 'sAMAccountName' 
     bind_dn: 'cn=***,cn=Users,dc=***,dc=****,dc=COM' 
     password: '*****' 
     encryption: 'plain' # "start_tls" or "simple_tls" or "plain" 
     verify_certificates: true 
     active_directory: true 
     allow_username_or_email_login: true 
     lowercase_usernames: false 
     block_auto_created_users: false 
     base: 'OU=Users,OU=*****,DC=***,DC=*****,DC=COM' 
     user_filter: '' 
     ## EE only 
#     group_base: '' 
#     admin_group: '' 
#     sync_ssh_keys: false 

#   secondary: # 'secondary' is the GitLab 'provider ID' of second LDAP server 
#     label: 'LDAP' 
#     host: '_your_ldap_server' 
#     port: 389 
#     uid: 'sAMAccountName' 
#     bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' 
#     password: '_the_password_of_the_bind_user' 
#     encryption: 'plain' # "start_tls" or "simple_tls" or "plain" 
#     verify_certificates: true 
#     active_directory: true 
#     allow_username_or_email_login: false 
#     lowercase_usernames: false 
#     block_auto_created_users: false 
#     base: '' 
#     user_filter: '' 
#     ## EE only 
#     group_base: '' 
#     admin_group: '' 
#     sync_ssh_keys: false 
 EOS 

 

 

重要配置参数解释(仔细阅读上一篇svn集成LDAP认证的文章这些参数会更好理解):
- host:LDAP服务器地址
- port:LDAP服务端口
- uid:以哪一个属性做为验证属性,能够为uid、cn等,咱们使用uid
- method:若是开启了tls或ssl则填写对应的tls或ssl,都没有就填写plain
- bind_dn:search搜索帐号信息的用户完整bind(须要一个有read权限的帐号验证经过后搜索用户输入的用户名是否存在)
- password:bind_dn用户的密码,bind_dn和password两个参数登陆LDAP服务器搜索用户
- active_directory:LDAP服务是不是windows的AD,咱们是用的OpenLDAP,这里写false
- allow_username_or_email_login:是否容许用户名或者邮箱认证,若是是则用户输入用户名或邮箱均可
- base:从哪一个位置搜索用户,例如容许登陆GitLab的用户都在ou gitlab里,name这里能够写ou=gitlab,dc=domain,dc=com
- filter:添加过滤属性,例如只过滤employeeType为developer的用户进行认证(employeeType=developer)

 

配置完成后进行配置更新:

  gitlab-ctl reconfigure

检查是否配置成功:

  gitlab-rake gitlab:ldap:check(列出前100个用户)

重启gitlab服务:

  gitlab-ctl restart

 

注意:  确认该用户不处于特殊状态

 

1.不处于“禁用帐户”的状态;

 

2.不处于“须要首次登陆修改密码”的状态;

 

(处于上面任意一种状态的帐户在登陆gitlab时都会报“Cloud not authenticate you from Ldapmain because "Invalid creadentials".”)

下图是发出的search 用户状态的请求:

判断用户状态码:

http://www.javashuo.com/article/p-woikbxpm-dq.html

相关文章
相关标签/搜索