CentOS安装gitlab环境

环境准备:

centos 7
gitlab 10

安装依赖包

GitLab 10.x之后添加多了一些依赖,并且要启动sshd服务,所以我们先添加依赖,启动sshd,为防火墙添加服务

sudo yum install -y curl policycoreutils-python openssh-server openssh-clients 
sudo systemctl enable sshd 
sudo systemctl start sshd  

# 防火墙这2步可以不用管
# sudo firewall-cmd –permanent –add-service=http 
# sudo systemctl reload firewalld

postfix的产生是为了替代传统的sendmail.相较于sendmail,postfix在速度。性能和稳定性上都更胜一筹。
如今眼下许多的主流邮件服务事实上都在採用postfix. 当我们须要一个轻量级的的邮件server是,postfix不失为一种选择。

  • postfix想要作用的范围是广大的Internet用户。试图影响大多数的Internet上的电子邮件系统,因此它是免费的。
  • postfix在性能上大约比sendmail快三倍。一部执行postfix的台式PC每天能够收发上百万封邮件。
  • postfix是sendmail兼容的,从而使sendmail用户能够非常方便地迁移到postfix。Postfix支持/var[/spool]/mail、/etc/aliases、 NIS、和 ~/.forward 文件。
  • postfix被设计成在重负荷之下仍然能够正常工作。当处理的邮件数目增长时,postfix执行的进程不会跟着添加。
  • postfix是由超过一打的小程序组成的,每一个程序完毕特定的功能。

gitlab配置需要用到邮件发送,所以先安装postfix

yum -y install postfix

安装完之后,启动postfix

systemctl start postfix

启动过程中如果报错:Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.

解决办法,vim打开/etc/postfix/main.cf,修改如下两项,修改之前可以先备份下

image
# 修改 /etc/postfix/main.cf的设置  

inet_protocols = ipv4  
inet_interfaces = all  

修改完成后,再次启动,就不会报错了,设置postfix为开机自启动

systemctl enable postfix

查看启动状态,看到 Active: active (running) 就是已经正常启动了

[root@yoyo ~]# systemctl status postfix

完整的操作如下

[root@yoyo ~]# yum -y install policycoreutils-python openssh-server openssh-clients
[root@yoyo ~]# systemctl enable sshd 
[root@yoyo ~]# systemctl start sshd

[root@yoyo ~]# yum -y install postfix
[root@yoyo ~]# systemctl start postfix
Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.
[root@yoyo ~]# cp /etc/postfix/main.cf  /etc/postfix/main.cf.bak
[root@yoyo ~]# vim /etc/postfix/main.cf
# 修改inet_protocols = ipv4   和inet_interfaces = all  
[root@yoyo ~]# systemctl start postfix
[root@yoyo ~]# systemctl enable postfix
 [root@yoyo ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-01-15 15:37:28 CST; 5min ago
  Process: 3171 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 3167 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 3164 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 3244 (master)
   CGroup: /system.slice/postfix.service
           ├─3244 /usr/libexec/postfix/master -w
           ├─3245 pickup -l -t unix -u
           └─3246 qmgr -l -t unix -u

Jan 15 15:37:27 yoyo systemd[1]: Starting Postfix Mail Transport Agent...
Jan 15 15:37:28 yoyo postfix/postfix-script[3242]: starting the Postfix mail system
Jan 15 15:37:28 yoyo postfix/master[3244]: daemon started -- version 2.10.1, configuration /etc/postfix
Jan 15 15:37:28 yoyo systemd[1]: Started Postfix Mail Transport Agent.
[root@yoyo ~]# 

gitlab安装

centos 7系统的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

image

找个最新版去下载gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm

下载rpm包并安装

[root@yoyo ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
[root@yoyo ~]# mkdir /usr/local/gitlab
[root@yoyo ~]# mv gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm /usr/local/gitlab/
[root@yoyo ~]# cd /usr/local/gitlab/
[root@yoyo gitlab]# rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
error: Failed dependencies:
    policycoreutils-python is needed by gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

# 如果出现上面这个报错就执行yum install policycoreutils-python
[root@yoyo gitlab]# yum -y install policycoreutils-python

[root@yoyo gitlab]# rpm -i gitlab-ce-11.6.3-ce.0.el7.x86_64.rpm 
warning: gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

安装完成之后,会出现gitlab官方文档地址https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

配置并启动gitlab-ce

gitlab安装完成后,需要设置一个访问地址(或域名),打开/etc/gitlab/gitlab.rb,将默认的external_url = 'http://git.example.com'修改为自己的IP地址:http://xxx.xx.xxx.xx

[root@yoyo conf]# vim /etc/gitlab/gitlab.rb

原来默认的external_url

## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://git.example.com'

修改成自己定义的url地址,端口自己设置一个,别和已有的冲突了

## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://47.104.x.x:8100'

修改完成后:wq保存退出,执行以下命令,让配置生效

[root@yoyo conf]# gitlab-ctl reconfigure

启动Gitlab

[root@yoyo conf]# gitlab-ctl start

[root@yoyo ~]# gitlab-ctl start
ok: run: gitaly: (pid 6638) 186s
ok: run: gitlab-monitor: (pid 6656) 186s
ok: run: gitlab-workhorse: (pid 6659) 186s
ok: run: logrotate: (pid 6703) 185s
ok: run: nginx: (pid 6709) 185s
ok: run: node-exporter: (pid 6715) 184s
ok: run: postgres-exporter: (pid 6720) 184s
ok: run: postgresql: (pid 7324) 44s
ok: run: prometheus: (pid 6752) 171s
ok: run: redis: (pid 6761) 171s
ok: run: redis-exporter: (pid 6765) 170s
ok: run: sidekiq: (pid 7299) 45s
ok: run: unicorn: (pid 7476) 18s

启动完成后,在浏览器输入http://47.104.x.x:8100,就是gitlab的登录首页了,如果出现502页面,需修改默认的8080端口

502问题

打开gitlab首页出现502问题

image

出现这个问题,主要是因为8080端口被占用,之前安装tomcat默认的是8080端口,netstat -ntpl查看端口情况

[root@yoyo ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9100          0.0.0.0:*               LISTEN      6715/node_exporter       
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      801/java      
tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      6709/nginx: master  
tcp        0      0 127.0.0.1:9121          0.0.0.0:*               LISTEN      6765/redis_exporter 
tcp        0      0 127.0.0.1:9090          0.0.0.0:*               LISTEN      6752/prometheus     
tcp        0      0 127.0.0.1:9187          0.0.0.0:*               LISTEN      6720/postgres_expor 
tcp        0      0 0.0.0.0:8100            0.0.0.0:*               LISTEN      6709/nginx: master  
tcp        0      0 127.0.0.1:8101          0.0.0.0:*               LISTEN      7495/unicorn master 
tcp6       0      0 :::3306                 :::*                    LISTEN      1370/mysqld    

杀掉8080端口即可,8080端口对应的pip是801

[root@yoyo ~]# kill -9 801

重启下服务,刷新页面就可以访问了

[root@yoyo ~]# gitlab-ctl restart

为了避免8080端口冲突问题,可以修改下unicorn的默认端口,vim打开/etc/gitlab/gitlab.rb配置文件

新增一项unicorn['port'] = 8101,修改后内容如下

## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://47.104.x.x:8100'

unicorn['port'] = 8101

修改完成后:wq保存退出,执行gitlab-ctl reconfigure命令,让配置生效,再重新启动服务

[root@yoyo conf]# gitlab-ctl reconfigure
[root@yoyo conf]# gitlab-ctl stop
[root@yoyo conf]# gitlab-ctl start

接着在浏览器访问就能看的gitlab登录首页了

image

gitlab配置查看

gitlab的配置主要是etc/gitlab/gitlab.rb下的两个地方

external_url 'http://47.104.x.x:8100'

unicorn['port'] = 8101

查看更多配置信息可以,在/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml查看具体的详情

  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 47.104.x.x
    port: 8100
    https: false

相关操作

启动服务:gitlab-ctl start
查看状态:gitlab-ctl status
停掉服务:gitlab-ctl stop
重启服务:gitlab-ctl restart
让配置生效:gitlab-ctl reconfigure

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,636评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,890评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,680评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,766评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,665评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,045评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,515评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,182评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,334评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,274评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,319评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,002评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,599评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,675评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,917评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,309评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,885评论 2 341

推荐阅读更多精彩内容