zoukankan      html  css  js  c++  java
  • centos6.0搭建gitlab环境

    刚刚完成在centos上部署gitlab,遇到了许多问题,做个备忘。

    基本介绍

      参考文档:https://www.cnblogs.com/leeyongbard/p/9777498.html

      git,github,gitlab之间的关系

        版本控制系统

          集中式版本控制系统(svn,cvs):集中式版本控制系统下的历史仓库是存在于中央仓库,每次对比与提交代码都必须连接到中央仓库.

            

               分布式版本控制系统(git):分布式版本控制系统下的本地仓库包含代码库还有历史库,在本地就可以查看版本历史。

            

          GitHub 和  GitLab 都是基于 web 的 Git 仓库,使用起来二者差不多,它们都提供了分享开源项目的平台,为开发团队提供了存储、分享、发布和合作开发项目的中心化云存储的场所。

                  

      github和gitlab都是基于web的git仓库,gitlab与github的区别如下:

        (1) gitlab允许免费设置仓库权限;

        (2) gitlab允许用户选择分享一个 project 的部分代码;

        (3) gitlab允许用户设置 project 的获取权限,进一步提升安全性;

        (4) gitlab可以设置获取到团队整体的改进进度;

        (5) gitlab通过 innersourcing 让不在权限范围内的人访问不到该资源.

      所以对大多数有服务器资源的公司来讲,都会选择更加安全并且免费的gitlab。

    环境准备及安装

      

    1.环境依赖安装
      [root@linux~]#yum install curl policycoreutils openssh-server openssh-clients postfix
      [root@linux ~]#systemctl start postfix
    2.安装gitlab-ce
      [root@linux ~]# vim /etc/yum.repos.d/gitlab-ce.repo
    #在编辑器中输入如下内容保存
      [gitlab-ce]
      name=gitlab-ce
      baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7注意:如果是centos6版本的,这里改成e16
      repo_gpgcheck=0
      gpgcheck=0
      enabled=1
      gpgkey=https://packages.gitlab.com/gpg.key
    
    [root@linux ~]# yum makecache  #更新本地yum缓存
    [root@linux ~]# yum install gitlab-ce  #自动安装gitlab的最新社区版
    3.配置并启动gitlab-ce
      [root@linux ~]# gitlab-ctl reconfigure
    安装完成使用命令验证一下
    [root@linux ~]# gitlab-ctl status
    run: alertmanager: (pid 13786) 14040s; run: log: (pid 13463) 14051s
    run: gitaly: (pid 1743) 19295s; run: log: (pid 1742) 19295s
    run: gitlab-monitor: (pid 13695) 14043s; run: log: (pid 12862) 14074s
    run: gitlab-workhorse: (pid 13655) 14044s; run: log: (pid 12267) 14097s
    run: logrotate: (pid 27759) 3287s; run: log: (pid 12564) 14086s
    run: nginx: (pid 12391) 14094s; run: log: (pid 12465) 14090s
    run: node-exporter: (pid 13673) 14044s; run: log: (pid 12739) 14079s
    run: postgres-exporter: (pid 13816) 14040s; run: log: (pid 13633) 14045s
    run: postgresql: (pid 10555) 14200s; run: log: (pid 10644) 14196s
    run: prometheus: (pid 13730) 14042s; run: log: (pid 13296) 14057s
    run: redis: (pid 1741) 19295s; run: log: (pid 1740) 19295s
    run: redis-exporter: (pid 13703) 14043s; run: log: (pid 13027) 14068s
    run: sidekiq: (pid 12030) 14108s; run: log: (pid 12072) 14105s
    run: unicorn: (pid 11873) 14114s; run: log: (pid 11948) 14111s
    注意:这里都是gitlab的组件,有时候gitlab-ctl reconfigure执行完会报错,导致的结果是组件启动不全,我遇到的报错内容如下:
    Running handlers:
    There was an error running gitlab-ctl reconfigure:

    execute[/opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8] (postgresql::enable line 80) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
    ---- Begin output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
    STDOUT: The files belonging to this database system will be owned by user "gitlab-psql".
    This user must also own the server process.

    The database cluster will be initialized with locale "zh_CN.GBK".
    STDERR: initdb: encoding mismatch
    The encoding you selected (UTF8) and the encoding that the
    selected locale uses (GBK) do not match.  This would lead to
    misbehavior in various character string processing functions.
    Rerun initdb and either do not specify an encoding explicitly,
    or choose a matching combination.
    ---- End output of /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 ----
    Ran /opt/gitlab/embedded/bin/initdb -D /var/opt/gitlab/postgresql/data -E UTF8 returned 1
    这是由于系统编码问题造成的,解决方法如下:
    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    export LANGUAGE=en_US.UTF-8
    $ source ~/.bashrc
    因为我服务器的编码格式不是UTF-8,所以导致某些组件不能正确安装,所以要仔细看组件的启动个数,而且执行gitlab-ctl reconfigure之后的报错要挨个解决。

    4.启动gitlab-ce之后,修改ip地址并重新初始化配置:gitlab-ctl reconfigure
    [root@linux ~]#vim /etc/gitlab/gitlab.rb
      external_url 'http://192.168.0.6:8081' #这一行有初始值,把''里的初始域名改成我们要访问的也就是服务器的ip+端口
    [root@linux ~]#gitlab-ctl reconfigure
    这个时候我们访问http://192.168.0.6:8081应该可以看到以下界面

     如果不能访问,就需要去查看我们设置的端口(8081)是否开放.

    lsof -i tcp:8081

    如果没有返回内容,则有两种可能:
      1.gitlab-ctl status查看是否有组件未启动,按照之前的步骤重新初始化
      2.8081端口没有开放
        /etc/init.d/iptables status #查看iptable是否开放了8081,有这一条就证明没问题
        num  target     prot opt source               destination         
        1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8081
    如果没有开放
      /sbin/iptables -I INPUT -p tcp --dport 8081 -j ACCEPT #写入修改
      /etc/init.d/iptables save #保存修改
      service iptables restart #重启防火墙,修改生效

      再查看检查一下,确定端口没问题。

    gitlab常用命令

    sudo gitlab-ctl start    # 启动所有 gitlab 组件;
    sudo gitlab-ctl stop        # 停止所有 gitlab 组件;
    sudo gitlab-ctl restart        # 重启所有 gitlab 组件;
    sudo gitlab-ctl status        # 查看服务状态;
    sudo gitlab-ctl reconfigure        # 启动服务;
    sudo vim /etc/gitlab/gitlab.rb        # 修改默认的配置文件;
    gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
    sudo gitlab-ctl tail        # 查看日志;

    gitlab修改用户密码

    对于普通用户而言,系统可以重置密码,但是需要邮箱确认,如果当时的邮箱是随便填的,就需要在服务器端修改密码了。

    官方修改密码地址:https://docs.gitlab.com/ce/security/reset_root_password.html

    gitlab-rails console production
    user = User.where(id: 1).first #根据用户id来查找要修改密码的用户
    或者
    user = User.find_by(email: 'admin@local.host') #根据邮箱地址来查找要修改密码的用户
    user.password=12345678
    user.password_confirmation=12345678
    user.save!
    quit

    #注意,密码那里不能有引号
      
    人生短短数十载,经不起几次重头再来
  • 相关阅读:
    网页嵌入视频常用方式
    2.4 对字母数字的混合排序
    VC操作Image的三种方法(收集)
    VC 窗口出现白屏闪烁的解决办法
    Invalidate(TRUE)与Invalidate(FALSE)区别(前者会发送WM_ERASEBKGND消息全部刷新,然后使用WM_PAINT消息绘制,而后者只发送WM_PAINT消息)
    QT 文件拖放事件dropEvent和dragEnterEvent
    百用随身系统 Veket Linux
    C#通过属性名称获取(读取)属性值的方法
    搭建一个完整的Java开发环境
    XSD实例
  • 原文地址:https://www.cnblogs.com/bk770466199/p/10571086.html
Copyright © 2011-2022 走看看