Github版本管理以及git使用

1.git客户端编译安装

同步系统时间服务器

ntpdate cn.ntp.org.cn

安装依赖包:

[root@baolin ~]# yum install epel-release -y
[root@baolin ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker -y

编译安装高版本git

wget https://github.com/git/git/archive/v2.7.4.zip
unzip v2.7.4.zip 
cd git-2.7.4/
make prefix=/usr/local/git all
make prefix=/usr/local/git install
rm -fr /usr/bin/git
ln -s /usr/local/git/bin/git /usr/bin/git 
git --version

在commit后可以对当次提交做一个tag版本

[root@baolin git_test]# git tag -a v1.0 -m "注释内容" 
[root@baolin git_test]# git tag
v1.0

# -d 删除指定标签
[root@baolin git_test]# git tag -d v1.0
Deleted tag 'v1.0' (was 07032f1)

2.安装gitlab版本厂库

1.安装依赖关系

[root@baolin git_test]# yum install curl policycoreutils openssh-server openssh-clients policycoreutils-python -y
[root@baolin git_test]# systemctl enable sshd 
[root@baolin git_test]# systemctl start sshd

[root@baolin git_test]# systemctl enable postfix
[root@baolin git_test]# systemctl start postfix

2.下载安装

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

[root@baolin git_test]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.6.6-ce.0.el7.x86_64.rpm
[root@baolin git_test]# rpm -ivh gitlab-ce-10.6.6-ce.0.el7.x86_64.rpm 

3.修改配置文件并启动

[root@baolin git_test]# vim /etc/gitlab/gitlab.rb 
#external_url 'http://gitlab.example.com'
# 访问地址,如果用域名访问,此处应该使用域名地址
external_url 'http://192.8.21.100'

# 自动化组件安装(并启动)
[root@baolin git_test]# gitlab-ctl reconfigure 

# 组件日志所在目录
[root@baolin gitlab]# pwd
/var/log/gitlab

4.Gitlab常用管理命令

# 查看 各组件状态
gitlab-ctl status
# 启动
gitlab-ctl start
# 关闭
gitlab-ctl stop
# 重启
gitlab-ctl restart
# 查看nginx 日志
gitlab-ctl tail nginx
# 备份命令
gitlab-rake gitlab:backup:create

5.Gitlab 常用组件

- nginx:静态Web服务器
- gitlab-shell:用于处理Git命令和修改authorized keys列表
- gitlab-workhorse:轻量级的反向代理服务器
- logrotate:日志文件管理工具
- postgresql:数据库
- redis:缓存数据库
- sidekiq:用于在后台执行队列任务(异步执行)
- unicorn:GitLab Rails 应用是托管在这个服务器上的

6.目录结构

- /var/opt/gitlab/git-data/repositories/   :库默认存储目录
- /opt/gitlab                                  :应用代码和相应的依赖程序
- gitlab-ctl reconfigure  : 命令编译后的应用数据和配置文件,不需要认为的修改配置
- /etc/gitlab     :配置文件目录
- /var/log/gitlab   :此目录下存放了gitlab各个组件产生的日志
- /var/opt/gitlab/backups    :备份文件生成的目录

变更主配置文件

- gitlab-ctl reconfigure    重置配置文件
- gitlab-ctl show-config    验证配置文件
- gitlab-ctl restart        重启gitlab服务
- gitlab-rails console      进入控制台

3.页面配置gitlab组权限

  • 登录Gitlab 用户root
  • 创建 Groups 组
  • 创建 Users 用户
  • 创建 Projects 项目
  • 将用 user 户加入到 projects 中,并设置权限
  • 添加用户 key 用于免秘钥 下载代码
  • Deploy key 只能下载代码不能上传代码,一般给Jenkins使用

4.gitlab的备份与恢复【全量包括用户关系】

修改后需要:gitlab-ctl reconfigure 更新配置 并 执行 gitlab-ctl restart 重启服务


1.配置备份路径

# 需要有git 用户权限
[root@baolin app1]# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

2.配置备份保存时间

# 默认保存时间 7 天,此处为 30天
gitlab_rails['backup_keep_time'] = 2592000

3.备份当前现有gitlab数据

[root@baolin app1]# gitlab-rake gitlab:backup:create

# 查看备份数据
[root@baolin app1]# ll -sh /var/opt/gitlab/backups
80K -rw------- 1 git git 80K Jun  6 16:38 1528274316_2018_06_06_10.6.6_gitlab_backup.tar

4.添加备份的计划任务

0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create

5.恢复数据

# 关闭 unicorn 和 sidekiq 服务
[root@baolin app1]# gitlab-ctl stop unicorn
[root@baolin app1]# gitlab-ctl stop sidekiq

# 切换至 备份文件所在目录 
[root@baolin backups]# cd /var/opt/gitlab/backups
[root@baolin backups]# pwd
/var/opt/gitlab/backups

# 执行恢复文件 文件名为 "时间戳加时间段" 名称
[root@baolin backups]# gitlab-rake gitlab:backup:restore BACKUP=1528274316_2018_06_06_10.6.6

# 重启服务 【30秒等待】
[root@baolin backups]# gitlab-ctl restart

6.只备份版本库

# 版本库路径
[root@baolin repositories]# pwd
/var/opt/gitlab/git-data/repositories

# 手动打包代码库
[root@baolin repositories]# ls
java
[root@baolin repositories]# tar zcf /data/git_bak.tar.gz ./

邮件配置

1.参考邮件配置:

https://docs.gitlab.com.cn/omnibus/settings/smtp.html#qq-exmail

2.邮件验证:gitlab-rails console

#配置完成后可以用Rails控制台验证邮件是否能发送成功。 在GitLab服务器上,执行 gitlab-rails console 进入控制台。 然后在控制台提示符后输入下面的命令 发送一封测试邮件:

irb(main):003:0> Notify.test_email('[email protected]', 'Message Subject', 'Message Body').deliver_now
# 示例
Notify.test_email('收件人邮箱', '邮件标题', '邮件正文').deliver_now

5.性能监控

查看当前数据任务

http://192.8.21.100/admin/background_jobs

猜你喜欢

转载自www.cnblogs.com/baolin2200/p/9183471.html