• 发文
  • 评论
  • 微博
  • 空间
  • 微信

Linux 环境下安装 GitLab 与配置

Python进阶学习交流 2019-05-16 22:13 发文


什么是 GitLab?

GitLab 是一个用于仓库管理系统的开源项目,使用 Git 作为代码管理工具,并在此基础上搭建起来的 web 服务。

GitLab的功能特点

提供了管理,计划,创建,验证,打包,发布,配置,监视和保护应用程序的功能 是一个在线代码仓库托管软件,是提供代码托管、提交审核和问题跟踪的代码管理平台

对服务器的要求:配置建议CPU2核心,内存4G以上Git、GitLab、GitHub三者的区别

Git 基于命令的版本操作,全命令操作,无可视化界面;

Gitlab 基于 Git 实现的在线代码仓库软件,提供了 web 的管理界面,用于企业内部;

Github 基于 Git 实现的在线代码仓库软件,提供了可视化管理界面,提供开放和私有的仓库。大部分开源项目选择 Github 作为代码托管仓库;

服务组成部分

nginx:静态web服务器:端口号为80;

gitlab-shell:用于处理 git 命令和修改 authorized key 列表;

gitlab-workhorse:轻量级反向代理服务器(go语言);

gitlab-workhorse 是一个敏捷的反向代理,它会处理一些大的 HTTP 请求,比如文件上传、下载,git

push/pull 和 git 包下载,其他请求会反向代理到 gitlab rails 应用,即反向按代理给后端的unicorn;

logrotate:日志文件管理工具;

postgresql:数据库;

reids:缓存数据库;

sidekiq:用于在后台执行队列任务(异步执行) (ruby);

unicorn:用ruby编写的一个HTTP服务器:端口号为8080;

gitlab rails应用:是托管在这个服务器上

功能介绍

基于web方式的管理平台;

拥有完善的权限的控制和身份认证模块;

问题追踪和代码质量管理;

代码review(复查)功能;

文档管理、知识库管理;

安装 GitLab 的步骤[root@localhost ~]# ls /var/cache/yum/x86_64/$releasever/gitlab_gitlab-ce/packages/     //从网络上yum下载的包的位置[root@localhost ~]# yum install -y curl openssh-server openssh-clients cronie policycoreutils-python postfix     //安装依赖包[root@localhost ~]# curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash   //下载gitlab的yum(仓库)源,sudo用于提权(适用于普通用户)[root@localhost ~]# yum list | grep gitlab-ce           //查看是否有gitlab-cegitlab-ce.x86_64                        11.7.5-ce.0.el7            gitlabgitlab-ce[root@localhost ~]# yum -y install gitlab-ce        //安装gitlab-ce [root@localhost ~]# ls /var/cache/yum/x86_64/$releasever/gitlab_gitlab-ce/packages/     //从网络上yum下载的包的位置
###设置URL[root@localhost ~]# vim /etc/gitlab/gitlab.rb  //修改一个URL地址  external_url 'http://gitlab.bdqn.cn'[root@localhost ~]# vim /etc/hosts  //编辑一个域名解析  192.168.1.21    gitlab.bdqn.cn[root@localhost ~]# gitlab-ctl reconfigure   //重新配置gitlab的配置文件
[root@localhost ~]# gitlab-ctl start   //启动gitlab服务ok: run: alertmanager: (pid 5151) 363sok: run: gitaly: (pid 4934) 368sok: run: gitlab-monitor: (pid 5070) 366sok: run: gitlab-workhorse: (pid 4897) 370sok: run: logrotate: (pid 4120) 416sok: run: nginx: (pid 4071) 418sok: run: node-exporter: (pid 4974) 367sok: run: postgres-exporter: (pid 5178) 362sok: run: postgresql: (pid 3564) 458sok: run: prometheus: (pid 5111) 364sok: run: redis: (pid 3420) 464sok: run: redis-exporter: (pid 5090) 365sok: run: sidekiq: (pid 3934) 430sok: run: unicorn: (pid 3862) 431s[root@localhost ~]# gitlab-ctl restart          //重新启动gitlab服务[root@localhost ~]# free -m    //查看运行内存[root@localhost ~]# firefox gitlab.bdqn.cn   //查看gitlab页面,或者使用ip地址访问[root@localhost ~]# firefox 192.168.1.21

gitlab页面的出现的问题; 检测端口号80和8080是否被占用;
访问主页502的时候,看一下端口号8080是否被占用

gitlab相关命令gitlab-ctl start       //启动gitlab服务gitlab-ctl stop        //停止gitlab服务gitlab-ctl start unicorn(添加组件名称)   //单独开启某个组件gitlab-ctl status        //查看gitlab的运行状态gitlab-ctl reconfigure    //修改完配置文件重新编译gitlab-ctl tail       //查看gitlab的日志


配置 GitLab 邮件服务

sendmail /postfix /smtp
古老邮箱 邮件服务服务器 在线邮箱

配置smtp邮箱步骤


###修改配置文件[root@localhost ~]# vim /etc/gitlab/gitlab.rb gitlab_rails['gitlab_email_from'] = 'bm73333@163.com'   //说明邮箱从哪里发,设置自己的邮箱地址 #ctrl+v 进入可视块 +x gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.163.com" //在线邮件服务器地址 gitlab_rails['smtp_port'] = 25   //端口号,开启本地发邮件的端口 gitlab_rails['smtp_user_name'] = "bm73333@163.com"  //邮箱地址 gitlab_rails['smtp_password'] = "qwerty567890"  //邮箱授权码,调用邮箱 ###邮箱授权码的获取 设置  POP3/SMTP/IMAP 客户端授权密码,在里面就可以设置授权码  gitlab_rails['smtp_domain'] = "163.com" gitlab_rails['smtp_authentication'] = "login"   //在登录时,查看是否有授权码 gitlab_rails['smtp_enable_starttls_auto'] = true   //加密方式 gitlab_rails['smtp_tls'] = false    //加密方式
 user['git_user_email'] = "bm73333@163.com"###修改完成
重新编译配置文件[root@localhost ~]# gitlab-ctl reconfigure重启gitlab服务[root@localhost ~]# gitlab-ctl restart进入控制台[root@localhost ~]# gitlab-rails console------------------------------------------------------------------------------------- GitLab:       11.7.5 (c5b5b18) GitLab Shell: 8.4.4 postgresql:   9.6.11-------------------------------------------------------------------------------------Loading production environment (Rails 5.0.7.1)irb(main):001:0> Notify.test_email('18256001006@163.com','yangxiaofeiNB','hello,world!').deliver_now  //发送邮件,deliver_now代表立刻发送(格式:收件人的邮箱地址,邮件标题,邮件内容)irb(main):003:0> exit   //退出控制台


GitLab 的日常操作gitlab的备份
[root@localhost ~]# gitlab-rake gitlab:backup:create    //gitlab的备份
备份的数据的目录
[root@localhost ~]# ls /var/opt/gitlab/backups/
1550541218_2019_02_19_11.7.5_gitlab_backup.tar   //备份完成后会形成tar包,文件名格式:时间戳,当前日期,当前gitlab版本,backup备份包恢复数据的步骤首先停止一下两个组件[root@localhost ~]# gitlab-ctl stop sidekiqok: down: sidekiq: 0s, normally up[root@localhost ~]# gitlab-ctl stop unicornok: down: unicorn: 0s, normally up
切换到备份目录[root@localhost ~]# cd /var/opt/gitlab/backups/[root@localhost backups]# ls1550541218_2019_02_19_11.7.5_gitlab_backup.tar[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1550541218_2019_02_19_11.7.5   //进行数据的恢复,名字为上面的时间戳,日期,版本号组成出现以下提示Do you want to continue (yes/no)? yesDo you want to continue (yes/no)? yes[root@localhost backups]# gitlab-ctl start sidekiq  //启动组件服务ok: run: sidekiq: (pid 19474) 0s[root@localhost backups]# gitlab-ctl start unicorn  //启动组件服务ok: run: unicorn: (pid 19536) 1s数据恢复完成

访问gitlab的web页面
http://gitlab.bdqn.com 或者 http://localhost 的 ip 地址

进入控制台的两种方法


1、[root@localhost ~]# gitlab-rails console   //进入控制台------------------------------------------------------------------------------------- GitLab:       11.7.5 (c5b5b18) GitLab Shell: 8.4.4 postgresql:   9.6.11-------------------------------------------------------------------------------------Loading production environment (Rails 5.0.7.1)  //加载生产环境irb(main):001:0>#2、[root@localhost ~]# gitlab-rails console production------------------------------------------------------------------------------------- GitLab:       11.7.5 (c5b5b18) GitLab Shell: 8.4.4 postgresql:   9.6.11-------------------------------------------------------------------------------------Loading production environment (Rails 5.0.7.1)irb(main):001:0>忘记 root 密码,进行修改[root@localhost ~]# gitlab-rails console production------------------------------------------------------------------------------------- GitLab:       11.7.5 (c5b5b18) GitLab Shell: 8.4.4 postgresql:   9.6.11-------------------------------------------------------------------------------------Loading production environment (Rails 5.0.7.1)irb(main):001:0> user = User.where(id:1).first   //切换到root用户=> #<User id:1 @root>    irb(main):002:0> user.password='1234.com'   //''里面修改密码,密码为8位=> "1234.com"irb(main):003:0> user.save!Enqueued ActionMailer::DeliveryJob (Job ID: 7661b452-fcb4-48a0-b9f0-35995ba21258) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f4360748a10 @uri=#<URI::GID gid://gitlab/User/1>>=> trueirb(main):004:0> exit
验证是都修改成功,使用web进行登录测试##至此修改完成查看 GitLab 的日志[root@localhost ~]# gitlab-ctl tail   //查看整体的日志查看组件的相关日志[root@localhost ~]# gitlab-ctl tail redis   //查看redis的日志[root@localhost ~]# gitlab-ctl tail logrotate通过 ssh 远程连接方式往 GitLab 上传文件查看密钥[root@localhost ~]# ssh-keygen -t rsa -C "zhangsan@bdqn.cn"  //为创建用户时输入的邮箱地址[root@localhost .ssh]# pwd /root/.ssh[root@localhost .ssh]# lsid_rsa  id_rsa.pub[root@localhost .ssh]# cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDG+woCe7UsBcXhU/I5hRZ0B7fzOOzzGsYzm1+qSvxn1SRaWQ53TNfWJJKpmamodHDI0IWHld6MI+2IB5bSXobNjrV1W147m34fE3KZZ4Kx9wwQ89UnUzqREIPDHnTLozHOE36AxGh6pREFawMjxJJjzd6d3xC9PM9bQ3KaY80agGY44N1vO6c+Turfkpyre3fyITudEqPlrCibJF9eikXgFhHNtrrWVAII6LUKU89LNfXKKYfOmXvB+T+ZYODkXqPR5GPCz4IIuGd5fxpfAmnTvm+Sz3Dp5APVSmveEx9ivtRVsb5lqlYoXJT1vL+D9dQKFY7HI8/FttOSduQNLfrv 45354066@qq.com复制密钥,到web页面进行添加密钥
验证远程登录是否成功[root@localhost .ssh]# ssh -T git@gitlab.bdqn.cnThe authenticity of host 'gitlab.bdqn.cn (192.168.1.21)' can't be established.ECDSA key fingerprint is SHA256:88Ixrb6xHdt9SVsQ3n78nQbfzPplW8kZNKQLuldud6w.ECDSA key fingerprint is MD5:3e:34:68:db:3a:f6:5c:a5:de:18:9b:1c:cc:ef:f9:ff.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added 'gitlab.bdqn.cn,192.168.1.21' (ECDSA) to the list of known hosts.Welcome to GitLab, @root!克隆项目,进行上传[root@localhost ~]# yum install -y git   //下载git声明谁操作,全局配置,为用户和用户邮箱(用户必须有才行)[root@localhost ~]# git config --global user.name "zhangsan"[root@localhost ~]# git config --global user.email "zahngsan@bdqn.cn"[root@localhost ~]# git clone git@gitlab.bdqn.cn:ios/ios.git   //克隆项目库正克隆到 'ios'...warning: 您似乎克隆了一个空版本库。[root@localhost ~]# ls                  //生成一个目录,就是克隆的代码anaconda-ks.cfg       ios   模板  图片  下载  桌面initial-setup-ks.cfg  公共  视频  文档  音乐[root@localhost ~]# cd ios/             //首先进入到克隆的库中[root@localhost ~]# touch README.md          //创建一个文件[root@localhost ~]# echo 111 > README.md        //输入内容[root@localhost ios]# git add README.md       //git中添加内容[root@localhost ios]# git commit -m "test111"   //进行提交,打一个标签[master(根提交) ad3c913] test111 1 file changed, 1 insertion(+) create mode 100644 README.md[root@localhost ios]# git push origin master  //上传,原来的,向主干添加Counting objects: 3, done.Writing objects: 100% (3/3), 209 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To git@gitlab.bdqn.cn:ios/ios.git * [new branch]      master -> master进入web页面就可以看到项目了克隆项目[root@localhost ~]# mkdir test[root@localhost ~]# cd test/[root@localhost test]# git clone git@gitlab.bdqn.cn:ios/ios.git正克隆到 'ios'...remote: Enumerating objects: 3, done.remote: Counting objects: 100% (3/3), done.remote: Total 3 (delta 0), reused 0 (delta 0)接收对象中: 100% (3/3), done.[root@localhost test]# lsios[root@localhost test]# cd ios/[root@localhost ios]# lsREADME.md


-----END-----

声明:本文为OFweek维科号作者发布,不代表OFweek维科号立场。如有侵权或其他问题,请及时联系我们举报。
2
评论

评论

    相关阅读

    暂无数据

    Python进阶学习交流

    专注于分Python网络爬虫、数...

    举报文章问题

    ×
    • 营销广告
    • 重复、旧闻
    • 格式问题
    • 低俗
    • 标题夸张
    • 与事实不符
    • 疑似抄袭
    • 我有话要说
    确定 取消

    举报评论问题

    ×
    • 淫秽色情
    • 营销广告
    • 恶意攻击谩骂
    • 我要吐槽
    确定 取消

    用户登录×

    请输入用户名/手机/邮箱

    请输入密码