美文网首页
CentOS 7 下 GitLab安装部署及汉化教程

CentOS 7 下 GitLab安装部署及汉化教程

作者: 我是哈斯 | 来源:发表于2019-08-09 15:34 被阅读0次

    一、前言

    1、GitLab是什么?

    GitLab一个开源的git仓库管理平台,方便团队协作开发、管理。在GitLab上可以实现完整的CI(持续集成)、CD(持续发布)流程。而且还提供了免费使用的Plan,以及免费的可以独立部署的社区版本(https://gitlab.com/gitlab-org/gitlab-ce )。
    官网:https://about.gitlab.com/

    2、本篇环境信息

    工具/环境 版本
    Linux Server CentOS 7
    GitLab 社区版 11.1.4

    二、准备工作

    1、安准基础依赖

    安装技术依赖

        sudo yum install -y curl policycoreutils-python openssh-server
    

    启动ssh服务&设置为开机启动

        sudo systemctl enable sshd
        sudo systemctl start sshd
    

    2、安装Postfix

    Postfix是一个邮件服务器,GitLab发送邮件需要用到
    安装postfix

        sudo yum install -y postfix
    

    启动postfix并设置为开机启动

        sudo systemctl enable postfix
        sudo systemctl start postfix
    

    3、开放ssh以及http服务(80端口)

    开放ssh、http服务

        sudo firewall-cmd --add-service=ssh --permanent
        sudo firewall-cmd --add-service=http --permanent
    

    重载防火墙规则

        sudo firewall-cmd --reload
    

    三、部署过程

    本次我们部署的是社区版:gitlab-ce,如果要部署商业版可以把关键字替换为:gitlab-ee

    1、Yum安装GitLab

    添加GitLab社区版Package

        curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
    

    安装GitLab社区版

        sudo yum install -y gitlab-ce
    

    2、或者下载对应版本手动安装

    添加gitlab镜像 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

        wget [https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm](https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm)
    

    安装gitlab 安装命令:

        rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
    

    如果出现下图,则说明安装成功。

    bbb.png

    3、配置GitLab站点Url

    GitLab默认的配置文件路径是 /etc/gitlab/gitlab.rb
    默认的站点Url配置项是: external_url 'http://gitlab.example.com'
    这里我将GitLab站点Url修改为 http://git.xxx.com 也可以用IP代替域名,这里根据自己需求来即可

    修改配置文件

        sudo vi /etc/gitlab/gitlab.rb
    

    配置首页地址(大约在第15行)

        external_url 'http://git.xxx.com'
    

    4、启动并访问GitLab

    • 启动GitLab

    重新配置并启动

        sudo gitlab-ctl reconfigure
    

    完成后将会看到如下输出

    Running handlers complete
    Chef Client finished, 432/613 resources updated in 03 minutes 43 seconds
    gitlab Reconfigured!
    

    重新启动

        sudo gitlab-ctl restart
    
    • 访问GitLab

    将设置的域名DNS解析到服务器IP,或者修改本地host将域名指向服务器IP。 访问:http://git.xxx.com

    eee.png
    这时候会提示为管理员账号设置密码。管理员账号默认username是root。

    设置完成之后即可使用root账号登录,登陆后会进入欢迎界面。

    ttt.png

    四、GitLab常用配置

    1、禁用创建组权限

    GitLab默认所有的注册用户都可以创建组。但对于团队来说,通常只会给Leader相关权限。
    虽然可以在用户管理界面取消权限,但毕竟不方便。我们可以通过配置GitLab默认禁用创建组权限。

    修改配置文件

        sudo vi /etc/gitlab/gitlab.rb
    

    开启gitlab_rails['gitlab_default_can_create_group'] 选项,并将值设置为false

    ### GitLab user privileges
    gitlab_rails['gitlab_default_can_create_group'] = false
    

    保存后,重新配置并启动GitLab

        sudo gitlab-ctl reconfigure
    

    2、gitlab-ctl常用命令介绍

    Gitlab命令分为两部分:通用命令 和服务管理命令
    通用命令:

    语法:gitlab-ctl 命令参数
    命令参数如下:

    命令 说明
    help 帮助
    reconfigure 修改配置文件之后,需要重新加载下
    show-config 查看所有服务配置文件信息
    uninstall 卸载这个软件
    cleanse 删除gitlab数据,重新白手起家

    服务管理命令:

    命令 说明
    start 启动所有服务
    stop 关闭所有服务
    restart 重启所有服务
    status 查看所有服务状态
    tail 查看日志信息
    service-list 列举所有启动服务
    graceful-kill 平稳停止一个服务

    五、汉化Gitlab

    Gitlab默认语言是英文,对于想加强英文的同学,建议继续使用英文,但要求使用中文,这里需要下载一个汉化包。

    下载最新的汉化包:

        [root@gitlab ~]# git clone https://gitlab.com/xhang/gitlab.git
    

    如果要下载指定版本的汉化包,需要加上版本号。
    例:下载10.5.1,命令如下:

        [root@gitlab ~]# git clone https://gitlab.com/xhang/gitlab.git  -b  v10.5.1-zh
    

    下载完成后,将下载的文件夹内容复制到gitlab目录下
    复制前先停止Gitlab

    [root@gitlab ~]# gitlab-ctl stop
    ok: down: gitaly: 0s, normally up
    ok: down: gitlab-monitor: 0s, normally up
    ok: down: gitlab-workhorse: 1s, normally up
    ok: down: logrotate: 0s, normally up
    ok: down: nginx: 1s, normally up
    ok: down: node-exporter: 0s, normally up
    ok: down: postgres-exporter: 1s, normally up
    ok: down: postgresql: 0s, normally up
    ok: down: prometheus: 0s, normally up
    ok: down: redis: 0s, normally up
    ok: down: redis-exporter: 1s, normally up
    ok: down: sidekiq: 0s, normally up
    ok: down: unicorn: 1s, normally up
    
    [root@gitlab ~]# cp -r -f  ./gitlab/*  /opt/gitlab/embedded/service/gitlab-rails/ 
    

    复制时可能不断提示是否要覆盖,这时可能是系统每次执行cp命令时,其实是执行了cp -i命令的别名。出现这种情况可以修改~/.bashrc,在“alias cp=’cp -i’”前加#注释,再刷新文件 source ~/.bashrc

    复制完成后,需要重新加载配置,并启动Gitlab

    [root@gitlab ~]# gitlab-ctl reconfigure      
    ...
    ... ...
    ... ... ...
    ... ... ... ...
    ...
    Running handlers:
    Running handlers complete
    Chef Client finished, 2/516 resources updated in 09 seconds
    gitlab Reconfigured!
    
    [root@gitlab ~]# gitlab-ctl restart
    ok: run: gitaly: (pid 42828) 0s
    ok: run: gitlab-monitor: (pid 42852) 0s
    ok: run: gitlab-workhorse: (pid 42858) 0s
    ok: run: logrotate: (pid 42867) 0s
    ok: run: nginx: (pid 42874) 0s
    ok: run: node-exporter: (pid 42879) 0s
    ok: run: postgres-exporter: (pid 42884) 1s
    ok: run: postgresql: (pid 42894) 0s
    ok: run: prometheus: (pid 42897) 0s
    ok: run: redis: (pid 42907) 0s
    ok: run: redis-exporter: (pid 42912) 1s
    ok: run: sidekiq: (pid 42997) 0s
    ok: run: unicorn: (pid 43007) 0s
    
    [root@gitlab ~]# lsof -i:80
    COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    nginx   42874       root    7u  IPv4 125185      0t0  TCP *:http (LISTEN)
    nginx   42875 gitlab-www    7u  IPv4 125185      0t0  TCP *:http (LISTEN)
    
    [root@gitlab web-demo]# lsof -i:8080
    COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    bundle  40358  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
    bundle  40650  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
    bundle  40652  git   18u  IPv4 119105      0t0  TCP localhost:webcache (LISTEN)
    

    再次访问web界面,显示的已经为汉化熟悉的中文

    相关文章

      网友评论

          本文标题:CentOS 7 下 GitLab安装部署及汉化教程

          本文链接:https://www.haomeiwen.com/subject/okzndctx.html