一、GitLab 安装1.1 准备工作1.1.1 关闭防火墙关闭防火墙命令:iptables -F查看防火墙命令:iptables -L1.1.2 关闭SELinuxsed -i ’s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/configsetenforce 01.1.3 关闭NetworkManagersystemctl disable NetworkManager1.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 postfix1.1.5 启动sshd查看是sshd 是否启动: ps -ef | grep sshd如果未启动执行以下命令。执行命令:systemctl enable sshd执行命令:systemctl start sshd1.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.rpm1.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.txt3.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 。