小诺文档中心 小诺文档中心
首页
小诺博客 (opens new window)
DevOps
云原生
技术
更多
网址导航
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

kevin

运维界的菜鸟
首页
小诺博客 (opens new window)
DevOps
云原生
技术
更多
网址导航
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • shell编程

  • 消息队列

  • web

  • ELK

  • 自动化运维

    • ansible笔记
    • gitlab
      • jenkins
    • linux

    • DevOps
    • 自动化运维
    xiaonuo
    2022-06-24
    目录

    gitlab

    # 一、gitlab的工作流程

    创建并克隆项目 创建项目某feature分支 编写代码并提交至分支 推送该项目分支至远程gitlab服务器 进行代码检查并提交master主分支合并申请 项目领导审查代码并确认合并申请

    # 二、gitlab安装配置管理

    安装Omnibus Gitlab-ce package

    # 1.安装gitlab组件

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

    # 2.配置yum仓库

    curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh|sudo bash

    # 3.启动postfix

    systemctl start postfix && systemctl enable postfix

    # 4.安装gitlab-ce社区版本

    yum install -y gitlab-ce

    Omnibus Gitlab等相关配置初始化并完成安装

    # 1.证书创建与配置加载
    # 2.nginx ssl代理服务配置
    # 3.初始化gitlab相关服务并完成安装
    # 创建证书

    mkdir -p /etc/gitlab/ssl openssl genrsa -out "/etc/gitlab/ssl/gitlab.example.com.key" 2048 openssl req -new -key "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.csr"

    cn bj bj gitlab.example.com admin@example.com

    openssl x509 -req -days 365 -in "/etc/gitlab/ssl/gitlab.example.com.csr" -signkey "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.crt"

    openssl dhparam -out /etc/gitlab/ssl/dhparams.pem 2048

    chmod 600 /etc/gitlab/ssl/*

    vim /etc/gitlab/gitlab.rb 修改以下几个位置

    external_url 'https://gitlab.example.com'
    nginx['redirect_http_to_https'] = true
    nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.example.com.crt"
    
    nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.example.com.key"
    
    nginx['ssl_dhparam'] = /etc/gitlab/ssl/dhparams.pem
    
    1
    2
    3
    4
    5
    6
    7
    # 初始化配置

    gitlab-ctl reconfigure

    nginx ssl代理配置 vim /var/opt/gitlab/nginx/conf/gitlab-http.conf server_name gitlab.example.com; rewrite ^(.*)$ https://$host$1 permanent;

    gitlab-ctl restart

    https://gitlab.example.com

    # 邮件配置
    gitlab_rails['smtp_enable'] = true
    gitlab_rails['smtp_address'] = "smtp.qq.com"               #发送邮箱的smtp
    gitlab_rails['smtp_port'] = 465                                   #目前大部分IDC 都封了25端口,需要配置465加密端口才可以发送邮件,这也是为什么不用postfix的原因,以下为阿里云企业邮配置(和腾讯企业邮相同):
    gitlab_rails['smtp_user_name'] = "541885811@qq.com"       #发送邮箱地址
    gitlab_rails['smtp_password'] = "gydoxozuwzmgbfge"              #发送邮箱的密码
    gitlab_rails['smtp_domain'] = "smtp.qq.com"                             #发送邮箱的后缀
    gitlab_rails['smtp_authentication'] = :login                         #开启日志记录
    gitlab_rails['smtp_enable_starttls_auto'] = true
    gitlab_rails['smtp_tls'] = true
    gitlab_rails['gitlab_email_from'] = "541885811@qq.com"        #配置gitlab的配置的发信人
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    gitlab-ctl reconfigure gitlab-ctl restart gitlab-rails console

    Notify.test_email('48211701@qq.com', 'GitLab email', 'Hellow world').deliver_now

    # 5.git使用教程

    版本控制 git

    https://git-scm.com/downloads

    git 基本命令

    查看配置 git config -l git config --system -list git config --global --list

    所有的配置都保存在本地

    C:\Program Files\Git\etc\gitconfig

    配置账号和邮箱

    git config --global user.name “wangkai” git config --blobal user.mail “48211701@qq.com”

    git clone

    添加所有文件到暂存区 git add .

    git status

    将暂存区的内容提交到本地库 git commit -m “1.txt”

    -m 添加文件信息

    git log 查看历史记录

    git push

    git init 初始化新建仓库

    忽略文件 在主目录下创建.gitignore文件

    忽略

    .txt 忽略所有.txt结尾的文件 !lib.txt 但lib.txt除外 build/忽略build/目录下的所有文件 doc/.txt 会忽略doc/notes.txt 但不包括doc/server/arch.txt

    生成公钥 ssh-keygen

    创建分支 git branch 分支名 查看分支 git branch -v 切换分支 git checkout 分支名

    git branch -r 列出所有分支

    git branch -d 删除分支 git branch -dr remote/branch 删除远程分支

    git merge branch 合并指定分支到当前分支

    git大全 https://gitee.com/all-about-git

    团队很重要

    新建项目

    https://gitlab.example.com/root/testrepo.git

    cd d: git -c http.sslVerify=false clone https://gitlab.example.com/root/testrepo.git cd d:\repo\testrepo

    git add . git commit -m"First commit" git config --global user.email "admin@example.com" git config --global user.name "admin" git -c http.sslVerify=false push origin master

    git init 初始化 git add README.md git commit -m "first commit" git remote add origin https://github.com/xlqywk/jenkins.git git push -u origin master

    ssh方式配置 ssh-keygen -t rsa -C "你的Git邮箱" 复制pub到gitlab

    git config --global user.name "wang" git config --global user.email "48211701@qq.com"

    git clone git@gitlab.example.com:testgroup/testproject.git

    cat ~/.gitconfig vim index.html git add . git commit -m "v2" git push

    git config --global user.name “name“ #设置全局用户名 git config --global user.email xxx@yyy.com #设置全局邮箱 git config --global --list #列出用户全局设置,默认保存在~/.gitconfig文件中 git add index.html / . #添加指定文件、目录或当前目录下所有数据到暂存区 git commit -m “comment“ #提交文件到工作区 git status #查看工作区的状态 git push #将本地仓库提交代码到远程服务器 git pull #从服务器获取代码到本地仓库 git log #查看操作日志 vim .gitignore #定义忽略文件,即不放在仓库的文件 git reset --hard HEAD^^ #git版本回滚, HEAD为当前版本,加一个^为上一个,^^为上上一个版本 git reflog # #获取每次提交的ID,可以使用--hard根据提交的ID进行版本回退 git reset --hard 5ae4b06 #回退到指定id的版本 git branch #查看当前所处的分支 git checkout -b develop #创建并切换到一个新分支 git checkout develop #切换分支

    # 6.gitlab数据备份恢复

    gitlab-ctl stop unicorn gitlab-ctl stop sidekiq gitlab-rake gitlab:backup:create gitlab-ctl start ll /var/opt/gitlab/backups/ 恢复 gitlab-rake gitlab:backup:restore BACKUP=备份文件名

    # 7.Git远程仓库地址变更本地如何修改

    公司搬移, 作为git仓库的服务器IP地址变了。 本地代码挺多,重新检出太占时间,可以修改一个什么配置让我本地仓库和新的远程仓库建立关联吗, 答案是肯定的!

    方法有很多,这里简单介绍几种: 以下均以项目git_test为例: 老地址:http://192.168.1.12:9797/john/git_test.git 新地址:http://192.168.100.235:9797/john/git_test.git 远程仓库名称: origin

    # 方法一 通过命令直接修改远程地址

    进入git_test根目录 git remote 查看所有远程仓库, git remote xxx 查看指定远程仓库地址 git remote set-url origin http://192.168.100.235:9797/john/git_test.git

    # 方法二 通过命令先删除再添加远程仓库

    1.进入git_test根目录

    2.git remote 查看所有远程仓库, git remote xxx 查看指定远程仓库地址

    3.git remote rm origin

    4.git remote add origin http://192.168.100.235:9797/john/git_test.git

    # 方法三 直接修改配置文件

    进入git_test/.git vim config

    复制代码 [core] repositoryformatversion = 0 filemode = true logallrefupdates = true precomposeunicode = true [remote "origin"] url = http://192.168.100.235:9797/shimanqiang/assistant.git fetch = +refs/heads/:refs/remotes/origin/ [branch "master"] remote = origin merge = refs/heads/master 复制代码 修改 [remote “origin”]下面的url即可

    # 方法四 通过第三方git客户端修改。

    以SourceTree为例,点击 仓库 -> 仓库配置 -> 远程仓库 即可管理此项目中配置的所有远程仓库, 而且这个界面最下方还可以点击编辑配置文件,同样可以完成方法三。

    # 8.gitlab汉化

    默认的全英文界面对于英文水平低的来讲当然用着很不舒服,于是便需要来一波操作进行汉化,英文好的请自觉忽略

    GitLab中文社区的项目,v7-v8.8是由Larry Li发起的"GitLab中文社区版项目"(https://gitlab.com/larryli/gitlab),从v8.9之后由@xhang开始继续汉化项目(https://gitlab.com/xhang/gitlab)

    [root@gitlab tools]# pwd

    /service/tools

    [root@gitlab tools]# mkdir /backup

    [root@gitlab tools]# cp /opt/gitlab/embedded/service/gitlab-rails/* /backup #防止汉化失败,备份原文件

    [root@gitlab tools]# git clone https://gitlab.com/xhang/gitlab.git #下载最新的汉化包

    汉化包的版本更新速度不得而知,所以尽量不要安装最新版本的gitlab。如果是要下载老版本的汉化包,需要加上老版本的分支,如果想下载10.0.2,可以运行如下语句

    [root@gitlab tools]# git clone https://gitlab.com/xhang/gitlab.git -b v12.3.0-zh

    [root@gitlab tools]# ls #git下来的文件为gitlab

    gitlab gitlab-ce-10.8.4-ce.0.el7.x86_64.rpm

    [root@gitlab tools]# \cp -rf gitlab/* /opt/gitlab/embedded/service/gitlab-rails/ #拷贝文件

    检验汉化

    [root@gitlab tools]# gitlab-ctl reconfigure #加载配置(第一次执行此命令会启动,若只启动执行start)

    # 9.gitlab占用内存大

    gitlab 一跑起来内存就占一大半,在上传个代码就卡死了有时候,

    解决方法:

    top -ac 看一下开启了多少unicorn worker进程,gitlab默认开启进程数与CPU内核数相同

    解决:

    修改gitlab.rb文件(根据实际修改)

    1.减少进程数

    vim /etc/gitlab/gitlab.rb

    unicorn['worker_processes'] = 8 默认是被注释掉的,官方建议该值是CPU核心数加一,可以提高服务器的响应速度,如果内存只有4G,或者服务器上有其它业务,就不要改了,以免内存不足。另外,这个参数最小值是2,设为1,服务器可能会卡死。

    1. # 减少数据库缓存

    postgresql['shared_buffers'] = "256MB" 默认为256MB,可适当改小

    1. # 减少数据库并发数

    postgresql['max_worker_processes'] = 8 默认为8,可适当减少

    1. # 减少sidekiq并发数

    Bash

    sidekiq['concurrency'] = 25 默认是25,可适当改小

    1. # 启用Swap分区

    使用Swap的方法,请自行搜索

    需要注意的是,修改完配置以后,需要执行下面的命令使配置生效:

    Bash

    sudo gitlab-ctl reconfigure sudo gitlab-ctl restart 以上就是解决GitLab内存占用过高的几点方法,有什么问题可在文章下方留言一起讨论。

    重新加载配置

    重启gitlab

    (建议worker=CPU核数+1)

    # 10.gitlab优化

    修改/etc/gitlab/gitlab.rb配置文件,修改成自己的域名

    1 external_url 'http://gitlab.example.com'

    修改GitLab仓库存储位置,GitLab仓库默认位子:/var/opt/gitlab/git-data

    a、创建/data/soft/gitlab/gitlab-data目录,作为仓库存储目录

    命令:mkdir /data/soft/gitlab/gitlab-data

    b、修改gitlab配置文件,找到git_data_dir

    命令:vim /etc/gitlab/gitlab.rb

    增加内容:

    1 git_data_dirs({

    2 "default" => {

    3 "path" => "/data/soft/gitlab/gitlab-data"

    4 }

    5 })

    修改nginx端口,nginx默认端口是80,有可能被占用,修改成其他端口

    a、修改/etc/gitlab/gitlab.rb配置文件

    1 nginx['listen_port'] = 28000

    b、修改/var/opt/gitlab/nginx/conf/gitlab-http.conf文件

    1 listen *:28000;

    4、修改unicorn端口,unicorn默认端口是8080,有可能被占用,修改成其他端口

    a、修改/etc/gitlab/gitlab.rb配置文件

    1 unicorn['port'] = 28001

    b、修改/var/opt/gitlab/gitlab-rails/etc/unicorn.rb文件

    1 listen "127.0.0.1:28001", :tcp_nopush => true

    6、优化GitLab性能,修改gitlab配置文件/etc/gitlab/gitlab.rb

    官方推荐最低物理配置是 2核4G(本例使用的是1核2G运行比较慢)

    a、减少进程数与超时时间

    1 # 超时时间

    2 unicorn['worker_timeout'] = 60

    3

    4 # 不能低于2,否则卡死 worker=CPU核数+1

    5 unicorn['worker_processes'] = 2

    b、GitLab默认使用了PostgreSQL,优化PostgreSQL

    # 减少数据库缓存大小 默认256,可适当改小

    postgresql['shared_buffers'] = "256MB"

    # 减少数据库并发数

    postgresql['max_worker_processes'] = 8

    # 减少sidekiq并发数

    sidekiq['concurrency'] = 10

    c、减少unicorn内存使用

    1 # 减少内存

    2 unicorn['worker_memory_limit_min'] = "200 * 1 << 20"

    3 unicorn['worker_memory_limit_max'] = "300 * 1 << 20"

    unicorn['worker_timeout'] = 60

    #worker=CPU核数+1 573

    unicorn['worker_processes'] = 17

    ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

    ansible笔记
    jenkins

    ← ansible笔记 jenkins→

    最近更新
    01
    postgresql安装
    06-24
    02
    oracle笔记
    06-24
    03
    opengauss笔记
    06-24
    更多文章>
    Theme by Vdoing | Copyright © 2019-2022 kevin | 小诺运维
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式
    ×