目录
简介
1.什么是gitlab?
- web平台【网站】
- gitlab上存储的文件
- 用户可以将文件存在到gitlab上
- 用户也可以将gitlab上的文件拉取下来
2.gitlab和github的区别?
- github和gitlab是一样的东西
- github是别人作用,是公用,需要联网
- gitlab是在公司内部使用
3.怎么安装gitlab?
- 物理机通过rpm包进行安装
- 通过docker容器来启动gitlab (镜像名:gitlab/gitlab-ce)
下载并配置Docker环境
1)配置阿里的docker源
[root@hya ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2)安装Docker
[root@hya ~]# yum -y install docker
[root@hya ~]# vim /etc/docker/daemon.json
{"registry-mirrors": ["https://26ahzfln.mirror.aliyuncs.com"]}
3)启动Docker,关闭setenforce
[root@hya ~]# setenforce 0
[root@hya ~]# systemctl start docker
[root@hya ~]# systemctl stop firewalld #gitlab公司局域网中可以关闭防火墙
拉取镜像并启动Gitlab
1)拉取gitlab镜像
[root@hya ~]# docker image pull gitlab/gitlab-ce
Using default tag: latest
[root@hya ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/gitlab/gitlab-ce latest 85ef0c92d667 5 days ago 1.98 GB
2)启动容器
[root@hya ~]# docker run -it -d --name gitbab -p 81:80 85ef0c92d667 #通过id启动容器
aed663b50d425501c44bd15edec7f628a0d87229d76d4a748ffea631161e0619
[root@hya ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aed663b50d42 85ef0c92d667 "/assets/wrapper" 4 seconds ago Up 2 seconds (health: starting) 22/tcp, 443/tcp, 0.0.0.0:81->80/tcp gitbab
3)测试
4)设置中文版
将本地代码推送到Gitlab当中
创建本地代码仓库的步骤在这里 ~~> 点我点我点我吖
1)创建一个项目
2)创建三个文件并存放代码仓库
[root@hya mydate]# touch {1..3}.txt
[root@hya mydate]# echo "this is the first line" >> 1.txt
[root@hya mydate]# git add ./*
[root@hya mydate]# git commit -m "v1:三个新文件"
[master(根提交) e485c97] v1:三个新文件
3 files changed, 1 insertion(+)
create mode 100644 1.txt
create mode 100644 2.txt
create mode 100644 3.txt
3)创建一个新仓库*(命令)
[root@hya ~]# git clone git@aed663b50d42:root/mydate.git #实际以自己操作为准
[root@hya ~]# cd mydate
[root@hya ~]# touch README.md
[root@hya ~]# git add README.md
[root@hya ~]# git commit -m "add README"
[root@hya ~]# git push -u origin master
4)推送现有文件夹*(命令)
[root@hya ~]# cd existing_folder
[root@hya ~]# git init
[root@hya ~]# git remote add origin git@aed663b50d42:root/mydate.git
[root@hya ~]# git add .
[root@hya ~]# git commit -m "Initial commit"
[root@hya ~]# git push -u origin master
5)推送现有的Git仓库*(命令)
[root@hya ~]# cd existing_repo
[root@hya ~]# git remote rename origin old-origin
[root@hya ~]# git remote add origin git@aed663b50d42:root/mydate.git
[root@hya ~]# git push -u origin --all
[root@hya ~]# git push -u origin --tags
6)从gitlab上拉取下一个项目#(操作)
[root@hya ~]# git clone http://192.168.253.120:81/root/mydate.git #从gitlab上拉取这个项目
正克隆到 'mydate'...
Username for 'http://192.168.253.120:81': root
Password for 'http://[email protected]:81': #我的gitlab密码是12345678
warning: 您似乎克隆了一个空版本库。
7) 修改这个项目并且把修改过后的push到gitlab #(操作)
[root@hya mydate]# touch {1..3}.txt
[root@hya mydate]# git add ./*
[root@hya mydate]# git commit -m "v1:第一版"
[master(根提交) 5a45008] v1:第一版
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 1.txt
create mode 100644 2.txt
create mode 100644 3.txt
[root@hya mydate]# git push -u origin master
Username for 'http://192.168.253.120:81': root
Password for 'http://[email protected]:81':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 224 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.253.120:81/root/mydate.git
* [new branch] master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
总结
这是我在研究这套自动化上线体系的过程中,模拟架构中的一部分,私有云部分就到此为止啦。创作不易,你们的 “一键三连” 就是我最大的动力。