docker专题

---------------git 版本控制系统-------------------
git是一个版本控制系统

一、什么是版本控制系统?

1、概念

版本控制是一种 记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统。

(*)记录文件的所有历史变化
(*)随时可恢复到任何一个历史状态
(*)多人协作开发或修改
(*)错误恢复
(*)多功能并行开发

产品--> 新加功能A ---> 单独拉一个新分支 --> 开发完成后合并到master或者丢弃

2、分类

本地版本控制系统
集中化版本控制系统 SVN
分布式版本控制系统 Git

3、基本概念

repository 存放所有文件及其历史信息
checkout 取出或切换到执行版本的文件
version 表示一个版本
tag 记录标识一个主要版本。2.0 3.0。用来标识一个特定的version

4、不同版本控制系统优缺点

本地:
优点:
简单,很多系统中内置。适合保存文本文件(配置文件、文章、信件)

缺点:
只支持管理少量的文件,不支持基于项目的管理
支持的文件类型单一
不支持网络,无法实现多人协作

集中式版本控制系统
优点:
适合多人团队协作开发
代码集中化管理

缺点:
单点故障
必须联网工作,无法单机工作

解决:
分布式版本控制系统
集合集中式版本控制系统优点
支持离线工作,先提交到本地仓库,再在某个时间上传到远程仓库
每个计算机都是一个完整仓库:强备份。

二、git分布式版本管理系统

由Linux创始人开发,作为Linux内核代码管理系统使用。

Git在设计时考虑了很多方面设计目标

速度
简单的设计
对非线性开发模式的强力支持(允许上千个并行开发的分支)
完全分布式
有能力管理超大规模项目(挑战:速度和数据量)

Git原理:保存快照而非保存区别。
Git保存时,相当于保存了当下所有文件的一个整体快照。
所以,每个版本都是独立的。随时想取某一个版本,可以很快取出来。

三、安装git

Git 的工作区域:

Git repository 最终确定的文件保存到仓库,作为一个新的版本
staging area 暂存已经修改的文件
woking directory 工作目录

安装git
从 https://git-scm.com/ 下载windows版本git
全使用默认值,一直下一步

四、创建仓库和基本操作

git安装好后,需要一些基本设置
设置用户名:git config --global user.name "yibo"
设置邮箱:git config --global user.email "[email protected]"

查看所有设置 git config --list

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2
$ git init
Initialized empty Git repository in C:/Users/vilibra/Desktop/tzkt_demo2/.git/

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 (master)
$ ll -a
total 68
drwxr-xr-x 1 root 197121 0 4月 21 21:56 ./
drwxr-xr-x 1 root 197121 0 4月 21 21:55 ../
drwxr-xr-x 1 root 197121 0 4月 21 21:56 .git/

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 (master)
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

$ git status
On branch master

Initial commit

Untracked files:
(use "git add <file>..." to include in what will be committed)

README

nothing added to commit but untracked files present (use "git add" to track)

新建文件,默认是未追踪的文件

$ git add README
warning: LF will be replaced by CRLF in README.
The file will have its original line endings in your working directory.

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 (master)
$ git status
On branch master

Initial commit

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: README

git add 提交到了暂存区域

$ git commit -m "add README"
[master (root-commit) 6363356] add README
1 file changed, 1 insertion(+)
create mode 100644 README

提交到仓库

$ git commit -a -m "modify README"
warning: LF will be replaced by CRLF in README.
The file will have its original line endings in your working directory.
[master db6832b] modify README
1 file changed, 1 insertion(+)

删除文件
rm README
git rm README
git commit -m "delete README"

checkout 某个版本
$ git checkout db6832b5e55a506e29c1c920489208f8d3c881a4
Note: checking out 'db6832b5e55a506e29c1c920489208f8d3c881a4'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b <new-branch-name>

HEAD is now at db6832b... modify README

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 ((db6832b...))
$ ll
total 1
-rw-r--r-- 1 root 197121 24 4月 21 22:09 README

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 ((db6832b...))
$ cat README
Hello All
Hello world

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 ((db6832b...))
$ git checkout master
Previous HEAD position was db6832b... modify README
Switched to branch 'master'

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 (master)
$ ll
total 0

五、git远程仓库

实现代码共享
远程仓库实际保存了本地.git文件夹下的东西,内容几乎一样

git 远程仓库访问协议:

ssh协议
git协议
http https协议:一般用于开源项目

常用远程仓库实现:

1、github
2、自己搭建git仓库服务器 gitlab

举例:在自己的github中,关联本地仓库。

ssh-keygen -t rsa -C "[email protected]"命令 创建公钥

$ git remote add origin [email protected]:yibo4github/learnggit2.git

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 (master)
$ ll
total 1
-rw-r--r-- 1 root 197121 15 4月 21 22:13 README2

root@Lenovo MINGW32 ~/Desktop/tzkt_demo2 (master)
$ git push -u origin master
Counting objects: 11, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (11/11), 816 bytes | 0 bytes/s, done.
Total 11 (delta 0), reused 0 (delta 0)
To github.com:yibo4github/learnggit2.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.

----------------docker------------------------

2013年发布

一、环境配置难题

开发环境运行没有问题,生产不能用,因为生产缺乏某些组件。

换一台机器,需要重新配置一遍。

能不能从根本上解决问题:安装的时候,把原始环境,一模一样地安装一遍。

二、虚拟机

带环境安装的一种解决方案。

缺点:
占用资源多:虚拟机本身需要消耗资源,程序1M,环境几百MB。
冗余步骤多:虚拟机是完整的操作系统,一些系统级别的操作步骤,无法跳过,比如用户登录。
启动慢:启动操作系统要多久,启动虚拟机就要多久。

三、Linux容器

针对虚拟机的缺点,Linux发展出另外的一种虚拟化技术:Linux容器。

Linux容器不是模拟完整的操作系统,而是对进程进行隔离。
即在正常进程的外面,套一个保护层,对于容器里面的进程来说,它接触到的资源都是虚拟的,实现与底层系统的隔离。

优点:

启动快:容器里面的应用,直接就是底层系统中的一个进程,启动容器相当于启动本机的进程。而不是启动操作系统。
占用资源少:容器只占用需要的资源,不占用没有用到的资源。
体积小:只包含用到的组件,而虚拟机包含了整个操作系统。所以容器文件比虚拟机文件小的多。

四、Docker是什么?

Docker属于Linux容器的一种封装,提供了简单易用的容器使用接口。

Docker将应用程序与该程序的依赖,打包到一个文件里面,运行这个文件,就会产生一个虚拟容器。
程序在虚拟容器中运行,就好像运行在真正的物理机上一样。

Docker提供版本管理、复制、分享、修改等功能,就像管理普通代码一样管理Docker容器。

五、Docker的用途:

Docker的主要用途,目前有三大类。

1、提供一次性的环境:本地测试他人的软件程序。

2、提供弹性的云服务。Docker容器可以随开随关,很适合动态的扩容和缩容。

3、组建微服务架构。通过多个容器,一台机器可以跑多个服务,在本机就可以模拟出微服务架构。

六、Docker安装

1、Linux安装

Docker要求CentOS内核版本高于3.10
uname -r 查看内核版本

安装必要的系统工具:
yum install -y yum-utils device-mapper-persistent-data lvm2

添加软件源信息:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

更新 yum 缓存:
yum makecache fast

安装 Docker-ce:
yum -y install docker-ce

启动 Docker 后台服务
systemctl start docker

测试运行 hello-world
docker run hello-world

看到hello from docker证明安装成功。


2、windows安装

win10专业版,直接安装 docker for windows 即可。

win10普通版、win7 win8 ,需要安装 docker tool box

toolbox 配置:
右键 Docker Quickstart Terminal
"D:\Program Files (x86)\Git\bin\bash.exe" --login -i "C:\Program Files\Docker Toolbox\start.sh"
把这个位置配成你本机的git位置 修改后面这个脚本

DOCKER_MACHINE="C:\Program Files\Docker Toolbox\docker-machine.exe"


STEP="Looking for vboxmanage.exe"
VBOXMANAGE="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
#if [ ! -z "$VBOX_MSI_INSTALL_PATH" ]; then
# VBOXMANAGE="${VBOX_MSI_INSTALL_PATH}VBoxManage.exe"
#else
# VBOXMANAGE="${VBOX_INSTALL_PATH}VBoxManage.exe"
#fi

七、image文件

Docker把应用程序及其依赖,打包在image文件里面,只有通过image文件,才能生成docker容器。

Docker可以根据image文件生成容器实例。

image文件可以继承。在实际开发中,一个image文件往往通过继承另一个image文件,加上一些个性化的设置而生成。

启动容器
docker run hello-world

列出所有image文件
docker image ls

删除image文件
docker image rm image文件名

八、安装redis

1、搜索镜像:
docker search redis

2、拉取镜像
docker pull redis

3、启动redis

docker run --name myredis -p 6379:6379 -d redis redis-server

-d表示后台运行

-p表示端口号,左边的6379表示win10系统端口考,右边表示容器中redis端口号
--name表示运行redis镜像的实例名称

九、Kafka部署

前提:Zookeeper

官网下载安装包
http://kafka.apache.org/downloads

上传tar

解压
tar -zxvf ......

在kafka目录中,创建一个logs文件夹
如果不创建,默认放在 /tmp 目录下

修改 config/server.properties

broker.id=0
broker 的 全局唯一编号,不能重复

delete.topic.enable=true
允许删除topic

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3
处理网络请求的线程数量

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8
用来处理磁盘IO的线程数量

# A comma separated list of directories under which to store log files
log.dirs=/usr/local/kafka_2.11-2.1.1/logs
kafka运行日志存放的路径

zookeeper.connect=node3:2181,node4:2181,node5:2181
zookeeper相关信息

分发安装包
注意:要修改配置文件中 borker.id的值
broker id 不得重复

启动kafka集群
./bin/kafka-server-start.sh config/server.properties &

jps命令可以看Kafka进程

关闭命令:
bin/kafka-server-stop.sh stop

十、Kafka命令行操作

查看当前服务器中所有的topic

./bin/kafka-topics.sh --zookeeper node3:2181 --list

创建topic
./bin/kafka-topics.sh --zookeeper node3:2181 --create --replication-factor 3 --partitions 1 --topic second

删除topic
./bin/kafka-topics.sh --zookeeper node3:2181 --delete --topic second

发送消息
./bin/kafka-console-producer.sh --broker-list node3:9092 --topic second

消费消息
./bin/kafka-console-consumer.sh --bootstrap-server node3:9092 --from-beginning --topic second

消费者组消费:

修改 consumer.properties 配置文件
# consumer group id
group.id=tzkt

启动生产者

启动消费者
./bin/kafka-console-consumer.sh --bootstrap-server node3:9092 --topic second --consumer.config config/consumer.properties

CDH搭建:
https://juejin.im/post/5a55814e518825734859d69a

猜你喜欢

转载自www.cnblogs.com/jareny/p/10799802.html
今日推荐