操作系统:CentOS6.7
物理内存:4G
2G SWAP
GotLab版本:10.3.2-CE
(所有服务器上的配置均在root权限下操作)
一、基础环境搭建
1.安装软件依赖
yum install -y curl policycoreutils-python openssh-server cronie
2.配置主机名
cat << EOF > /etc/sysconfig/network NETWORKING=yes HOSTNAME=gitlab.example.com EOF
3.添加防火墙规则放行ssh和http服务用到的端口
lokkit -s http -s ssh
二、安装邮件服务器Postfix(可选)
yum install postfix service postfix start chkconfig postfix on
注:安装过程中在配置界面选择Internet Site,使用服务器的域名来配置mail name
如不想启用项目管理的邮件功能,可以跳过此步。
三、安装GitLab
1.离线安装GitLab
安装GitLab有很多办法,有直接安装的,有通过添加源在线安装的,有Docker、有VM镜像。。。
- 如果是为了研究学习,Docker和VM镜像是最好的选择
- 如果是生产环境部署,建议使用安装包部署在物理服务器上
本文以生产环境部署为背景,部署在物理服务器上。这里不建议使用官方Installation页面Recommended的安装方式,因为官方脚本里提供的源对国内来说速度很不友好,安装过程很痛苦,这里采用离线安装的方式。
首先在镜像站下载GitLab的安装包:
- gitlab-ce-10.3.2-ce.0.el6.x86_64.rpm
版本号因选择而异
下载安装包:
清华镜像站(推荐):
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/
官方镜像站:
https://packages.gitlab.com/gitlab/gitlab-ce
假设服务器的主机名/域名是gitlab.example.com,安装命令为:
EXTERNAL_URL="http://gitlab.example.com" rpm -i gitlab-ce-10.3.2-ce.0.el6.x86_64.rpm
正确安装后应有下列输出:
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
2.启动GitLab
gitlab的配置文件:/etc/gitlab/gitlab.rb
可以看情况修改其中的URL,port
正常情况下启动GitLab的命令为:
gitlab-ctl start
但因为是安装后第一次启动,配置文件需要初始化,第一次启动要执行:
gitlab-ctl reconfigure
稍候片刻就执行完成了。
gitlab-ctl start 启动
此时可以通过
netstat -lntp
查看进程占用端口情况,如果是按照上面的步骤全新安装,输出应类似如下:
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:9121 0.0.0.0:* LISTEN 46072/redis_exporte tcp 0 0 127.0.0.1:9090 0.0.0.0:* LISTEN 46354/prometheus tcp 0 0 127.0.0.1:9187 0.0.0.0:* LISTEN 46388/postgres_expo tcp 0 0 127.0.0.1:9100 0.0.0.0:* LISTEN 45935/node_exporter tcp 0 0 127.0.0.1:9229 0.0.0.0:* LISTEN 46310/gitlab-workho tcp 0 0 127.0.0.1:9168 0.0.0.0:* LISTEN 46342/ruby tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 45473/unicorn maste tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 45632/nginx tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 43821/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2064/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 8741/master tcp 0 0 0.0.0.0:8060 0.0.0.0:* LISTEN 45632/nginx tcp 0 0 ::1:9168 :::* LISTEN 46342/ruby tcp 0 0 :::22 :::* LISTEN 43821/sshd tcp 0 0 ::1:631 :::* LISTEN 2064/cupsd tcp 0 0 ::1:25 :::* LISTEN 8741/master
3.访问GitLab的WEB界面
如果服务器配置了域名,择可以直接访问域名;
如果服务器是在局域网内搭建,在客户端的主机上要配置服务器到主机名的映射:
服务器ip 服务器主机名
windows 10:
a.右键单击左下角窗口按钮,弹出菜单中选择“命令提示符(管理员)”
b.在命令行提示符键入:notepad drivers\etc\hosts
c.在打开的hosts文件中添加一行:(假设服务器的ip为192.168.10.168,主机名为 gitlab.example.com)
192.168.10.168 gitlab.example.com
保存并关闭
Most Linux OS:
执行:
cat << EOF >> /etc/hosts 192.168.10.168 gitlab.example.com EOF
打开浏览器,输入域名/ip,应能看到如下界面:
首次安装需要设置root密码。
用户名为root
密码就是刚才设置的密码。
作者:耗子在简书
链接:https://www.jianshu.com/p/a814b361aaf9
來源:简书