GitLab服务器安装配置手册

6次阅读

共计 2178 个字符,预计需要花费 6 分钟才能阅读完成。

一、GitLab 安装
1.1 准备工作
1.1.1 关闭防火墙
关闭防火墙命令:iptables -F
查看防火墙命令:iptables -L
1.1.2 关闭 SELinux
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
setenforce 0

1.1.3 关闭 NetworkManager
systemctl disable NetworkManager

1.1.4 安装 GetLab 依赖包
yum install -y curl policycoreutils policycoreutils-python openssh-server openssh-clients postfix

然后执行:systemctl restart 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 以下内容
inet_protocols = ipv4
inet_interfaces = all

执行命令:systemctl enable postfix
检查是否启动:ps -ef | grep postfix

1.1.5 启动 sshd
查看是 sshd 是否启动: ps -ef | grep sshd
如果未启动执行以下命令。
执行命令:systemctl enable sshd
执行命令:systemctl start sshd

1.2 GitLab 下载
1.2.1 下载地址
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.5.3-ce.0.el7.x86_64.rpm
1.2.2 解压
rpm -ivh gitlab-ce-11.5.3-ce.0.el7.x86_64.rpm

二、GitLab 配置
2.1 配置文件路径
vim /etc/gitlab/gitlab.rb 文件
2.2 配置域名地址
填写域名地址

2.3 修改 Git 库 SSH 链接默认端口号

2.4 邮件服务器配置
本示例参数配置为阿里云企业邮箱的配置

2.5 修改 Git 库 HTTP 链接默认端口号
2.5.1 文件路径
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
2.5.2 修改内容

修改完重启:gitlab-ctl restart
注意:GitLab 启动后才可执行此操作修改端口,不然提前修改会被配置文件覆盖!!!
三、GitLab 命令
3.1 GitLab 启动
配置文件配好后,先加载配置,第一次加载会比较慢。
加载配置命令:gitlab-ctl reconfigure
当加载完配置,启动 GitLab。
启动 Gitlab 命令:gitlab-ctl start
第一次打开 Gitlab 网站会让你设置 root 账号密码。

3.2 GitLab 常用命令
加载配置文件命令:gitlab-ctl reconfigure
启动 GitLab 命令:gitlab-ctl start
重启 GitLab 命令:gitlab-ctl restart
停止 GitLab 命令:gitlab-ctl stop
查看 GitLab 服务状态:gitlab-ctl status
查看 GitLab 版本号:head -1 /opt/gitlab/version-manifest.txt

3.3 GitLab 日志
查看日志命令:gitlab-ctl tail

四、GitLab 账户配置 SSH 密钥
4.1 本地密钥生成
密钥生成命令:ssh-keygen -t rsa -C “your.email@example.com” -b 4096
说明:-b 4096:b 是 bit 的缩写 4096 是密钥的长度,最小 768 位,默认 2048 位

4.2 查看本地密钥
id_rsa 是私钥,id_rsa.pub 是公钥,Linux 和 Windonws 文件路径分别为:
Linux:

Windonws:

4.3 配置密钥

返回 GitLab 项目库,复制 git 库 SSH 链接。

使用 git 克隆命令, 用 ssh 下载项目。

五、GitLab 汉化
5.1 下载最新的汉化包
git clone https://gitlab.com/xhang/gitlab.git
如果要下载指定版本的汉化包,需要加上版本号。例:下载 11.0.6,命令如下:
git clone https://gitlab.com/xhang/gitlab.git -b v11.0.6-zh
在汉化之前要先停止 GitLab,命令:gitlab-ctl stop。
5.2 汉化文件覆盖
cp -r -f ./gitlab/* /opt/gitlab/embedded/service/gitlab-rails/
这里有个坑,复制覆盖的时候你要按 N 多个 Y,用其他的方法也比较麻烦,在 cp 前边加个反斜杠就搞定了
\cp -r -f ./gitlab/* /opt/gitlab/embedded/service/gitlab-rails/
复制完成后重新加载配置,命令:gitlab-ctl reconfigure,并启动 GitLab,命令:gitlab-ctl start。

正文完
 0