centos6.0搭建gitlab环境

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

基本介绍

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

  git,github,gitlab之间的关系

    版本控制系统linux

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

        

 

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

        

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

              

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

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

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

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

    (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端口没有开放
    
    num  target     prot opt source               destination         
    1    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:8081 /etc/init.d/iptables status #查看iptable是否开放了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 productionuser = User.where(id: 1).first   #根据用户id来查找要修改密码的用户或者user = User.find_by(email: 'admin@local.host')  #根据邮箱地址来查找要修改密码的用户user.password=12345678user.password_confirmation=12345678user.save!quit#注意,密码那里不能有引号
相关文章
相关标签/搜索