https://about.gitlab.com/install/

使用ubuntu安装操作系统
安装包下载地址
https://packages.gitlab.com/gitlab/gitlab-ce

下载指定版本号软件

image.png
设置虚拟机为2核心cpu4g内存
root@node1:/var/36/videos# cd /var/36/videos
root@node1:/var/36/videos# vim /etc/hostname
gitlab
root@node1:~# hostnamectl set-hostname gitlab
root@gitlab:~# cd /usr/local/src/
-rw-r--r-- 1 root root 668531950 7月 18 10:54 gitlab-ce_11.11.5-ce.0_amd64.deb
root@gitlab:/usr/local/src# dpkg -c gitlab-ce_11.11.5-ce.0_amd64.deb |less
查看都安装那些包
root@gitlab:/usr/local/src# dpkg -c gitlab-ce_11.11.5-ce.0_amd64.deb |less
root@gitlab:/usr/local/src# dpkg -i gitlab-ce_11.11.5-ce.0_amd64.deb
安装软件
Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
安装完之后的页面
root@gitlab:/usr/local/src# vim /etc/gitlab/gitlab.rb
root@gitlab:/usr/local/src# grep "^[a-z]" /etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'
查看非注释行
external_url 'http://173.22.90.18'
改成本机的ip地址
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "50589143@qq.com"
gitlab_rails['smtp_password'] = "ijzbwfxedwpkbigs"
qq邮箱授权码
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = "50589143@qq.com"
user["git_user_email"] = "50589143@qq.com"
可以用这个邮件,给公司忘记密码的人,发邮件让他到邮件里去改密码
root@gitlab:/usr/local/src# gitlab-ctl reconfigure
让配置文件生效
,配置完以后自动起来
他会启动10个服务,对内存占用高
,通常这种软件公司只安装1两次,后期偏维护

登录页面创建密码
默认账户名称是root,密码就是刚才设置的密码

登录进来
创建一个项目

image.png
项目设置为私有

image.png
新建账户

image.png

这个一般写公司的企业邮箱
更改密码

image.png

image.png

在这里修改密码

重新设置密码

发送到需要设置密码的邮箱

image.png

image.png

image.png

image.png
登录user1

image.png
修改组和权限

image.png
登录user1的用户查看他的所属组

image.png
开发创建项目

image.png

image.png
添加一个文档

image.png
添加页面文件

image.png
点回项目里

image.png

选择http
在开一个将来作为jakens
4g内存2核心cpu
root@zabbix:~# apt install git -y 安装git命令
克隆
root@zabbix:~# git clone http://173.22.90.18/linux36/web1.git
Username for 'http://173.22.90.18': user1
Password for 'http://user1@173.22.90.18':
输入账户和密码
#查看刚克隆的
root@zabbix:~# cd web1/
root@zabbix:~/web1# ls
index.html
root@zabbix:~/web1# cat index.html
linux36 web1 v1root@zabbix:~/web1#
接下来在github下创建项目

image.png
创建一个所有人都可以看到的项目

image.png

image.png

image.png
点击这个

image.png
创建

image.png
然后在克隆
root@zabbix:~/web1# rm -rf linux36/
root@zabbix:~/web1# git clone https://github.com/hello-l-o-v-e/linux36.git
正克隆到 'linux36'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
展开对象中: 100% (3/3), 完成.
修改代码
root@zabbix:~/web1/linux36# vim index.html
v111111111
2222222222
root@zabbix:~/web1/linux36# git add index.html
先添加到暂存区

image.png

image.png

image.png
#查看帮助和监督命令
root@gitlab:/usr/local/src# gitlab-rails --help
进入pcq的控制台
root@gitlab:/usr/local/src# gitlab-rails dbconsole
gitlabhq_production=> \db 查看数据库
List of tablespaces
Name | Owner | Location
------------+-------------+----------
pg_default | gitlab-psql |
pg_global | gitlab-psql |
(2 rows)
gitlabhq_production=> \dt 查看表
gitlabhq_production=> \quit
退出

image.png
root@gitlab:/usr/local/src# gitlab-ctl status
root@gitlab:/usr/local/src# gitlab-ctl stop
root@gitlab:/usr/local/src# gitlab-ctl start
一般在晚上克隆或者提交代码的时候才做这种操作
root@gitlab:/usr/local/src# gitlab-ctl tail nginx
查看nginx组件的日志
修改名称为jekens.master
root@zabbix:~/web1/linux36# vim /etc/hostname
jenkins-master
root@zabbix:~/web1/linux36# hostnamectl set-hostname jenkins-master
root@jenkins-master:~# ssh-keygen
生成一个密钥对
root@jenkins-master:~# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8lHqes8XyEJCd76FnsIWCo8UDmnWndOBF08uy/fuBknaiIQLR08C4/tHWtgjJdvs+XaKhnHfEJQCVxXI5k46htlLkjXSF/S5MKp0wj/G5Dblu+eBrhTqRbm5vDaZhoHtPXZiSOFUc9WaAiB0Ey3bnwstJMonPMNtWkXtA1+/D7gsfrjNsVBNRTwOxavWPsOOFvgrCU0DZAMZxzT6y6TA9i4nLUHvdWouj3iE/2Pnq0S0cKheKdgO15kQZMM16OAbrMGwXK0Xc0FyAAW8GsRe3WagStnKgDew//+klZqrO0uAX1l37AJEQuKrYk+ELj0uW+0rLifN9YcPE54tLmFHR root@jenkins-master
查看秘钥对
因为key里边有主机名称的所以需要提前更改
把秘钥贴进来

image.png

image.png
使用ssh秘钥克隆,仅限添加秘钥的账户才可以

image.png
git 常用命令
git config --global user.name “name“ #设置全局用户名
git config --global user.email xxx@xx.com #设置全局邮箱
git config --global --list #列出用户全局设置
git add index.html / . #添加指定文件、 目录或当前目录下所有数据到暂存区
git commit -m “11“ #提交文件到工作区
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 #切换分支
git客户端测试clone项目
root@gitlab:~# git clone http://192.168.1.100/test/darius.git
Cloning into 'darius'...
Username for 'http://192.168.1.100': darius
Password for 'http://darius@192.168.1.100':
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
root@gitlab:~# ll darius/
total 16
drwxr-xr-x 3 root root 4096 Jul 19 04:36 ./
drwx------ 6 root root 4096 Jul 19 04:36 ../
drwxr-xr-x 8 root root 4096 Jul 19 04:36 .git/
-rw-r--r-- 1 root root 22 Jul 19 04:36 index.html
root@gitlab:~# cat darius/index.html
<h1>www.duxy6.com</h1>
#初次运行gitlab需要进行认证
root@gitlab:~/darius# git config --global user.email "50589143@qq.com"
root@gitlab:~/darius# git config --global user.name "user1"
#认证信息会保存在 .gitconfig 中,每次进行git操作都会查找此文件
root@gitlab:~/darius# cat ~/.gitconfig
[user]
name = user1
email = 50589143@qq.com
#编辑index.html文件上传
root@gitlab:~# cd darius/
root@gitlab:~/darius# vim index.html
root@gitlab:~/darius# cat index.html
<h1>www.duxy6.com</h1>
<h1>www.duxy6.com v2</h1>
root@gitlab:~/darius# git add index.html
root@gitlab:~/darius# git commit -m "v2"
[master 5f629ee] v2
1 file changed, 2 insertions(+), 1 deletion(-)
root@gitlab:~/darius# git push
Username for 'http://192.168.1.100': darius
Password for 'http://darius@192.168.1.100':
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 261.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.1.100/test/darius.git
248f4f9..5f629ee master -> master
root@jenkins-master:~# git clone git@173.22.90.18:linux36/web1.git
第一次需要输入yes,仅用于提交代码
root@jenkins-master:~# cd /opt/
root@jenkins-master:/opt# git clone http://173.22.90.18/linux36/web1.git
使用http克隆的时候是需要账户名和密码的
正克隆到 'web1'...
Username for 'http://173.22.90.18': user1
Password for 'http://user1@173.22.90.18':
root@jenkins-master:/opt# vim web1/index.html 修改页面
linux36 web1 v1
linux36 web1 v2
修改为v2
root@jenkins-master:/opt/web1# git add index.html
添加到暂存区
root@jenkins-master:/opt/web1# git commit -m "v2"
添加成v2
root@jenkins-master:/opt/web1# git push
Username for 'http://173.22.90.18': user1
Password for 'http://user1@173.22.90.18':
Everything up-to-date
[master 9bba1dc] v2
1 file changed, 3 insertions(+), 1 deletion(-)
root@jenkins-master:/opt/web1# git push
Username for 'http://173.22.90.18': user1
Password for 'http://user1@173.22.90.18':
对象计数中: 3, 完成.
写入对象中: 100% (3/3), 251 bytes | 251.00 KiB/s, 完成.
Total 3 (delta 0), reused 0 (delta 0)
To http://173.22.90.18/linux36/web1.git
42728fa..9bba1dc master -> master
修改页面
root@jenkins-master:/opt/web1# vim index.html
linux36 web1 v1
linux36 web1 v2
linux36 web1 v3
root@jenkins-master:/opt/web1# git add ./*
root@jenkins-master:/opt/web1# git commit -m "v3"
root@jenkins-master:/opt/web1# git push
root@jenkins-master:/opt/web1# git status 查看提交的状态
root@jenkins-master:/opt/web1# vim index.html
linux36 web1 v1
linux36 web1 v2
linux36 web1 v3
linux36 web1 v4
root@jenkins-master:/opt/web1# git add ./*
root@jenkins-master:/opt/web1# git commit -m "v4" 提交到工作区里
root@jenkins-master:/opt/web1# git status 查看工作区的状态
位于分支 master
您的分支领先 'origin/master' 共 1 个提交。
(使用 "git push" 来发布您的本地提交)
无文件要提交,干净的工作区

查看当前的代码
root@jenkins-master:/opt/web1# git push
提交代码到服务器

id很重要,后期根据id找,恢复版本v3,v2们对应的id,当前的是v4
root@jenkins-master:/opt/web1# git reset --hard HEAD
查看当前的版本号
HEAD 现在位于 942af30 v4
root@jenkins-master:/opt/web1# git reset --hard HEAD^
回退到上一个版本
HEAD 现在位于 383bc5e v3
root@jenkins-master:/opt/web1# git reset --hard HEAD
HEAD 现在位于 383bc5e v3
查看当前版本的状态
root@jenkins-master:/opt/web1# cat index.html 查看当前的页面版本已经变了
linux36 web1 v1
linux36 web1 v2
linux36 web1 v3

image.png
root@jenkins-master:/opt/web1# git reflog 从这里头恢复tag号
383bc5e (HEAD -> master) HEAD@{0}: reset: moving to HEAD
383bc5e (HEAD -> master) HEAD@{1}: reset: moving to HEAD^
942af30 (origin/master, origin/HEAD) HEAD@{2}: reset: moving to HEAD
942af30 (origin/master, origin/HEAD) HEAD@{3}: reset: moving to HEAD
942af30 (origin/master, origin/HEAD) HEAD@{4}: commit: v4
383bc5e (HEAD -> master) HEAD@{5}: commit: v3
9bba1dc HEAD@{6}: commit: v2
42728fa HEAD@{7}: clone: from http://173.22.90.18/linux36/web1.git

恢复第一次的版本

查看文件信息
linux36 web1 v1root@jenkins-master:/opt/web1# git branch
* master

创建新分支

后期默认的提交和发布都在开发分支上了
后边会有开发的领导,把这些分支合并到master里
root@jenkins-master:/opt/web1# git checkout develop
error: pathspec 'develop' did not match any file(s) known to git.
root@jenkins-master:/opt/web1# cd ..
root@jenkins-master:/opt# rm -rf web1/
root@jenkins-master:/opt# git clone git@173.22.90.18:linux36/web1.git
克隆master的

搜索k8s的项目
https://git-scm.com/download/win
在git官网下载windowsgit的软件

点击gitbash

使用git克隆

image.png

image.png

修改页面
Administrator@J9HJH6QI19LG003 MINGW64 ~/web1 (master)
$ git add ./*
Administrator@J9HJH6QI19LG003 MINGW64 ~/web1 (master)
$ git config --global user.name “user1”
Administrator@J9HJH6QI19LG003 MINGW64 ~/web1 (master)
$ git config --global user.email 50589143@qq.com
Administrator@J9HJH6QI19LG003 MINGW64 ~/web1 (master)
$ git commit -m "v5"
[master 68e26d5] v5
1 file changed, 1 insertion(+), 1 deletion(-)
Administrator@J9HJH6QI19LG003 MINGW64 ~/web1 (master)
$ git push
root@gitlab:/usr/local/src# gitlab-ctl stop unicorn
root@gitlab:/usr/local/src# gitlab-ctl stop sidekiq
root@gitlab:/usr/local/src# gitlab-rake gitlab:backup:create
备份到固定目录

这个目录就是备份的固定目录

image.png

再次备份uninx的时间戳不同其他的都一样