Loading

8.gitlab服务器搭建(基于centos7)

gitlab服务硬件要求
建议服务器最低配置:2核 2G以上内存(不包含2GB,2GB内存运行的时候内存直接爆掉)
官网给出的推荐配置:4核 4GB内存 支持500个用户,8核 8GB内存 支持1000个用户
文中使用的配置是2核5g
一、前置配置依赖
1.安装SSH协议
sudo yum install -y curl policycoreutils-python openssh-server
运行时如果提示/var/run/yum.pid已被锁定,删除重新安装解决该问题
sudo rm -f /var/run/yum.pid #删除
sudo yum -y install ntp #安装
 
2.设置SSH服务开机自启动
sudo systemctl enable sshd
 
3.安装防火墙
sudo yum install firewalld systemd -y
 
4.开启防火墙
sudo service firewalld start
 
5.添加http服务器到防火墙
sudo firewall-cmd --permanent --add-service=http 
sudo firewall-cmd --permanent --add-service=https
 
6.重启防火墙
sudo systemctl reload firewalld
 
7.安装邮件通知(可选)
sudo yum install postfix
将邮件通知设置为开机自启动
sudo systemctl enable postfix
启动 邮件
sudo systemctl start postfix
8.安装wget(如果已有无需安装)
sudo yum -y install wget
 
9.安装vim编辑器
sudo yum install vim -y
 
二、安装配置gitlab
配置镜像
curl -fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash
开始安装
sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-jh
修改gitlab配置文件
sudo vim /etc/gitlab/gitlab.rb #打开配置文件
 
external_url 'https://gitlab.example.com'# 找到该配置 external_url 'http://ip:port' #将ip地址和端口修改成我们的地址,注意端口号不要使用被占用的 
#centos的iP地址为ifconfig中的ens33条目中的inte值
将gitlab配置的端口添加到防火墙
firewall-cmd --zone=public --add-port=端口/tcp --permanent
重启防火墙
sudo systemctl reload firewalld
重置gitlab
sudo gitlab-ctl reconfigure 
#重置过程中如果报错
ruby_block[authorize Grafana with GitLab] (monitoring::grafana line 101) had an error: Mixlib::ShellOut::CommandTimeout: Command timed out after 600s:
Command exceeded allowed execution time, process terminated

是虚拟机设置的运行内存太行了,调整设置重新重置即可
重启gitlab
gitlab-ctl restart
 
访问gitlab
# 如果访问的时候502 可能是端口未开放或者端口被占用 
firewall-cmd --zone=public --add-port=端口/tcp --permanent  # 将gitlab服务器端口开放
firewall-cmd --reload #配置立即生效 
firewall-cmd --zone=public --list-ports #查看防火墙所有开放端口
通过配置的ip和端口访问gitlab服务
gitlab初始密码
sudo cat /etc/gitlab/initial_root_password # 服务安装初始化后,默认账号是root,初始密码存在在对应文件
#这个文件将在首次执行reconfigure后24小时自动删除,复制里面的密码登录后即时修改自己的账号密码
 
 
 
三、gitlab服务常用命令
gitlab-ctl start    # 启动所有 gitlab 组件;
gitlab-ctl stop        # 停止所有 gitlab 组件;
gitlab-ctl restart        # 重启所有 gitlab 组件;
gitlab-ctl status        # 查看服务状态;
vim /etc/gitlab/gitlab.rb        # 修改gitlab配置文件;
gitlab-ctl reconfigure        # 重新编译gitlab的配置;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
gitlab-ctl tail        # 查看日志;
gitlab-ctl tail nginx/gitlab_access.log

systemctl enable gitlab-runsvdir.service # 开机启动

systemctl disable gitlab-runsvdir.service # 禁止开机自启动

#如果启动失败 可以尝试以下或者sudo
sudo systemctl start gitlab-runsvdir
sudo gitlab-ctl restart
 

posted @ 2022-07-08 10:16  木子七  阅读(1004)  评论(0编辑  收藏  举报