1. 程式人生 > >docker搭建redis叢集

docker搭建redis叢集

序言

    在原來VM使用redis的時候,搭建的時候,需要下載redis的原始碼,然後進行編譯,安裝,配置檔案,啟動服務,好麻煩的。。。當使用docker的時候,指令太少了,簡單到爆炸。。。。

    作為一個快取伺服器或者是資料儲存伺服器,。。。redis還是相當簡單的。。

搭建redis叢集

    1、 首先需要將redis的映象檔案下載到本地:

    當直接pull redis的時候,沒有選擇版本號,那麼使用的是最新版本,最新版本的redis是4.0.6。。。

    這版本發展的真是快,生產環境基本上使用的版本號為2.8。。。。

?wx_fmt=png&wxfrom=5&wx_lazy=1

    2、 執行redis master服務

?wx_fmt=png

    3、 下載redis的配置檔案

[[email protected] ~]# wget  http://download.redis.io/redis-stable/redis.conf    

?wx_fmt=png

    在以上的配置主要將redis的主伺服器名稱寫入到配置檔案中,記得原來可以直接寫master的主機名或者ip就好了,現在。。。居然還要寫上相應的埠。

    4、 執行redis的slave伺服器

    在此處需要注意的是,兩個docker預設都是使用橋接模式,也就是使用的是docker0的橋,從而都會分配IP地址,在使用--link的時候,主要是為了從容器裡面能夠直接解析這個主機名,不需要在配置檔案寫上ip地址,由於是使用的自定義的配置檔案,從而需要將本地的配置檔案進行掛載上去,也就是-v引數的作用,將這個配置檔案掛載到redis伺服器,然後使用這個配置檔案啟動這個容器。


?wx_fmt=png

    5、 出錯的時候如果檢查錯誤

    在檢查錯誤的時候,主要是根據日誌來檢查

?wx_fmt=png

    如上的錯誤中,表示無法開啟redis的配置檔案,也就是在掛載的時候,許可權不對,然而這邊使用的是devicemapper驅動,從而許可權不對,所以無法開啟這個配置檔案,使用--privileged引數run即可。

    6、 容器其他

    在使用容器執行服務的時候,很乾淨,很清爽。。。。

?wx_fmt=png

    如上,執行的是redis的服務,這個只有這個一個程序。。。而且是使用的相應的使用者來進行執行,安全性也還是不錯的。

總結

    在這種環境下,一般是實驗性的測試,主備放在同一個機器上是不可以的,生產環境一般主備都分佈在不同的機器上面,畢竟。。。雞蛋不要放在一個籃子裡

。。。

    看下存在的網路情況及主機名的解析:

?wx_fmt=png

    如上,這個是安裝docker服務的時候,自動建立的橋接介面docker0介面。

    橋接模式如下所示:

?wx_fmt=png

    這個可以從物理主機上看見兩個虛擬的網絡卡,其實也就是和容器的網絡卡對應的,docker0橋接的相當於一個虛擬的交換機,從而容器之間能相互通訊,和物理主機也能進行通訊,如下所示:

?wx_fmt=png

我的腦子呢???---抱怨資訊。。。。沒耐心的可以不看。。。哈哈。。。

    this song is beautiful ,for sharing,then you can listen it ,thinking something....

    for much more times ,when i have the spare time,then ....always thinking....where is my time....who i am,.....where i am....why i am live ....

    I lost my mind....I lost my heart.....where to find it...how can i get it back....i dont know....

    I was in the lost forest,which always in the fucking shit place.....

    there was more challenge,challenge my life ,challenge my work,challenge my opnion....fuck you....a piece of shit....

    no more models to learn,in my dream this place is all tiger or wolf,but....all weak person...

    they say ,maybe you can learn how to manage person....but in my mind ,only dogs must be managed ,if the person must manage,they must be a piece of shit....far away from of the dogs.....

    In the virtual place,i will be weighte of the load balance,but if the hardware is not the good,i will not use it,but....the envirment is a fuck place....

    solve one problem ,there come one hundred problems,fuck you ....more and more problems in the road.....i am tied.....

    destorying my heart, broken my heart.... I have  lost .....my .....brain.....

    where to go...............

    I only say。。。。fuck my blind eyes......

    I miss you.....my brain......

?wx_fmt=jpeg