Centos7.2上搭建Gitlab服务

目录
文章目录

  • 目录
      • 一、机器准备
      • 二、系统环境
      • 三、安装依赖及所需服务
        • 3.1 安装依赖
        • 3.2 安装sshd服务
        • 3.3 安装postfix邮件服务
      • 四、安装部署gitlab服务
        • 4.1 添加gitlab镜像
        • 4.2 安装gitlab
        • 4.3 修改gitlab配置文件指定服务器ip和自定义端口
        • 4.4 新配置gitlab,使刚刚改动的配置生效
        • 4.5 查看gitlab运行状态
        • 4.6 重新启动gitlab
        • 4.7 查看gitlab-ctl命令的帮助信息
      • 五、访问 GitLab页面

一、机器准备
服务器ip 主机名 系统版本
192.168.2.201 myhost Centos7.2
二、系统环境
[root@myhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@myhost ~]#firewall-cmd --state#查看防火墙的状态 running [root@myhost ~]#firewall-cmd --list-ports#查看防火墙已经开放的端口 [root@myhost ~]#firewall-cmd --list-services#查看防火墙开放的服务 dhcpv6-client ssh #httpd服务默认的端口是80,防火墙允许80/tcp端口访问 [root@myhost ~]#firewall-cmd --zone=public --permanent --add-port=80/tcp success [root@myhost ~]#firewall-cmd --reload#重新加载防火墙配置 success [root@myhost ~]#setenforce 0&&getenforce Permissive [root@myhost ~]#sed -i"s/SELINUX=enforcing/SELINUX=disabled/g"/etc/sysconfig/selinux

三、安装依赖及所需服务
3.1 安装依赖
[root@myhost ~]# yum install -y curlwget policycoreutils-python openssh-server

3.2 安装sshd服务 sshd一般系统是默认安装好的,不过也不排除一些最小安装的系统没有sshd服务。
[root@myhost ~]# systemctl status sshd#检查sshd服务运行状态 ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since 四 2020-08-13 11:41:49 CST; 2h 5min ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 48329 (sshd) CGroup: /system.slice/sshd.service └─48329 /usr/sbin/sshd -D8月 13 11:41:49 myhost systemd[1]: Starting OpenSSH server daemon... 8月 13 11:41:49 myhost sshd[48329]: Server listening on 0.0.0.0 port 22. 8月 13 11:41:49 myhost sshd[48329]: Server listening on :: port 22. 8月 13 11:41:49 myhost systemd[1]: Started OpenSSH server daemon. 8月 13 11:48:58 myhost sshd[74055]: Accepted publickey for root from 192.168.2.225 port 598...R+4Y 8月 13 12:31:36 myhost sshd[105008]: Accepted publickey for root from 192.168.2.225 port 59...R+4Y 8月 13 12:32:49 myhost sshd[105095]: Accepted publickey for root from 192.168.2.225 port 59...R+4Y Hint: Some lines were ellipsized, use -l to show in full. [root@myhost ~]# systemctl enable sshd#设置开机自启动

3.3 安装postfix邮件服务 当gitlab想要通过邮件通知,也可以另外配置其它的邮件服务器
[root@myhost ~]# yum install postfix [root@myhost ~]# systemctl enable postfix #设置开机自启动 [root@myhost ~]# systemctl start postfix #启动postfix服务 [root@myhost ~]# systemctl status postfix #检查postfix服务运行状态 ● postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled) Active: active (running) since 四 2020-08-13 13:50:50 CST; 38s ago Main PID: 107138 (master) CGroup: /system.slice/postfix.service ├─107138 /usr/libexec/postfix/master -w ├─107139 pickup -l -t unix -u └─107140 qmgr -l -t unix -u8月 13 13:50:49 myhost systemd[1]: Starting Postfix Mail Transport Agent... 8月 13 13:50:50 myhost postfix/postfix-script[107136]: starting the Postfix mail system 8月 13 13:50:50 myhost postfix/master[107138]: daemon started -- version 2.10.1, configurati...fix 8月 13 13:50:50 myhost systemd[1]: Started Postfix Mail Transport Agent. Hint: Some lines were ellipsized, use -l to show in full.

四、安装部署gitlab服务
4.1 添加gitlab镜像
[root@myhost ~]# cd /home/tools/ [root@myhost tools]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm [root@myhost tools]# ll 总用量 37426 -rw-r--r--. 1 root root 359519811 9月22 2017 gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

4.2 安装gitlab
[root@myhost tools]# rpm -ivh gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm

4.3 修改gitlab配置文件指定服务器ip和自定义端口 注意:这里设置的端口不能被占用,默认是8080端口,如果8080已经使用,请自定义其它端口,并在防火墙设置开放相对应得端口
[root@myhost tools]# vi /etc/gitlab/gitlab.rb 修改 external_url 'http://gitlab.example.com' 为: external_url 'http://localhost:80'

4.4 新配置gitlab,使刚刚改动的配置生效 重新配置gitlab,使刚刚改动的配置生效
[root@myhost tools]# gitlab-ctl reconfigure Starting Chef Client, version 12.12.15 resolving cookbooks for run list: ["gitlab"] Synchronizing Cookbooks: - gitlab (0.0.1) - package (0.1.0) - registry (0.1.0) - consul (0.0.0) - runit (0.14.2) Installing Cookbook Gems: Compiling Cookbooks... ... ... [root@myhost tools]# echo $? 0

4.5 查看gitlab运行状态
[root@myhost tools]#gitlab-ctl status run: gitaly: (pid 109308) 38s; run: log: (pid 108632) 96s run: gitlab-monitor: (pid 109345) 37s; run: log: (pid 109043) 69s run: gitlab-workhorse: (pid 109323) 37s; run: log: (pid 108744) 90s run: logrotate: (pid 108879) 81s; run: log: (pid 108878) 81s run: nginx: (pid 108814) 88s; run: log: (pid 108813) 88s run: node-exporter: (pid 108989) 75s; run: log: (pid 108988) 75s run: postgres-exporter: (pid 109405) 36s; run: log: (pid 109215) 56s run: postgresql: (pid 108297) 140s; run: log: (pid 108296) 140s run: prometheus: (pid 109390) 36s; run: log: (pid 109141) 62s run: redis: (pid 108174) 146s; run: log: (pid 108173) 146s run: redis-exporter: (pid 109085) 68s; run: log: (pid 109084) 68s run: sidekiq: (pid 108571) 102s; run: log: (pid 108570) 102s run: unicorn: (pid 108503) 104s; run: log: (pid 108502) 104s

4.6 重新启动gitlab
[root@myhost tools]# gitlab-ctl restart ok: run: gitaly: (pid 109647) 0s ok: run: gitlab-monitor: (pid 109656) 1s ok: run: gitlab-workhorse: (pid 109669) 0s ok: run: logrotate: (pid 109680) 0s ok: run: nginx: (pid 109721) 1s ok: run: node-exporter: (pid 109730) 0s ok: run: postgres-exporter: (pid 109736) 1s ok: run: postgresql: (pid 109751) 0s ok: run: prometheus: (pid 109759) 0s ok: run: redis: (pid 109770) 0s ok: run: redis-exporter: (pid 109774) 0s ok: run: sidekiq: (pid 109781) 0s ok: run: unicorn: (pid 109790) 1s

4.7 查看gitlab-ctl命令的帮助信息 gitlab-ctl --help
五、访问 GitLab页面
如果没有域名,直接输入设置的服务器ip和指定端口进行访问。打开浏览器查看效果,第一次打开页面会让我们设置root用户的密码。记住自己设置的密码,再次刷新进入登录页面。
访问地址:http://192.168.2.201:80/ 登录账号:root密码:xdsdfgghhy

【Centos7.2上搭建Gitlab服务】参考文档: https://www.cnblogs.com/zhangycun/p/10963094.html

    推荐阅读