`
ssydxa219
  • 浏览: 609042 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

gitlab安装使用

 
阅读更多
第一步,查看Linux版本信息。

查看Linux系统的版本信息
命令:cat /proc/version

查看Linux系统发行版信息
命令:cat /etc/redhat-release

第二步,安装依赖包。

yum install -y policycoreutils openssh-server openssh-clients postfix

systemctl enable sshd

systemctl start sshd

systemctl enable postfix

systemctl start postfix

第三步,下载并安装rpm包。

方法一:通过rpm包进行安装。(一般选择这种方法)

不同版本的Linux对应不同的rpm包。

若Linux版本为Centos 7,则需要下载el7版本的GitLab。

下载el7版本的GitLab,登录网址:

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/



https://packages.gitlab.com/app/gitlab/gitlab-ce/search

下载el7版本rpm
命令:cd /usr/local/rpm

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.0.0-ce.0.el7.x86_64.rpm

或 wget https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-15.0.0-ce.0.el7.x86_64.rpm/download.rpm

chown -R git:git /usr/local/rpm

rpm -ivh gitlab-ce-15.0.0-ce.0.el7.x86_64.rpm

若结果显示“policycoreutils-python is needed by gitlab-ce”,则说明运行出现错误。又因为Linux版本为Centos 7,GitLab版本为el7,所以可以使用命令“yum install policycoreutils-python”来解决这个问题。若使用上述命令无效,则说明Linux版本一定不是centos 7。然后重新安装GitLab。

若Linux版本为Alibaba Cloud Linux 3,则需要下载el8版本的GitLab。

下载el8版本的GitLab,登录网址:

https://packages.gitlab.com/app/gitlab/gitlab-ce/search,搜索下载gitlab-ce-15.0.0-ce.0.el8安装包,然后使用WinSCP将下载的安装包上传到/usr/local/rpm文件夹中。

将/usr/local/rpm的所有者及所属组改为git,然后安装gitlab
命令:cd /usr/local/rpm

chown -R git:git /usr/local/rpm

rpm -ivh gitlab-ce-15.0.0-ce.0.el8.x86_64.rpm

若结果显示“policycoreutils-python-utils is needed by gitlab-ce”,则说明运行出现错误。又因为Linux版本为Alibaba Cloud Linux 3,GitLab版本为el8,所以可以使用命令“yum install policycoreutils-python-utils”来解决这个问题。

方法二:通过yum源安装。

新建/etc/yum.repos.d/gitlab-ce.repo文件,并在文件中写入下面的代码:

[gitlab-ce] name=gitlab-ce baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 Repo_gpgcheck=0 Enabled=1 Gpgkey=https://packages.gitlab.com/gpg.key

更新本地yum缓存
命令:yum makecache

安装GitLab社区版
命令:yum install gitlab-ce #自动安装最新版

或 yum install gitlab-ce-x.x.x #安装指定版本

第四步,修改配置文件。

1)修改配置文件 vim /etc/gitlab/gitlab.rb ,在文件中做如下修改:

把网址改为服务器公网IP(默认IP为8080,若8080已经使用,自定义其它端口),这个IP一定要在阿里云上进行授权配置。
external_url 'http://192.168.0.111:8080' 2)确保防火墙启动成功

命令:systemctl status firewalld

若结果显示“Active: inactive (dead)”,则需要启动防火墙。

systemctl start firewalld

若结果显示“Active: active (running)”,则可以运行下面的命令:

sudo firewall-cmd --permanent --add-service=http

sudo firewall-cmd --permanent --add-service=https

sudo systemctl reload firewalld

若结果都显示“success”,则说明防火墙启动成功。

3)把GitLab的端口号放开

firewall-cmd --zone=public --add-port=80/tcp --permanent

若结果显示“success”,则说明GitLab的端口号成功放开。

systemctl restart gitlab-runsvdir.service

4)重新加载并启动

命令:gitlab-ctl reconfigure

若结果显示“ruby_block[supervise_redis_sleep] action run”,则会一直卡无法往下进行,这时需要按住“CTRL+C”强制结束, 然后运行命令“sudo systemctl restart gitlab-runsvdir /opt/gitlab/embedded/bin/runsvdir-start ”,最后再次执行命令“sudo gitlab-ctl reconfigure”。

gitlab-ctl restart

若结果显示“ok: run”,则说明配置文件修改完成。

GitLab常用命令 gitlab-ctl start # 启动所有GitLab组件

gitlab-ctl stop # 停止所有GitLab组件

gitlab-ctl restart # 重启所有GitLab组件

gitlab-ctl status # 查看服务状态

gitlab-ctl reconfigure # 启动服务

gitlab-rake gitlab:check SANITIZE=true --trace # 检查GitLab

gitlab-ctl tail # 查看日志

1)GitLab的守护进程关闭和重启

备注:GitLab的守护进程会默认开启nginx
命令:gitlab-ctl stop nginx

gitlab-ctl restart nginx

释放资源,关闭GitLab
命令:gitlab-ctl stop

2)服务器重启或者GitLab意外停止,执行命令“gitlab-ctl start”。

若结果显示“fail: sidekiq: runsv not running”等,则说明GitLab不能启动。可以使用下面命令来解决这个问题:

systemctl start gitlab-runsvdir

gitlab-ctl restart

GitLab使用 在浏览器的地址栏中输入ECS服务器的公网IP(GitLab的ip和端口号),无法访问。

第一步,linux系统开放GitLab的端口号。

命令:cd /etc/sysconfig

ls -l

结果显示“ip6tables-config”和“iptables-config”,但是没有查看到iptables文件。

第二步,安装iptables-services。

命令:yum install iptables-services

第三步,启动iptables。

命令:systemctl enable iptables

systemctl start iptables

第四步,在iptables中配置开放GitLab的端口号。

命令:vim /etc/sysconfig/iptables

在文件中添加下面的代码:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 第五步,重启防火墙。

命令:service iptables restart

第六步,重新登录GitLab。

在浏览器的地址栏中输入ECS服务器的公网IP(GitLab的ip和端口号),登录GitLab的界面,第一次登录使用的用户名为 root,而密码在文件/etc/gitlab/initial_root_password中(密码不会含空格),且会在 24 小时后自动被删除。然后修改密码即可。

第七步,登录GitLab时界面显示“502”。

这个一般是权限问题,可以给予GitLab权限。

命令:chmod -R 755 /var/log/gitlab

创建Project 第一步,安装Git工具。

在linux中安装Git,使用自带的源安装。

命令:yum install git

第二步,生成密钥文件。

使用ssh-keygen生成密钥文件.ssh/id_rsa.pub。

命令:ssh-keygen #连续回车四下

cat .ssh/id_rsa.pub #结果显示生成的秘钥

第三步,在GitLab的主页中新建一个Project。

点击“新建Project”,在“Blank Project”栏目中,填写“Project name”,“Project URL”和“Project slug”,其他默认,最后点击“创建Project”。

第四步,添加ssh key导入第二步中生成的密钥文件内容。

点击“添加ssh key”,然后在“key”中复制粘贴刚刚生成的秘钥,最后点击“添加key”。

项目地址在进行clone操作时需要用到。

卸载

如果gitlab安装失败,那可以卸载gitlab并重装。注意:gitlab一定要卸载干净,否则会有不少麻烦。

第一步,停服务。

命令:sudo gitlab-ctl stop

第二步,卸载gitlab。(需确认gitlab是ce版本还是ee版本)

命令:sudo rpm -e gitlab-ce

第三步,杀掉gitlab守护进程。(带有opt/gitlab/service log)

命令:ps -ef|grep gitlab

sudo kill -9 [PID]

第四步,删除磁盘文件。

命令:sudo find / -name gitlab |xargs rm -rf

若结果提示“permission deny”,则手动逐层删除即可。

第五步,下载的gitlab软件包也删除。 当然若你没有全杀权限。那么可以可以把这三个目录给干掉也可以:

rm -rf /opt/gitlab rm -rf /etc/gitlab rm -rf /var/log/gitlab

1.下载 根据服务器操作系统版本,下载对应的RPM包。

gitlab官网: The DevSecOps Platform | GitLab

rpm包官网下载地址: gitlab/gitlab-ce - Results in gitlab/gitlab-ce

国内镜像地址: Index of /gitlab-ce/yum/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

2.安装 安装命令如下:

rpm -ivh gitlab-ce-16.4.3-ce.0.el7.x86_64.rpm 安装完成截图如下:

3.配置 打开/etc/gitlab/gitlab.rb文件, 修改 external_url 为服务器本地IP地址

vim /etc/gitlab/gitlab.rb 将 external_url 'http://gitlab.example.com

修改为: external_url 'http://10.54.183.53'

其中10.54.183.53为服务器本地IP地址

4.启动 运行重新配置命令 gitlab-ctl reconfigure 配置完成截图:

查看运行状态: gitlab-ctl status 截图如下:

启动gitlab gitlab-ctl start

5.登录 查看临时密码: 打开 /etc/gitlab/initial_root_password文件, 查看 Password

cat /etc/gitlab/initial_root_password 截图如下:

打开浏览器输入网址 http://10.54.183.53/

通过root用户和上面文件中的临时密码登录

成功登录页面:

————————————————------------------------------------------------------------

安装gitlab 1.更新本地缓存 sudo yum makecache 2.安装gitlab sudo yum install -y gitlab-ce 3.修改拉代码的地址换成自己的ip和端口 vim /etc/gitlab/gitlab.rb

external_url 'http://127.0.0.1:8099' 4.刷新配置(会执行更多文件) gitlab-ctl reconfigure 若卡在ruby_block[wait for logrotate service socket] action run 当前的的窗口不要关闭不要退出,另外开启一个终端启动如下命令

sudo /opt/gitlab/embedded/bin/runsvdir-start 5.启动gitlab sudo gitlab-ctl start 6.设置开机启动 systemctl enable gitlab-runsvdir.service 7.查看root用户密码并去更改(24后小时消失并失效) cat /etc/gitlab/initial_root_password

ARNING: This value is valid only in the following conditions

1. If provided manually (either via GITLAB_ROOT_PASSWORD environment variable or via gitlab_rails['initial_root_password'] setting in gitlab.rb, it was provided before database was seeded for the first time (usually, the first reconfigure run).
2. Password hasn't been changed manually, either via UI or via command line.
If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: i02Mu/O/Df2Cy30TsXIXDHiXGjWHL/LzrLCoMlqdmsg=

NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.
8.浏览器打开之前配置的http://127.0.0.1:8099 常用命令 find / -name gitlab | xargs rm -rf # 删除所有包含gitlab文件 sudo gitlab-ctl start # 启动所有 gitlab 组件; sudo gitlab-ctl stop # 停止所有 gitlab 组件; sudo gitlab-ctl restart # 重启所有 gitlab 组件; sudo gitlab-ctl status # 查看服务状态; systemctl enable gitlab-runsvdir.service #开机启动 systemctl disable gitlab-runsvdir.service #禁止开机自启动 卸载gitlab 1、停止gitlab gitlab-ctl stop 2、卸载gitlab rpm -e gitlab-ce 3、查看gitlab进程 ps aux | grep gitlab 4、杀掉第一个进程 kill -9 82507 (82507 是第一个进程的pid号,根据显示情况输入) 杀掉后,在ps aux | grep gitlab确认一遍,还有没有gitlab的进程 如果还有进程请用以下命令杀死所有进程

ps -ef | grep gitlab | xargs kill -s 9 5、删除所有包含gitlab文件 find / -name gitlab | xargs rm -rf

502问题:

proxy_buffer_size 128k proxy_buffers 4 256k proxy_busy_buffers_size 256k

netstat -anp |grep 8888
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics