拜讀:docker容器與容器雲(2),拜讀docker

來源:互聯網
上載者:User

拜讀:docker容器與容器雲(2),拜讀docker

總結一下docker的學習搭建過程
看了3.1講的核心,比較懵逼
看了網上的挑一挑外掛,基於python和模擬器的,試了試,都整好了,結果模擬器上的挑一挑打不開了。。。

1,擷取鏡像docker pull haproxydocker pull redisdocker pull django2,分別啟動六個容器三個redis(一主兩從)docker run -it --name redis-master redis /bin/bashdocker run -it --name redis-slave1 --link redis-master:master redis /bin/bashdocker run -it --name redis-slave2 --link redis-master:master redis /bin/bash兩個Djangodocker run -it --name APP1 --link redis-master:db -v /root/Projects/Django/App1:/usr/src/app django /bin/bashdocker run -it --name APP2 --link redis-master:db -v /root/Projects/Django/App2:/usr/src/app django /bin/bash一個HAProxydocker run -it --name HAProxy --link APP1:APP1 --link APP2:APP2 -p 6301:6301 -v ~/Projects/HAProxy:/tmp haproxy /bin/bash建議開七個視窗
2,配置三個redis針對沒有使用-v參數的容器  查看他的預設掛載點查看對應的掛載點 docker inspect imageID | grep Source從網上下載redis.conf【地址:http://download.redis.io/releases/redis-4.0.6.tar.gz】檔案。對應的大版本就行流程是:

1,使用docker ps -a 查看所有容器在,在使用docker inspect f2b | grep -E "Source|Destination"命令查看三個redis對應的掛載目錄
source對應的是主機的掛載點,Destination對應的是容器中與之對應的掛載點2,拷貝redis.confcd <Source.value>cp <you_redis.conf_dir>/redis.conf redis,conf3,修改參數,主節點修改三個參數band 0.0.0.0 #不然會搜尋不到主redisdeamonize yespidfile /var/run/redis.pid從節點修改四個參數band 0.0.0.0deamonize yespidfile /var/run/redis.pid #這裡該不該都行slaveof master 63794,進入對應的容器5,進入到對應的掛載點目錄,cd <Destination.value>6,將其redis.conf拷到 /usr/local/bin/,7,啟動redis,redis.server redis.conf8,測試主從redisredis-cli 進入到redis的命令,使用set和get對其設定值和取值

3,配置兩個App
1 在容器中使用pip命令安裝redispip install redis測試
2,建立並啟動App使用容器中python+Django環境產生cd /usr/src/appmkdir dockerwebcd dockerwebcd dockerwebdjango-admin.py startproject rediswebcd rediswebpython manage.py startapp helloworld產生helloworld檔案切換到主機中,編輯相應的設定檔:views、setting、urlscd /root/Projects/Django/App1/dockerweb/redisweb/helloworld/vim views.pyfrom django.shortcuts import render# Create your views here.from django.http import HttpResponseimport redisdef hello(request):    str = redis.__file__    str += "<br>"    r = redis.Redis(host='db',port=6379, db=0)    info = r.info()    str += ("set hi <br>")    r.set('Hi','Helloworld-APP1')    str +=("Get Hi:%s <br>" % r.get('Hi'))    str +=("Redis Info:<br>")    str +=("Key:Info Value")    for key in info:        str += ("%s : %s <br>" % (key,info[key]))    return HttpResponse(str)編輯setting檔案cd ../redisweb/#允許外來訪問ALLOWED_HOSTS = ['*']#添加helloworld項目# Application definitionINSTALLED_APPS = [    'django.contrib.admin',    'django.contrib.auth',    'django.contrib.contenttypes',    'django.contrib.sessions',    'django.contrib.messages',    'django.contrib.staticfiles',    'helloworld',]編輯urls.py添加引用from helloworld.views import hello增加連結url(r'^helloworld$',hello),

編譯helloworld項目python manage.py makemigrationspython manage.py migratepython manage.py createsuperuser #設定後台管理的使用者名稱和密碼 郵箱隨便設定
啟動helloworld項目python manage.py runserver 0.0.0.0:8001

4,HAProxy容器節點的配置
1,編輯haproxy.cfg檔案cd ~/Projects/HAProxyvim haproxy.cfgglobal  log 127.0.0.1 local0  maxconn 4096  chroot /usr/local/sbin  daemon  nbproc 4  pidfile /usr/local/sbin/haproxy.piddefaults  log 127.0.0.1 local3  mode http  option dontlognull  option redispatch  retries 2  maxconn 2000  balance roundrobin  timeout connect 5000ms  timeout client 50000ms  timeout server 50000mslisten redis_proxy  bind 0.0.0.0:6301   bind-process 2 #pao zai laing ge CPU shang`  stats enable  stats uri /haproxy-stats      server APP1 APP1:8001 check inter 2000 rise 2 fall 5      server APP2 APP2:8002 check inter 2000 rise 2 fall 5
適當的注釋(註:這裡少了兩項: bind 0.0.0.0:6301,bind-process 2 #pao zai laing ge CPU shang`)
2,進入容器並啟動cd /tmpcp  haproxy.cfg /usr/local/sbincd /usr/local/sbinhaproxy -f haproxy.cfg注:殺死所有有關HAProxy的進程:killall haproxy測試


美好的一天  明天加油
著作權聲明:菜鳥曆程,多多指教! http://blog.csdn.net/u013991917/article/details/79039635

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.