docker專題

---------------git 版本控制系統-------------------
git是一個版本控制系統node

1、什麼是版本控制系統?

一、概念

版本控制是一種 記錄一個或若干文件內容變化,以便未來查閱特定版本修訂狀況的系統。

(*)記錄文件的全部歷史變化
(*)隨時可恢復到任何一個歷史狀態
(*)多人協做開發或修改
(*)錯誤恢復
(*)多功能並行開發

產品--> 新加功能A ---> 單獨拉一個新分支 --> 開發完成後合併到master或者丟棄

二、分類

本地版本控制系統
集中化版本控制系統 SVN
分佈式版本控制系統 Gitlinux

三、基本概念

repository 存放全部文件及其歷史信息
checkout 取出或切換到執行版本的文件
version 表示一個版本
tag 記錄標識一個主要版本。2.0 3.0。用來標識一個特定的version

四、不一樣版本控制系統優缺點

本地:
優勢:
簡單,不少系統中內置。適合保存文本文件(配置文件、文章、信件)

缺點:
只支持管理少許的文件,不支持基於項目的管理
支持的文件類型單一
不支持網絡,沒法實現多人協做

集中式版本控制系統
優勢:
適合多人團隊協做開發
代碼集中化管理

缺點:
單點故障
必須聯網工做,沒法單機工做

解決:
分佈式版本控制系統
集合集中式版本控制系統優勢
支持離線工做,先提交到本地倉庫,再在某個時間上傳到遠程倉庫
每一個計算機都是一個完整倉庫:強備份。git

2、git分佈式版本管理系統

由Linux創始人開發,做爲Linux內核代碼管理系統使用。

Git在設計時考慮了不少方面設計目標

速度
簡單的設計
對非線性開發模式的強力支持(容許上千個並行開發的分支)
徹底分佈式
有能力管理超大規模項目(挑戰:速度和數據量)

Git原理:保存快照而非保存區別。
Git保存時,至關於保存了當下全部文件的一個總體快照。
因此,每一個版本都是獨立的。隨時想取某一個版本,能夠很快取出來。

3、安裝git

Git 的工做區域:

Git repository 最終肯定的文件保存到倉庫,做爲一個新的版本
staging area 暫存已經修改的文件
woking directory 工做目錄

安裝git
從 https://git-scm.com/ 下載windows版本git
全使用默認值,一直下一步

4、建立倉庫和基本操做

git安裝好後,須要一些基本設置
設置用戶名:git config --global user.name "yibo"
設置郵箱:git config --global user.email "yibo_qa@163.com"

查看全部設置 git config --list

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

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 masterredis

Initial commitdocker

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

$ git status
On branch masterapache

Initial commitbootstrap

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

READMEcentos

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

5、git遠程倉庫

實現代碼共享
遠程倉庫實際保存了本地.git文件夾下的東西,內容幾乎同樣

git 遠程倉庫訪問協議:

ssh協議
git協議
http https協議:通常用於開源項目

經常使用遠程倉庫實現:

一、github
二、本身搭建git倉庫服務器 gitlab

舉例:在本身的github中,關聯本地倉庫。

ssh-keygen -t rsa -C "email@email.com"命令 建立公鑰

$ git remote add origin git@github.com: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年發佈

1、環境配置難題

開發環境運行沒有問題,生產不能用,由於生產缺少某些組件。

換一臺機器,須要從新配置一遍。

能不能從根本上解決問題:安裝的時候,把原始環境,如出一轍地安裝一遍。

2、虛擬機

帶環境安裝的一種解決方案。

缺點:
佔用資源多:虛擬機自己須要消耗資源,程序1M,環境幾百MB。
冗餘步驟多:虛擬機是完整的操做系統,一些系統級別的操做步驟,沒法跳過,好比用戶登陸。
啓動慢:啓動操做系統要多久,啓動虛擬機就要多久。

3、Linux容器

針對虛擬機的缺點,Linux發展出另外的一種虛擬化技術:Linux容器。

Linux容器不是模擬完整的操做系統,而是對進程進行隔離。
即在正常進程的外面,套一個保護層,對於容器裏面的進程來講,它接觸到的資源都是虛擬的,實現與底層系統的隔離。

優勢:

啓動快:容器裏面的應用,直接就是底層系統中的一個進程,啓動容器至關於啓動本機的進程。而不是啓動操做系統。
佔用資源少:容器只佔用須要的資源,不佔用沒有用到的資源。
體積小:只包含用到的組件,而虛擬機包含了整個操做系統。因此容器文件比虛擬機文件小的多。

4、Docker是什麼?

Docker屬於Linux容器的一種封裝,提供了簡單易用的容器使用接口。

Docker將應用程序與該程序的依賴,打包到一個文件裏面,運行這個文件,就會產生一個虛擬容器。
程序在虛擬容器中運行,就好像運行在真正的物理機上同樣。

Docker提供版本管理、複製、分享、修改等功能,就像管理普通代碼同樣管理Docker容器。

5、Docker的用途:

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

一、提供一次性的環境:本地測試他人的軟件程序。

二、提供彈性的雲服務。Docker容器能夠隨開隨關,很適合動態的擴容和縮容。

三、組建微服務架構。經過多個容器,一臺機器能夠跑多個服務,在本機就能夠模擬出微服務架構。

6、Docker安裝

一、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證實安裝成功。


二、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

7、image文件

Docker把應用程序及其依賴,打包在image文件裏面,只有經過image文件,才能生成docker容器。

Docker能夠根據image文件生成容器實例。

image文件能夠繼承。在實際開發中,一個image文件每每經過繼承另外一個image文件,加上一些個性化的設置而生成。

啓動容器
docker run hello-world

列出全部image文件
docker image ls

刪除image文件
docker image rm image文件名

8、安裝redis

一、搜索鏡像:
docker search redis

二、拉取鏡像
docker pull redis

三、啓動redis

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

-d表示後臺運行

-p表示端口號,左邊的6379表示win10系統端口考,右邊表示容器中redis端口號
--name表示運行redis鏡像的實例名稱

9、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

10、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

相關文章
相關標籤/搜索