前言: Gitlab对机器的要求比较高, 如果仅用于学习, 建议在本地跑虚拟机安装Gitlab; 如果用云服务器的话, 最好给服务器分配至少4G内存
以下是Gitlab的安装步骤
1. 先检查依赖: sshd
[root@localhost download]# rpm -qa|grep openssh-server
openssh-server-7.4p1-21.el7.x86_64
[root@localhost download]# ps -e|grep sshd
695 ? 00:00:00 sshd
3013 ? 00:00:00 sshd
3016 ? 00:00:00 sshd
如果没有的话, 需要安装该依赖:
yum install -y curl policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd
firewall-cmd --permanent --add-service=http
systemctl reload firewalld
PS: 因为我是root账号, 所以每行命令前不加sudo, 否则就要把sudo加上
2. 检查postfix是否安装
[root@localhost download]# rpm -qa|grep postfix
postfix-2.10.1-9.el7.x86_64
[root@localhost download]# ps -e|grep postfix
如果没有一样要先手动安装:
yum install postfix
systemctl enable postfix
systemctl start postfix
做完以上准备工作后, 开始准备下载安装Gitlab
Gitlab下载地址: https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
由于我是用vagrant安装CentOS, 所以可以通过在Vagrantfile添加一下配置让服务器内存增加到4G:
config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 2
end
3. 找到你要存放的软件的目录
(1) mkdir /usr/local/download # 创建download目录
(2) cd /usr/local/download
(3) wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.4.0-ce.0.el7.x86_64.rpm
通过以上步骤把Gitlab安装包下载下来
如果wget不能使用, 先通过yum install wget安装
4. 安装并配置GItlab
[root@localhost download]# (1) rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.4.0-ce.0.el7.x86_64.rpm #安装Gitlab
(2) vi /etc/gitlab/gitlab.rb # 编辑gitlab.rb文件
(3) external_url 'http://192.168.56.10' #找到external_url, 并配置成本机的ip地址
(4) gitlab-ctl reconfigure # 然后运行该命令, 这步执行时间比较久,如果最后执行失败,一般是机器配置不够
5. 安装成功之后重启
gitlab-ctl restart
6. 检查是否安装成功
netstat -tunlp # 查看端口占用
firewall-cmd --zone=public --list-ports # 查看防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
7. 访问Gitlab: http://192.168.56.10, 刚登登录时会让你重置密码, 用户名是root, 密码则是你设置的那个, 至此, Gitlab就可以使用了.
有些人可能因为某些步骤导致gitlab安装不成功, 那么该如何删除?
1. 停止gitlab
gitlab-ctl stop
2. 卸载gitlab
rpm -e gitlab-ce
3. 查看gitlab进程
ps -ef|grep gitlab # 杀掉第一个守护进程, 即: /opt/gitlab/service log
kill -9 4473 # 杀掉该进程, 4473是该进程的pid, 杀掉后需要查看gitlab进程是否还存在
4. 删除gitlab文件
find / -name *gitlab*|xargs rm -rf # 删除所有包含gitlab的文件及目录
find / -name gitlab |xargs rm -rf # 删除gitlab-ctl uninstall时自动在root下备份的配置文件
ls /root/gitlab* # 看看有没有,有也删除
通过以上几步就可以彻底卸载gitlab
用到的文档资料:
- 修改vagrant虚拟机内存配置: https://www.vagrantup.com/docs/providers/virtualbox/configuration.html
- 安装wget命令: https://www.php.cn/linux-419500.html