• GitLab服务的搭建、配置


    一、Docker的安装

    1、卸载旧版本

    sudo yum remove docker \
                      docker-client \
                      docker-client-latest \
                      docker-common \
                      docker-latest \
                      docker-latest-logrotate \
                      docker-logrotate \
                      docker-engine

    2、使用脚本安装

    # 获取、执行脚本、
    curl -fsSL https://get.docker.com -o get-docker.sh
    sh ./get-docker.sh
    
    # 设置开启启动
    # 设置开机启动,并启动 docker 
    systemctl enable docker
    systemctl start docker

    3、设置镜像仓库

    可以使用阿里云的容器镜像服务提供的镜像加速器:

    vim /etc/docker/daemon.json

    {
      "registry-mirrors": ["https://****.mirror.aliyuncs.com"]  # 写入自己的镜像加速器
    }

    然后加载配置文件并且重启docker:

    systemctl daemon-reload && systemctl restart docker

     二、GitLab安装与配置

    1、设置卷位置

    在设置其它所有内容之前,配置一个新的环境变量,$GITLAB_HOME 指向配置、日志和数据文件所在的目录。确保目录存在并且已授予适当的权限

    export GITLAB_HOME=/gitlab

    2、安装

    sudo docker run --detach \
      --publish 443:443 --publish 80:80 --publish 222:22 \
      --name gitlab \
      --restart always \
      --volume $GITLAB_HOME/config:/etc/gitlab \
      --volume $GITLAB_HOME/logs:/var/log/gitlab \
      --volume $GITLAB_HOME/data:/var/opt/gitlab \
      --shm-size 256m \
      gitlab/gitlab-ee:latest
    • --detach: -d的缩写,后台启动
    • --publish: -p的缩写,其中80:80是将容器的80端口映射为宿主机的80端口,安装成功后可以通过ip:80直接访问
    • --name:容器命名

    详情配置可参考官网:https://docs.gitlab.com/ee/install/docker.html

    3、配置修改

    • 关闭防火墙
    # 查看防火墙
     systemctl status firewalld
    
    # 关闭防火墙
    systemctl stop firewalld
    
    # 永久关闭防火墙
    systemctl disable firewalld
    • gitlab配置

    当通过上述启动容器后,会在/gitlab目录下生成config配置文件的目录,需要进行修改一些参数然后重启容器。

    vim /gitlab/config/gitlab.rb

    # http协议访问地址
    external_url   '172.16.52.8'
    
    # ssh协议host和port
    gitlab_rails['gitlab_ssh_host'] = '172.16.52.8'
    gitlab_rails[''gitlab_shell_ssh_host] = 222
    
    # 修改时区
    gitlab_rails['time_zone'] = 'Asia/Shanghai'

    然后重启容器:

    docker restart gitlab

    如果此时出现502错误,如:

    一般情况就是内存不足,建议最少4G内存,另外就是修改一下配置文件中超时设置:

    # 超时设置
    gitlab_rails['webhook_timeout'] = 90

    然后重启容器。

     三、GitLab的使用

    1、初始化

    访问 http://172.16.52.8 即可:

     然后进行注册和登录即可。

    但是当你注册账号进行登录时出现:Your account is pending approval from your GitLab administrator and hence blocked... 这样的问题。就是说你注册的账号需要管理员来审批。

    所以需要先通过管理员root进行登录,此时需要进入容器中获取管理员密码:

    docker exec -it gitlab bash grep 'Password' /etc/gitlab/initial_root_password

    然后使用root账户登录,进行审批:

    然后就可以使用之前注册的帐号进行登录了.

    2、配置SSH密匙

    配置好SSH密匙后,本地代码pull/push就更简单了。

    • 生成 ssh
    # 命令生成
    ssh-keygen -t rsa -C "youremail@example.com"
    
    # 获取id_rsa.pub,将生成的id_rsa.pub添加到gitlab中的ssh管理处
    cat ~/.ssh/id_rsa.pub

    3、创建项目

     4、测试ssh配置

     复制ssh链接,然后进行clone:

    shenjianping@shenjianping-PC:~/PycharmProjects$ git clone ssh://git@172.16.52.8:222/shenjianping/ssh_test.git
    正克隆到 'ssh_test'...
    The authenticity of host '[172.16.52.8]:222 ([172.16.52.8]:222)' can't be established.
    ECDSA key fingerprint is 
    KLIU5WKxLIf+/46j2Cf+S+LqkUJtYa02vG3M.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '[172.16.52.8]:222' (ECDSA) to the list of known hosts.
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    接收对象中: 100% (3/3), 完成.

    至此就完成了GitLab的搭建与配置。

      

  • 相关阅读:
    Jmeter跨线程组传值
    python基础之高级函数
    Python基础之函数的应用
    python基础之文件的输入输出
    python基础练习之猜数字
    折腾了两天的跨站脚本提交问题,与IIS7有关
    python简介和环境搭建
    python paramiko
    Linux rsync 企业级应用
    Linux find 命令详解
  • 原文地址:https://www.cnblogs.com/shenjianping/p/16683631.html
Copyright © 2020-2023  润新知