gitlab一键安装+配置(备份+LADP认证)
1 2 #gitlab一键安装 3 #centos6 mini, GitLab社区版 4 #参考官方最新文档 https://www.gitlab.com.cn/installation 5 6 #关闭防火墙(略) 7 ntpdate ntp6.aliyun.com ##同步时间 8 #更换源 9 yum -y install wget vim 10 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 11 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo 12 yum -y install http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm 13 yum makecache #生成缓存 14 15 #安装配置依赖 16 yum install curl openssh-server openssh-clients postfix cronie -y 17 service postfix start 18 chkconfig postfix on 19 lokkit -s http -s ssh 20 21 # 添加GitLab仓库 22 curl -sS http://packages.gitlab.cc/install/gitlab-ce/script.rpm.sh | bash 23 yum install gitlab-ce #(自动安装最新版) 24 #yum install gitlab-ce-8.8.4-ce.0.el6 #(安装指定版本) 25 #下载rpm包安装 26 #https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/ 27 #curl -LJO https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-XXX.rpm 28 #rpm -i gitlab-ce-*.rpm 29 30 vim /etc/gitlab/gitlab.rb #修改配置 31 external_url 'http://192.168.18.9' #修改访问web 32 gitlab_rails['backup_path'] = '/home/backup' #修改备份文件的目录 33 gitlab_rails['backup_keep_time'] = 604800 #备份保存7天(604800是7天的秒数) 34 35 gitlab-ctl reconfigure #载入配置 36 #v8初始密码: 37 Username: root 38 Password: 5iveL!fe 39 #w1w1e1e1 40 41 gitlab-ctl status #查看服务状态 42 gitlab-rake gitlab:check SANITIZE=true --trace #检查gitlab 43 gitlab-ctl reconfigure #启动服务 44 gitlab-ctl stop #停止所有 gitlab 组件 45 gitlab-ctl start 46 gitlab-ctl restart 47 vim /etc/gitlab/gitlab.rb #修改默认的配置 48 cat /opt/gitlab/embedded/service/gitlab-rails/VERSION #查看版本 49 gitlab-ctl tail #查看日志 50 51 ##备份 52 gitlab-rake gitlab:backup:create #创建备份 53 #自动备份(定时任务凌晨2点执行) 54 crontab -e 55 0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create 56 #恢复 57 gitlab-ctl stop 58 #BACKUP=xxxxxx ,为备份文件前面的数字部分 59 cd /var/opt/gitlab/backups # 默认备份存放目录 60 gitlab-rake gitlab:backup:restore BACKUP=xxxxxx 61 gitlab-rake gitlab:backup:restore #backups目录只有一个备份时使用 62 63 ########################################################### 64 ##汉化 65 #下载对于版本的汉化包 66 https://coding.net/u/larryli/p/gitlab/git/tree/v8.1.2.zh1/ 67 #停止服务 68 gitlab-ctl stop 69 cp -arp /opt/gitlab/embedded/service/gitlab-rails /opt/gitlab/embedded/service/gitlab-rails-bak/ 70 #下载汉化版替换 71 cd /root/gitlab 72 unzip *.zh1.zip 73 cp -arp /root/gitlab/gitlab-v8.1.2.zh1/. /opt/gitlab/embedded/service/gitlab-rails/ 74 gitlab-ctl reconfigure #重新加载配置启动GitLab 75 76 ##GitLab修改root用户密码 77 # root用户下执行 78 gitlab-rails console production 79 user = User.where(id: 1).first 80 user.password=12345678 81 user.password_confirmation=12345678 82 user.save! 83 quit 84 ########完成 85 86 ########################################################### 87 #AD域配置文件,AD认证用户要对应其目录 88 #也可以使用OpenLADP 89 cp /etc/gitlab/gitlab.rb{,.bak} 90 #cp /etc/gitlab/gitlab.rb.bak /etc/gitlab/gitlab.rb 91 vim /etc/gitlab/gitlab.rb 92 #gitlab 93 external_url 'http://192.168.18.10' 94 # LDAP,AD 95 gitlab_rails['ldap_enabled'] = true 96 gitlab_rails['ldap_servers'] = YAML.load <<-EOS 97 main: # 'main' is the GitLab 'provider ID' of this LDAP server 98 label: 'xlh' 99 host: '172.16.16.16' #AD的IP# 100 port: 389 101 uid: 'sAMAccountName' 102 method: 'plain' # "tls" or "ssl" or "plain" 103 bind_dn: 'CN=gitlab,OU=Dev,OU=users,DC=test,DC=dev' 104 password: '12345678' 105 active_directory: true 106 allow_username_or_email_login: false 107 block_auto_created_users: false 108 allow_username_or_email_login: false 109 block_auto_created_users: false 110 base: 'OU=Dev,OU=users,DC=test,DC=dev' 111 user_filter: '' 112 group_base: '' 113 admin_group: '' 114 sync_ssh_keys: false 115 EOS 116 ########### 117 gitlab-ctl reconfigure #重新载入配置