gitlab安装基本运维

一、gitlab安装

  • 安装gitlab服务所需依赖包
[root@localhost ~]# yum -y install curl postfix policycoreutils-python openssh-server wget
  • 下载gitlab,安装gitlab服务
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.0.3-ce.0.el7.x86_64.rpm
[root@localhost ~]# yum -y localinstall  gitlab-ce-12.0.3-ce.0.el7.x86_64.rpm
  • 配置gitlab、访问域名及邮箱

[root@localhost ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.ddytest.com'
配置邮箱
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'  收件箱地址
gitlab_rails['gitlab_email_display_name'] = 'dingdongya'    收件人显示名称

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.codyy.com"      发件服务器
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "[email protected]"  发件人地址
gitlab_rails['smtp_password'] = "Abc123!"                发件人密码
gitlab_rails['smtp_domain'] = "codyy.com"                域名
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
关闭prometheus
prometheus['enable'] = flase
  • 初始化gitlab服务,启动gitlab服务
[root@localhost ~]# gitlab-ctl reconfigure
[root@localhost ~]# gitlab-ctl stop|start|status|restart 停止|启动|查看|重启 gitlab进程(可以更单个进程)
[root@localhost ~]# gitlab-ctl status
run: alertmanager: (pid 20905) 84s; run: log: (pid 20535) 173s
run: gitaly: (pid 20838) 86s; run: log: (pid 19944) 305s
run: gitlab-monitor: (pid 20837) 86s; run: log: (pid 20377) 191s
run: gitlab-workhorse: (pid 20819) 87s; run: log: (pid 20268) 217s
run: grafana: (pid 20929) 83s; run: log: (pid 20724) 117s
run: logrotate: (pid 20311) 206s; run: log: (pid 20325) 203s
run: nginx: (pid 20289) 212s; run: log: (pid 20306) 209s
run: node-exporter: (pid 20829) 87s; run: log: (pid 20357) 199s
run: postgres-exporter: (pid 20920) 84s; run: log: (pid 20575) 167s
run: postgresql: (pid 20058) 301s; run: log: (pid 20071) 300s
run: prometheus: (pid 20873) 86s; run: log: (pid 20490) 179s
run: redis: (pid 19892) 314s; run: log: (pid 19902) 311s
run: redis-exporter: (pid 20859) 86s; run: log: (pid 20406) 187s
run: sidekiq: (pid 20241) 224s; run: log: (pid 20250) 223s
run: unicorn: (pid 20212) 230s; run: log: (pid 20233) 229s

#ps:每次修改/etc/gitlab/gitlab.rb文件,都需要gitlab-ctl reconfigure
  • 访问gitlab服务,及gitlab邮箱测试
  • 汉化gitlab
下载汉化地址https://gitlab.com/xhang/gitlab

二、gitlab基本操作

git安装

yum -y install git

查看版本

git --version

通常配置git,只需要配置你是谁,你的邮箱是什么。

[root@codyy91-102 ~]# git config --global user.name "xxx"
[root@codyy91-102 ~]# git config --global user.email "[email protected]"
[root@codyy91-102 ~]# git config --global color.ui true  可以不配置

创建本地仓库

[root@codyy91-102 ~]# mkdir demo
[root@codyy91-102 ~]# cd demo/
[root@codyy91-102 demo]# git init

如何提交目录文件至本地仓库

[root@codyy91-102 demo]# touch file1 flie2 file3
[root@codyy91-102 demo]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#   file1
#   file3
#   flie2
nothing added to commit but untracked files present (use "git add" to track)

提交至缓存区

[root@codyy91-102 demo]# git add .
[root@codyy91-102 demo]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#   new file:   file1
#   new file:   file3
#   new file:   flie2
#

提交至git仓库

[root@codyy91-102 demo]# git commit -m "新增文件"
3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1
 create mode 100644 file3
 create mode 100644 flie2
[root@codyy91-102 demo]# git status
# On branch master
nothing to commit, working directory clean

git如何改名提交至git仓库

[root@codyy91-102 demo]# git mv file1 flie
[root@codyy91-102 demo]# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#   renamed:    file1 -> flie
#
[root@codyy91-102 demo]# git commit -m "..."
[master 61bf37f] ...
 Committer: [email protected] 
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email [email protected]

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 0 insertions(+), 0 deletions(-)
 rename file1 => flie (100%)

比较本地文件与暂存区文件的区别

[root@codyy91-102 demo]# echo "123456" > file3 
[root@codyy91-102 demo]# git diff file3 
diff --git a/file3 b/file3
index e69de29..9f358a4 100644
--- a/file3
+++ b/file3
@@ -0,0 +1 @@
+123456

比较暂存区与本地仓库文件内容的区别

[root@codyy91-102 demo]# git diff --cached file3 
diff --git a/file3 b/file3
index e69de29..9f358a4 100644
--- a/file3
+++ b/file3
@@ -0,0 +1 @@
+123456

如何理解commit提交操作

相当于对文件做了一个快照

  • 查看历史git commit快照操作

[root@codyy91-102 demo]# git log
commit d97984e8322ded51d97ed2bd77782cce7da52e6e
Author: [email protected] 
Date:   Sat Aug 22 10:32:04 2020 +0800

    123

commit 61bf37f5b474c18fa73aa0f5fdb3a7fbd96ad172
Author: [email protected] 
Date:   Sat Aug 22 10:09:36 2020 +0800

    ...

commit d4a669f21a242300d9ce927b37a07b297ccfd12d
Author: [email protected] 
Date:   Sat Aug 22 10:03:35 2020 +0800

[root@codyy91-102 demo]# git log --oneline
d97984e 123
61bf37f ...
d4a669f 新增文件

文件误操作清空内容,如何回退

[root@codyy91-102 demo]# > file3 
[root@codyy91-102 demo]# cat file3 
[root@codyy91-102 demo]# git checkout file3 
[root@codyy91-102 demo]# cat file3 
123456
[root@codyy91-102 demo]# 

本地文件误操作提交至暂存区,如何回退

本地仓库--覆盖--暂存区--本地文件

[root@codyy91-102 demo]# > file3 
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# git add .
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# git reset HEAD file3 
Unstaged changes after reset:
M   file3
[root@codyy91-102 demo]# git checkout file3 
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# cat file3 
123456
[root@codyy91-102 demo]# 

如果多次提交本地仓库,需要回退至某个版本

[root@codyy91-102 demo]# git log --oneline
d97984e 123
61bf37f ...
d4a669f 新增文件
[root@codyy91-102 demo]# git reset --hard d97984e
HEAD is now at d97984e 123

git reflog 查看所有操作的快照记录

查看分支

[root@codyy91-102 demo]# git branch
* master

新建分支

[root@codyy91-102 demo]# git branch dev
[root@codyy91-102 demo]# git branch 
  dev
* master

切换分支

[root@codyy91-102 demo]# git checkout dev
Switched to branch 'dev'
[root@codyy91-102 demo]# git branch 
* dev
  master

合并master

[root@codyy91-102 demo]# git checkout dev
Switched to branch 'dev'
[root@codyy91-102 demo]# git merge master -m "合并到master"
Updating d97984e..c7a3947
Fast-forward (no commit created; -m option ignored)
 file4 | 0
 file5 | 0
 file6 | 0
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file4
 create mode 100644 file5
 create mode 100644 file6

分支功能测试完成后,切换回master,合并分支内容

[root@codyy91-102 demo]# git checkout master
Switched to branch 'master'
[root@codyy91-102 demo]# git merge dev
Already up-to-date.

删除分支

[root@codyy91-102 demo]# git branch dev -d
Deleted branch dev (was c7a3947)

合并分支冲突

手动修改冲突部分(开发),然后master合并分支。

git 标签

标签的作用

标签容易被记住,方便回退

[root@codyy91-102 demo]# git tag -a "v1.0(自行定义)" -m "发布的第一版" 打标签
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# 
[root@codyy91-102 demo]# git tag   查看标签
v1.0(自行定义)
[root@codyy91-102 demo]# git show tag   查看描述
fatal: ambiguous argument 'tag': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git  [...] -- [...]'
[root@codyy91-102 demo]# git show
commit c7a394748d23b22ea0be8b2529e10c83e4ce5176
Author: [email protected] 
Date:   Sat Aug 22 15:26:48 2020 +0800

    new 4-6

diff --git a/file4 b/file4
new file mode 100644
index 0000000..e69de29
diff --git a/file5 b/file5
new file mode 100644
index 0000000..e69de29
diff --git a/file6 b/file6
new file mode 100644
index 0000000..e69de29

以某个commitid打标签

[root@codyy91-102 demo]# git tag -a "v2.0" d97984e -m "描述信息"

删除tag

 git tag -d v2.0

三、gitlab用户组、项目关系

[图片上传失败...(image-e512fc-1598247990853)]

  • git用户、用户组、项目配置

    1. 创建组
    2. 创建项目--->项目隶属于某个组
    3. 创建用户,设定密码,为用户分配组

四、gitlab备份恢复

  1. 备份

    1)修改配置文件,启用备份
    [root@localhost ~]# vim /etc/gitlab/gitlab.rb
    gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"    备份路径
    gitlab_rails['backup_keep_time'] = 604800                  备份保留时间7天
    2)重新加载配置
    [root@localhost ~]# gitlab-ctl  reconfigure
    3)手动执行备份命令,会将备份的结果存储至“/var/opt/gitlab/backups(自己设置的备份路径)”中
    [root@localhost ~]# gitlab-rake gitlab:backup:create
    4)查看备份的文件
    [root@localhost ~]# ll /var/opt/gitlab/backups/
    total 132
    -rw------- 1 git git 133120 Aug 23 17:06 1598173586_2020_08_23_12.0.3_gitlab_backup.tar
    
    
  2. 恢复

    1)停止数据库写入
    [root@localhost ~]# gitlab-ctl stop unicorn
    [root@localhost ~]# gitlab-ctl stop sidekiq
    2)通过gitlab-rake命令进行恢复,恢复时需要指定备份的名称(只需要到版本号,其他不需要)
    [root@localhost ~]# gitlab-rake gitlab:backup:restore BACKUP=1598173586_2020_08_23_12.0.3
    Do you want to continue (yes/no)?   (输入yes)
    Do you want to continue (yes/no)?   (输入yes)
    3)重启gitlab服务
     [root@localhost ~]# gitlab-ctl restart
    

你可能感兴趣的:(gitlab安装基本运维)