gitlab本地Centos 7 服务器搭建

gitlab本地Centos 7 服务器搭建

安装gitlab:

  1. 安装ssh
  1. sudo yum install -y curl policycoreutils-python openssh-server
  2. 将SSH服务设置成开机自启动,安装命令:sudo systemctl enable sshd
  3. 启动SSH服务,安装命令:sudo systemctl start sshd
  1. 安装防火墙
  1. sudo yum install firewalld systemd -y
  2. 开启防火墙,安装命令:sudo service firewalld start
  3. 添加http服务到firewalld,pemmanent表示永久生效,若不加–permanent系统下次启动后就会失效: sudo firewall-cmd --permanent --add-service=http
  4. 重启防火墙,安装命令:sudo systemctl reload firewalld
  1. 安装postfix
  1. sudo yum install postfix
  2. 启动postfix,安装命令:sudo systemctl start postfix
  1. 安装gitlab

方法一:

  1. 去https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 下载不同版本的gitlab
  2. 安装:sudo rpm -i gitlab-ce-14.2.0-ce.0.el7.x86_64.rpm, 如果出现:Thank you for installing GitLab 就说明安装成功了
    方法二:
  3. curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
  4. sudo yum install gitlab-ce -y
  1. 配置并启动gitlab

sudo gitlab-ctl reconfigure (如果设备配置比较低, 会在启动过程中卡死, 建议最低双核2G内存, 如果当前服务器的80和8080端口均未被占用, 则直接可以通过服务器的ip或域名访问到后台)
问题一:

  1. 卡在 execute[systemctl start gitlab-runsvdir] action run 不动
    解决:
  2. 可以先尝试用:sudo systemctl start gitlab-runsvdir.service
  3. 如果还是不动的话,就需要查看系统服务项了:sudo systemctl -t target (如果系统正常的话,所有任务应该是loaded active active,如果存在inactive dead选型,意味着有些服务出错了。)
  4. 查看系统任务:sudo systemctl list-jobs (如果存在某个任务是running,则是该任务堵塞了其他所有服务)
  5. 结束这个running的任务:sudo systemctl stop xxx.service
  6. 重新gitlab service启动:sudo systemctl start gitlab-runsvdir.service
  7. 重启配置文件: sudo gitlab-ctl reconfigure
  1. 获取/修改超级管理员root的密码
#切换目录:
cd /opt/gitlab/bin
#执行 :下方 命令 开始初始化密码
sudo gitlab-rails console -e production
#在irb(main):001:0> 后面通过 u=User.where(id:1).first 来查找与切换账号(User.all 可以查看所有用户)
u=User.where(id:1).first
#通过u.password='12345678'设置密码为12345678(这里的密码看自己喜欢):
u.password='12345678'
#通过u.password_confirmation='12345678' 再次确认密码
u.password_confirmation='12345678'
#通过 u.save!进行保存(切记切记 后面的 !)
u.save!
#如果看到显示为true ,恭喜你已经成功了,执行 exit 退出当前设置流程即可。
exit
# 重启gitlab
sudo gitlab-ctl restart
  1. 登录gitlab
  1. 如果没有修改配置文件/etc/gitlab/gitlab.rb, 默认网站是:http://localhost:8080 或者 http://localhost:80
  2. 账户:root, 密码:12345678 (自己设定的)

服务管理

  1. 查看服务状态:gitlab-ctl status
  2. 开启服务: gitlab-ctl start
  3. 关闭服务:gitlab-ctl stop
  4. 重启服务:gitlab-ctl restart
  5. 关闭gitlab的自动启动 :systemctl disable gitlab-runsvdir.service
  6. 开启gitlab的自动启动:
  1. systemctl enable gitlab-runsvdir.service
  2. systemctl start gitlab-runsvdir.service
  3. gitlab-cmd start

配置gitlab功能

官网配置介绍:https://docs.gitlab.com/omnibus/settings/

修改访问url

  1. sudo vim /etc/gitlab/gitlab.rb : 找到关键字:external_url ‘http://localhost:9090’
  2. sudo gitlab-ctl reconfigure #重新编译gitlab.rb文件,使用做的修改生效

更改gitlab仓库存储位置

默认时GitLab的仓库存储位置在“/var/opt/gitlab/git-data/repositories”
这里规划把数据存放在“/data/git-data”目录下

1. sudo mkdir -pv /data/git-data 
2. sudo chown -R git.git /data/git-data  #修改创建目录的属主和属组为git用户
3. sudo cp /etc/gitlab/gitlab.rb /etc/gitlab/gitlab.rb.bak # 做一个备份
4. sudo vim /etc/gitlab/gitlab.rb 
	1. 启用git_data_dirs参数,并修改如下:
	git_data_dirs({
       "default" => {
         "path" => "/data/git-data",
         "failure_count_threshold" => 10,
         "failure_wait_time" => 30,
         "failure_reset_time" => 1800,
         "failure_timeout" => 30
        }
     })
在gitlab里面没有项目的时候可以直接使用下面使之生效     
	1. sudo gitlab-ctl reconfigure  #重新编译gitlab.rb文件,使用做的修改生效  
	2. ls -ld /data/git-data/repositories/  # 查看结果
否则:
	1. sudo gitlab-ctl stop
	2. sudo rsync -av /var/opt/gitlab/git-data/repositories /data/git-data/
	3. sudo gitlab-ctl reconfigure
	4. ls -ld /data/git-data/repositories/
	5. sudo gitlab-ctl start
	6. 正常之后删除原来数据:sudo rm -rf /var/opt/gitlab/git-data/repositories

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值