运维八一 运维八一
首页
运维杂记
编程浅尝
周积跬步
专栏
生活
关于
收藏
  • 分类
  • 标签
  • 归档
Source (opens new window)

运维八一

运维,运维!
首页
运维杂记
编程浅尝
周积跬步
专栏
生活
关于
收藏
  • 分类
  • 标签
  • 归档
Source (opens new window)
  • 操作系统

  • 域名解析

  • 公有云

  • CI&CD

  • 数据库

  • 负载均衡&反向代理

  • 存储系统

  • 容器&容器编排

  • 批量管理

  • 邮件系统

  • 监控系统

  • Web服务

  • 虚拟化

  • 防火墙

  • 压测

  • 文件同步

  • 私有云

  • 日志系统

  • 代码仓库&版本管理

    • git常用命令
    • svn常用命令
    • gitlab+nginx部署
      • 1. 配置yum源
      • 2. 更新本地yum源
      • 3. 安装GitLab社区版
      • 4. 配置gitlab
      • 5. 启动Gitlab
      • 5. 配置nginx
      • 6. gitlab命令
    • svn关联网站目录
    • 搭建SVN服务及实现备份
  • 安全审计

  • 远程拨号

  • 大数据

  • 统一认证

  • 消息队列

  • Apollo

  • 运维杂记
  • 代码仓库&版本管理
lyndon
2022-06-08
目录

gitlab+nginx部署

# gitlab+nginx代码仓库安装

GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目安装。

它拥有与GitHub类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。

团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

# 1. 配置yum源

vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
1
2
3
4
5
6

# 2. 更新本地yum源

yum makecache
1

# 3. 安装GitLab社区版

自动安装最新版本

yum -y install gitlab-ce
1

# 4. 配置gitlab

  • gitlab默认安装位置/etc/gitlab/
  • gitlab默认仓库存储位置/var/opt/gitlab/git-data/

gitlab默认集成nginx/redis等服务

[root@ip-172-31-24-119 gitlab]# ll /var/opt/gitlab/
total 20
drwxr-x---. 3 gitlab-prometheus root         40 Aug 29 14:39 alertmanager
drwx------. 2 git               root          6 Aug 29 10:42 backups
-rw-------. 1 root              root         38 Aug 29 10:44 bootstrapped
drwx------. 2 git               root         75 Aug 29 14:40 gitaly
drwx------. 3 git               root         25 Aug 29 10:42 git-data
drwxr-xr-x. 3 git               root         19 Aug 29 10:42 gitlab-ci
drwxr-xr-x. 2 git               root         50 Aug 29 14:39 gitlab-monitor
drwxr-xr-x. 9 git               root       4096 Aug 29 14:39 gitlab-rails
drwx------. 2 git               root         23 Aug 29 14:39 gitlab-shell
drwxr-x---. 2 git               gitlab-www   51 Aug 29 14:40 gitlab-workhorse
drwx------. 4 gitlab-prometheus root         78 Aug 29 14:39 grafana
drwx------. 3 root              root         68 Aug 29 16:50 logrotate
drwxr-x---. 9 root              gitlab-www 4096 Aug 29 14:40 nginx
drwxr-xr-x. 3 root              root         31 Aug 29 10:44 node-exporter
drwx------. 2 gitlab-psql       root         25 Aug 29 14:39 postgres-exporter
drwxr-xr-x. 3 gitlab-psql       root         77 Aug 29 14:40 postgresql
drwxr-x---. 4 gitlab-prometheus root         50 Aug 29 14:39 prometheus
-rw-r--r--. 1 root              root        226 Aug 29 14:39 public_attributes.json
drwxr-x---. 2 gitlab-redis      git          57 Aug 29 17:36 redis
-rw-r--r--. 1 root              root         40 Aug 29 10:42 trusted-certs-directory-hash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

修改gitlab配置文件

vim /etc/gitlab/gitlab.rb
# 修改gitlab内置nginx的端口为8000,防止与现有nginx冲突
nginx['listen_port'] = 8000
# 设置gitlab的访问路径(是通过外部nginx反向代理访问的)
external_url 'http://git域名/'
# 修改gitlab的备份路径
gitlab_rails['backup_path'] = "/data/gitlab/backups"
# 修改gitlab的仓库地址
git_data_dirs({ "default" => { "path" => "/mnt/nas/git-data" } })
1
2
3
4
5
6
7
8
9

配置完成后,重新加载配置

gitlab-ctl stop
gitlab-ctl reconfigure
1
2

重新加载后,会发现在/data/gitlab目录下多出一个repositories目录

# 5. 启动Gitlab

gitlab-ctl start
1

扩展(可不做):

  • 1). 已存在git库时修改备份、仓库地址,会导致已有project的丢失,需要提前进行备份,然后再修改配置文件中的相应参数,修改后再导入备份文件

    创建备份

    gitlab-rake gitlab:backup:create
    
    1

    使用以上命令会默认在/var/opt/gitlab/backups目录下创建一个名称类似为1520580592_2018_03_09_10.5.3_gitlab_backup.tar的压缩包, 这个压缩包就是Gitlab整个的完整部分, 其中开头的1520580592_2018_03_09_10.5.3是备份创建的日期。

    恢复备份

    先停止相关数据连接服务

    gitlab-ctl stop unicorn
    gitlab-ctl stop sidekiq
    
    1
    2

    从1520580592_2018_03_09_10.5.3编号备份中恢复

    gitlab-rake gitlab:backup:restore BACKUP=1520580592_2018_03_09_10.5.3
    
    1
  • 2). 修改仓库地址

    在gitlab 8.0以后11.0之前的版本参数为:gitlab_rails['backup_path'] = "/mnt/gitlab/backup",在11.0之后的版本为:git_data_dirs({ "default" => { "path" => "/mnt/nas/git-data" } })

  • 3). gitlab配置通过smtp发送邮件(QQ exmail腾讯企业为例)

    编辑/etc/gitlab/gitlab.rb文件(加到文件最后面就好了)。以QQ企业邮箱为例:

    gitlab_rails['smtp_enable'] = true
    
    gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
    
    gitlab_rails['smtp_port'] = 465
    
    gitlab_rails['smtp_user_name'] = "gitlab@fayfox.com"
    
    gitlab_rails['smtp_password'] = "******"
    
    gitlab_rails['smtp_authentication'] = "login"
    
    gitlab_rails['smtp_enable_starttls_auto'] = true
    
    gitlab_rails['smtp_tls'] = true
    
    gitlab_rails['gitlab_email_from'] = 'gitlab@fayfox.com'
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17

    重新配置gitlab

    gitlab-ctl reconfigure
    
    1

    通过命令行测试邮件是否发送成功(也可以不测)

    gitlab-rails console
    irb(main):003:0> Notify.test_email('369281831@qq.com', 'Message Subject', 'Message Body').deliver_now
    
    1
    2
  • 4). gitlab内置的有nginx,如果要使用自建nginx方法有两种:

    • 第一种:自建nginx ---> gitlab

      #禁止内置nginx启动

      vim /etc/gitlab/gitlab.rb
      更改配置:
      nginx['enable'] = false
      参考内置nginx的配置,修改自建nginx配置
      
      1
      2
      3
      4
    • 第二种:自建nginx ---> 内置nginx ---> gitlab (比较方便)

      vim /etc/gitlab/gitlab.rb
      
      修改内置nginx端口,防止与现有nginx冲突
      
      nginx['listen_port'] = 8000
      
      设置gitlab的访问路径(是通过自建nginx反向代理访问的)
      
      external_url 'http://git域名/'
      
      修改自建nginx配置反代到内置nginx上
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11

# 5. 配置nginx

在nginx配置文件中增加server段:

server {
      listen 80;
      server_name gitlab.gogobanking.com;
      location / {
设置最大允许上传单个的文件大小
          client_max_body_size 1024m;
          proxy_redirect off;
          #以下确保 gitlab中项目的 url 是域名而不是 http://git,不可缺少
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          # 反向代理到 gitlab 内置的 nginx
          proxy_pass http://127.0.0.1:8000;
          index index.html index.htm;
        }
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

检查nginx配置

nginx -t
1

重启nginx

nginx -s reload
1

# 6. gitlab命令

#启停命令

gitlab-ctl start | stop | restart | status
1

#也可单独对一个服务进行启停

gitlab-ctl start nginx
1

#查看日志信息

gitlab-ctl tail
1

#查看具体某个服务的日志

gitlab-ctl tail nginx
1

#列举所有服务

gitlab-ctl service-list
1

#平稳停止一个服务

gitlab-ctl graceful-kill
1

#重新加载配置文件

gitlab-ctl reconfigure
1

#查看所有服务配置文件信息

gitlab-ctl show-config
1

#卸载软件

gitlab-ctl uninstall
1

#删除gitlab数据,重新白手起家

gitlab-ctl cleanse
1

#修改root密码

gitlab-rails console production
user = User.where(id: 1).first
=>
user.password = 'secret_pass'
=>
user.password_confirmation = 'secret_pass'
=>
user.save!
1
2
3
4
5
6
7
8
上次更新: 2022/06/12, 15:48:09
svn常用命令
svn关联网站目录

← svn常用命令 svn关联网站目录→

最近更新
01
ctr和crictl显示镜像不一致
03-13
02
alpine镜像集成常用数据库客户端
03-13
03
create-cluster
02-26
更多文章>
Theme by Vdoing | Copyright © 2015-2024 op81.com
苏ICP备18041258号-2
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式