Skip to content
SRE运维进阶之路SRE运维进阶之路
github icon
  • Jenkins

    • Jenkins 学习笔记
      • 1 Jenkins 简介

        • 1.1 DevOps、CI、CD都是什么鬼?
          • 1.2 Jenkins简介
          • 2 安装 Jenkins

            • 2.1 yum 安装 jenkins
              • 2.2 war 包安装 jenkins
                • 2.3 使用 ansible 安装 jenkins
                  • 2.4 使用docker安装jenkins
                  • 3 使用 Jenkins

                    • 3.1 Jenkins用户权限管理
                      • 3.2 访问 API
                      • 4 流水线核心语法

                        • 4.1 开始编写Jenkinsfile
                          • 4.2 Jenkins流水线语法
                            • 4.3 Groovy 简明教程
                              • 4.4 Jenkins共享库应用
                                • 4.5 共享库之钉钉消息推送
                                  • 4.6 流水线开发工具
                                    • 4.7 pipeline 生产配置实例
                                      • 4.8 在 VS Code 中校验 Jenkinsfile
                                      • 5 流水线集成篇

                                        • 5.1 构建发布工具集成
                                          • 5.2 用户认证系统集成
                                          • 6 管理 jenkins

                                            • 6.1 Jenkins 关闭和重启的实现方式
                                            • 7 日常维护

                                              • 7.1 Jenkins Job迁移
                                              • 8 Jenkins 常见问题
                                              • Ansible

                                                • Ansible 学习笔记
                                                  • 1 初识Ansible
                                                    • 2 Ansible Inventory配置详解
                                                      • 3 Ansible Ad-hoc命令集

                                                        • 3.1 Ansible Ad-hoc 常用命令集
                                                          • 3.2 Ansible lineinfile模块详解
                                                          • 4 Ansible Playbook

                                                            • 4.1 Playbook的结构及handler用法
                                                              • 4.2 Playbook循环语句
                                                                • 4.3 Playbook条件语句
                                                                  • 4.4 Playbook高级用法
                                                                    • 4.5 Playbook之tags
                                                                      • 4.6 巧用Roles
                                                                        • 4.7 Jinja2 模板
                                                                          • 4.8 yaml语法
                                                                          • 5 Ansible变量

                                                                            • 5.1 自定义变量
                                                                              • 5.2 Fact变量
                                                                                • 5.3 魔法变量
                                                                                  • 5.4 使用lookup生成变量
                                                                                    • 5.5 使用vault配置加密
                                                                                    • 6 Ansible使用优化
                                                                                      • 7 常见问题
                                                                                        • 8 综合项目

                                                                                          • 使用 ansible 快速安装 k8s 机器

                                                                                        gitlab备份迁移升级&集成openldap

                                                                                        author iconClaycalendar icon2019年12月20日category icon
                                                                                        • 自动化工具
                                                                                        tag icon
                                                                                        • Gitlab
                                                                                        timer icon大约 4 分钟

                                                                                        此页内容
                                                                                        • gitlab安装
                                                                                          • 安装相关依赖
                                                                                          • 镜像切换
                                                                                          • 配置使用
                                                                                        • gitlab备份&恢复
                                                                                          • 备份配置
                                                                                          • 手动备份
                                                                                          • 自动备份
                                                                                          • 备份恢复
                                                                                        • gitlab升级
                                                                                        • gitlab集成openldap
                                                                                          • Setting up LDAP sign-in

                                                                                        # gitlab备份迁移升级&集成openldap

                                                                                        # gitlab安装

                                                                                        # 安装相关依赖

                                                                                        yum install -y curl policycoreutils-python openssh-server
                                                                                        yum install postfix
                                                                                        systemctl enable postfix
                                                                                        systemctl start postfix
                                                                                        
                                                                                        1
                                                                                        2
                                                                                        3
                                                                                        4

                                                                                        # 镜像切换

                                                                                        切换为国内的清华源

                                                                                        # cat gitlab_gitlab-ce.repo 
                                                                                        [gitlab_gitlab-ce]
                                                                                        name=gitlab_gitlab-ce
                                                                                        baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
                                                                                        repo_gpgcheck=0
                                                                                        gpgcheck=0
                                                                                        enabled=1
                                                                                        
                                                                                        1
                                                                                        2
                                                                                        3
                                                                                        4
                                                                                        5
                                                                                        6
                                                                                        7

                                                                                        由于不同版本号的备份文件不能相互使用,下载旧gitlab中的对应的版本

                                                                                        yum -y install gitlab-ce-11.5.1
                                                                                        
                                                                                        1

                                                                                        # 配置使用

                                                                                        安装完成之后,可以在/etc/gitblab/gitlab.rb中按照需求修改配置, 主要需要修改external_url,改成自己使用的 url 地址。 执行命令配置生效:

                                                                                        gitlab-ctl reconfigure
                                                                                        gitlab-ctl restart
                                                                                        
                                                                                        1
                                                                                        2

                                                                                        # gitlab备份&恢复

                                                                                        Gitlab 成功运行起来之后,最终的事情就是定期的备份,遇到问题后的还原。

                                                                                        # 备份配置

                                                                                        默认 Gitlab 的备份文件会创建在/var/opt/gitlab/backups文件夹中,格式为时间戳_日期_版本号_gitlab_backup.tar,例如:1515031353_2018_01_04_10.3.2_gitlab_backup.tar。 修改备份文件夹,需要修改配置文件/etc/gitlab/gitlab.rb中的:

                                                                                        gitlab_rails['backup_path'] = '/your_wish/backups'
                                                                                        
                                                                                        1

                                                                                        然后gitlabctl-reconfigure生效。

                                                                                        # 手动备份

                                                                                        命令:gitlab-backup create

                                                                                        For GitLab 12.1 and earlier, use gitlab-rake gitlab:backup:create. 会在命令执行的时间点,在你配置的文件夹或者默认文件夹创建一个备份文件。

                                                                                        # 自动备份

                                                                                        0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1
                                                                                        
                                                                                        1

                                                                                        Note For GitLab 12.1 and earlier, use gitlab-rake gitlab:backup:create.

                                                                                        # 备份恢复

                                                                                        First make sure your backup tar file is in the backup directory described in the gitlab.rb configuration gitlab_rails['backup_path']. The default is /var/opt/gitlab/backups. It needs to be owned by the git user.

                                                                                        cp 11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar /var/opt/gitlab/backups/
                                                                                        chown git.git /var/opt/gitlab/backups/11493107454_2018_04_25_10.6.4-ce_gitlab_backup.tar
                                                                                        
                                                                                        1
                                                                                        2

                                                                                        Stop the processes that are connected to the database. Leave the rest of GitLab running:

                                                                                        gitlab-ctl stop unicorn
                                                                                        gitlab-ctl stop sidekiq
                                                                                        # Verify
                                                                                        gitlab-ctl status
                                                                                        
                                                                                        1
                                                                                        2
                                                                                        3
                                                                                        4

                                                                                        Next, restore the backup, specifying the timestamp of the backup you wish to restore:

                                                                                        # This command will overwrite the contents of your GitLab database!
                                                                                        gitlab-backup restore BACKUP=1493107454_2018_04_25_10.6.4-ce
                                                                                        
                                                                                        1
                                                                                        2

                                                                                        Note For GitLab 12.1 and earlier, use gitlab-rake gitlab:backup:restore.

                                                                                        Warning: gitlab-rake gitlab:backup:restore does not set the right file system permissions on your Registry directory. This is a known issueopen in new window. On GitLab 12.2 or newer, you can use gitlab-backup restore to avoid this issue.

                                                                                        Next, restore /etc/gitlab/gitlab-secrets.json if necessary as mentioned above.

                                                                                        Reconfigure, restart and check GitLab:

                                                                                        gitlab-ctl reconfigure
                                                                                        gitlab-ctl restart
                                                                                        gitlab-rake gitlab:check SANITIZE=true
                                                                                        
                                                                                        1
                                                                                        2
                                                                                        3

                                                                                        If there is a GitLab version mismatch between your backup tar file and the installed version of GitLab, the restore command will abort with an error. Install the correct GitLab versionopen in new window and try again.

                                                                                        # gitlab升级

                                                                                        It is considered safe to jump between patch versions and minor versions within one major version. For example, it is safe to:

                                                                                        • Upgrade the patch version:
                                                                                          • 8.9.0 -> 8.9.7
                                                                                          • 8.9.0 -> 8.9.1
                                                                                          • 8.9.2 -> 8.9.6
                                                                                          • 9.5.5 -> 9.5.9
                                                                                          • 10.6.3 -> 10.6.6
                                                                                          • 11.11.1 -> 11.11.8
                                                                                          • 12.0.4 -> 12.0.9
                                                                                        • Upgrade the minor version:
                                                                                          • 8.9.4 -> 8.12.3
                                                                                          • 9.2.3 -> 9.5.5
                                                                                          • 10.6.6 -> 10.8.7
                                                                                          • 11.3.4 -> 11.11.8

                                                                                        Upgrading the major version requires more attention. We cannot guarantee that upgrading between major versions will be seamless. As previously mentioned, major versions are reserved for backwards incompatible changes. We recommend that you first upgrade to the latest available minor version within your major version. By doing this, you can address any deprecation messages that could change behavior in the next major release. To ensure background migrations are successful, increment by one minor version during the version jump before installing newer releases.

                                                                                        For example: 11.11.x -> 12.0.x Please see the table below for some examples:

                                                                                        Latest stable versionYour versionRecommended upgrade pathNote
                                                                                        9.4.58.13.48.13.4 -> 8.17.7 -> 9.4.58.17.7 is the last version in version 8
                                                                                        10.1.48.13.48.13.4 -> 8.17.7 -> 9.5.10 -> 10.1.48.17.7 is the last version in version 8, 9.5.10 is the last version in version 9
                                                                                        11.3.48.13.48.13.4 -> 8.17.7 -> 9.5.10 -> 10.8.7 -> 11.3.48.17.7 is the last version in version 8, 9.5.10 is the last version in version 9, 10.8.7 is the last version in version 10
                                                                                        12.5.811.3.411.3.4 -> 11.11.8 -> 12.0.9 -> 12.5.811.11.8 is the last version in version 11

                                                                                        我的升级路线为:表格中最后一个

                                                                                        每次升级直接yum -y install gitlab-ce-版本号就可以了

                                                                                        例如

                                                                                        yum -y install gitlab-ce-11.11.8
                                                                                        
                                                                                        1

                                                                                        每升级一次,重载一下配置,重启一下gitlab

                                                                                        gitlab-ctl reconfigure
                                                                                        gitlab-ctl restart
                                                                                        
                                                                                        1
                                                                                        2

                                                                                        # gitlab集成openldap

                                                                                        # Setting up LDAP sign-in

                                                                                        If you have an LDAP directory service such as Active Directory, you can configure GitLab so that your users can sign in with their LDAP credentials. Add the following to /etc/gitlab/gitlab.rb, edited for your server.

                                                                                        For GitLab Community Edition:

                                                                                        以下是我ldap的配置

                                                                                        ### LDAP Settings
                                                                                        ###! Docs: https://docs.gitlab.com/omnibus/settings/ldap.html
                                                                                        ###! **Be careful not to break the indentation in the ldap_servers block. It is
                                                                                        ###!   in yaml format and the spaces must be retained. Using tabs will not work.**
                                                                                        
                                                                                        gitlab_rails['ldap_enabled'] = true
                                                                                        gitlab_rails['prevent_ldap_sign_in'] = false
                                                                                        gitlab_rails['ldap_servers'] = YAML.load <<-EOS
                                                                                        main:
                                                                                          label: 'LDAP'
                                                                                          host: '192.168.x.x'
                                                                                          port: 389
                                                                                          uid: 'cn'
                                                                                          encryption: 'plain'
                                                                                          bind_dn: 'cn=admin,dc=xxx,dc=com'
                                                                                          password: 'xxx'
                                                                                          smartcard_auth: false
                                                                                          active_directory: true
                                                                                          allow_username_or_email_login: true
                                                                                          lowercase_usernames: false
                                                                                          base: 'ou=People,dc=xxx,dc=com'
                                                                                          user_filter: ''
                                                                                        EOS
                                                                                        
                                                                                        1
                                                                                        2
                                                                                        3
                                                                                        4
                                                                                        5
                                                                                        6
                                                                                        7
                                                                                        8
                                                                                        9
                                                                                        10
                                                                                        11
                                                                                        12
                                                                                        13
                                                                                        14
                                                                                        15
                                                                                        16
                                                                                        17
                                                                                        18
                                                                                        19
                                                                                        20
                                                                                        21
                                                                                        22
                                                                                        23
                                                                                        gitlab-ctl reconfigure
                                                                                        gitlab-ctl restart
                                                                                        
                                                                                        1
                                                                                        2

                                                                                        参考文章:

                                                                                        https://www.jianshu.com/p/d29c332bcf53

                                                                                        https://docs.gitlab.com/ee/raketasks/backup_restore.html#restore-for-omnibus-gitlab-installations

                                                                                        https://www.jianshu.com/p/6361cba123a8

                                                                                        https://docs.gitlab.com/ee/policy/maintenance.html#upgrade-recommendations

                                                                                        https://docs.gitlab.com/omnibus/settings/ldap.html

                                                                                        https://www.jianshu.com/p/083cf462fed4

                                                                                        edit icon编辑此页open in new window
                                                                                        上次编辑于: 2022/4/27 15:33:00
                                                                                        贡献者: clay-wangzhi
                                                                                        备案号:冀ICP备2021007336号
                                                                                        Copyright © 2023 Clay