1 / 33

drbd

drbd. 阿晃. drbd & hb 安裝. rpm - Uvh http://120.125.145.43/public/ha/rpm_819/rpmforge-release-0.5.2-2.el6.rf.i686.rpm rpm - Uvh http://120.125.145.43/public/ha/rpm_819/elrepo-release-6-4.el6.elrepo.noarch.rpm rpm - Uvh http://120.125.145.43/public/ha/rpm_819/epel-release-6-5.noarch.rpm

violet
Download Presentation

drbd

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. drbd 阿晃

  2. drbd & hb安裝 • rpm -Uvh http://120.125.145.43/public/ha/rpm_819/rpmforge-release-0.5.2-2.el6.rf.i686.rpm • rpm -Uvh http://120.125.145.43/public/ha/rpm_819/elrepo-release-6-4.el6.elrepo.noarch.rpm • rpm -Uvh http://120.125.145.43/public/ha/rpm_819/epel-release-6-5.noarch.rpm • yum -y install gcc • yum -y install drbd83-utils kmod-drbd83 • yum -y install heartbeat heartbeat-devel heartbeat-libs • chkconfigdrbd off • chkconfig heartbeat off • reboot

  3. apache ha • 1.) 安裝 apache • 2.) 設定DRBD資料同步 • apache documentroot > 改為/data • 只有primary node可以存取 /data • 3.) 設定Heartbeat • 監控apache • primary node apache 失效  自動切換由Secondary (備用)node 接手apache • 4.) apache 架設完成後 • 手動切換node  test是否可自動切換apache 服務 • 各種故障  apache HA是否還可用 • 5.) apache HA更改設定 •  Cluster ip更改 • 正確關/開機流程

  4. 1.) 安裝 apache (01, 02) • yum -y install httpd • rpm -qa | grephttpd

  5. 2.) 設定DRBD資料同步7步驟 -1 • 2.1 修改DRBD設定檔 (01 &02) • /etc/drbd.conf • 2.2 載入DRBD模組&啟動服務 (01 & 02) • 2.3 初始化apache01的/data partition - /dev/sda5 (你的可能不是這partition)only 01 • 亦即先同步兩台nodes的/dev/sda5 (未來的/data) • 其實,就是在primary node執行resync process以確保secondary的/dev/sda5與primary的相同,這動作當然只在primary做 • 2.4 primary格式化 /dev/sda5 (你的可能不是這partition)  only 01

  6. 2.) 設定DRBD資料同步 -2 • 2.5 修改apache /etc/httpd/conf/httpd.conf • 01 & 02 (/etc並沒有同步) • DocumentRoot原/var/www/html 改為/data • only 01: 建/data/index.html 內容為”apache ok!” • /data 有sync, 02不需做 • 2.6 啟動apache - only 01 • win7 test http://10.10.88.111 (apache01.abc.com) • 接下來要設Heartbeat了,設定hb之前 only 01 做以下三件事 • 先把 apache stop • umount /data • 01 的DRBD 資源角色降為secondary • 不然heartbeat會無法設定 • 02 不會做 • DRBD 設定結束

  7. 2.1 :修改DRBD設定檔(01 &02) 修改/etc/drbd.conf p1 • ftp://120.125.145.81/ha/drbd.conf.txt • 此檔為drbdadm的設定檔,兩台必須完全相同 • 所有參數參考 • http://www.drbd.org/users-guide-8.3/re-drbdconf.html • 有一些參數細節,目前不重要,比如usage-count yes就是告知drbd.org”我正在使用drbd” • 資料同步模式 - Protocol C: • 同步複製協定:Primary與Standby伺服器皆寫入資料並確認後才回報完成,可降低資料漏失風險,但此方式網路頻寬需求較大。 • DRBD同步速率為100Mbps(bits),單.conf中的單位為bytes除以8,取約略10Msyncer { rate 10M; } • resource ha DRBD資源名稱:ha • handlers  處理drbd的一些shell script • wfc-timeout: wait-for-connection時限(01先啟動 drbd, 02必須在60秒內啟動) • outdated-wfc-timeout: 每隔2秒看看對方 drbd是不是掛了 • apache01 server資訊on apache01.abc.com { device /dev/drbd0; //device名稱,用來代表 /dev/sda5,就是/data disk /dev/sda5; // “/data”的partition,可用fdisk -l查//因為已umount,請用fdisk -l查 address 192.168.88.111:7788; //drbd同步ip & port meta-disk internal;} • apache02 server資訊,意義同上

  8. matadata, meta-disk是什麼? p2 • metadata • 描述資源/data屬性的data • 也就是描述/data的 • DRBD設備的大小 • flag • journal … • 存放metadata的disk叫做meta-disk • meta-disk 存儲方式有internal & external兩種 • internal:metadata存放在同一partition最後位置 • ..有興趣的再去K文獻,不是很重要

  9. 2.1 :修改DRBD設定檔(01 &02) 修改/etc/drbd.confp3 • drbd.conf兩台都改好之後,必須調整drbd相關執行檔的權限,待會兒建立drbd資源(就是建立metadata)時會出錯 • ftp://120.125.145.81/ha/change_per_drbd.txt • chgrphaclient /sbin/drbdsetup • chmod o-x /sbin/drbdsetup • chmodu+x /sbin/drbdsetup • chgrphaclient /sbin/drbdmeta • chmod o-x /sbin/drbdmeta • chmodu+x /sbin/drbdmeta • 目的是讓後續建DRBD資源時,可以順利執行相關指令

  10. 2.2: 載入DRBD模組&啟動服務(01 & 02) p1 • modprobe指令載入drbd模組 (locate drbd.ko確認有此module) • modprobedrbd • 確認 drbd模組是否載入 • lsmod|grepdrbd • 執行drbd之前,必須塞一些資料到/dev/sda5內,否則create-md時會出現錯誤 • dd if=/dev/zero of=/dev/sda5 bs=1M count=100 • sda5就是/data的partition • 載入drbd moduleok後,建立 drbd resource, 指令 • drbdadm create-md 資源名稱,因為在 drbd設定檔(drbd.conf)中 resource 名稱為 ha 所以上述的資源名稱就是以ha取代,指令如下:drbdadm create-md ha (執行成功後,可以以 ctrl+c跳出) • 啟動 drbd服務 (01先啟動, 02必須在60秒內啟動) • service drbd start • 設定 drbd開機時自動啟動 • chkconfigdrbd on • 所有指令: • ftp://120.125.145.81/ha/drbd_load_mo_create_rs.txt

  11. 上一頁,指令匯整(01 & 02都要做) p2 • modprobedrbd //載入 drbd模組 • lsmod|grepdrbd //確認 drbd模組是否載入 • dd if=/dev/zero of=/dev/sda5 bs=1M count=100//執行drbd之前,必須塞一些資料到/dev/sda5內(否則 create-md 時會出現錯誤) • drbdadm create-md ha //建立 drbd resource • service drbd start //啟動 drbd服務 • (01先啟動, 02必須在60秒內啟動) • chkconfigdrbd on //設定 drbd開機時自動啟動

  12. 2.2: 載入DRBD模組&啟動服務(01 & 02) p3 • 從01 & 02 看目前drbd狀態 • 影片 • http://youtu.be/irGmU6rm2_Q?hd=1

  13. 補充一下drbd status的一些資訊 • IBM的info: • http://pic.dhe.ibm.com/infocenter/ntz/v7r0m3/index.jsp?topic=%2Fcom.ibm.nz.adm.doc%2Fr_sysadm_sample_drbd_status.html

  14. 2.3 初始化apache01的(only 01)/data的partition - /dev/sda5 p1 • 確定上一頁的drbdcs為connected • 01 初始化指的是 • 01 promote自己為primary • 01 把 /dev/sda5 resync到 02 的 /dev/sda5 • 01 & 02都先開watch service drbd status監看畫面 • 01再開另一terminal(或剛才用&執行watch),promote自己為primary node • 01執行drbdadm, promote為DRBD primary node • drbdadm -- --overwrite-data-of-peer primary ha • ftp://120.125.145.81/ha/01_promote_to_primary_via_drbdadm-primary-RESOURCE_NAME.txt • 01 promote為primary的同時,會開始同步定義在drbd.conf中的disk 到02,也就是/dev/sda5 (未來的 /data) • 其實,就是在primary node執行resync process以確保secondary的/dev/sda5與primary的相同,這動作當然只在primary做

  15. 2.3 初始化apache01的(only 01)/data的partition - /dev/sda5 p2 • 01 & 02先開: watch service drbd status監看畫面 • 01執行: drbdadm-- --overwrite-data-of-peer primary ha • 影片 • http://youtu.be/eBaSN85mE6Y?hd=1錄音時,mic一直有爆音,爛mic~

  16. 2.4 primary格式化 /dev/sda5 (only 01) p1 • 確定01 & 02 /dev/sda5已同步 • drbd status 中的 ds (data state): UpToDate • 01 把 /dev/drbd0 (就是/dev/sda5)格式化掉 • mkfs.ext4 /dev/drbd0 (只要01做就好了,02不需做) • 這個/dev/drbd0從那兒來的?? • 在drbd.conf中的device /dev/drbd0;disk /dev/sda5;定義 /dev/drbd0 就是 disk /dev/sda5 • 把/dev/drbd0 mount到/data • 啊~不是說drbddisk不要用 mount的嗎?? • 因為我們等一下要test http://apache01.abc.com/index.html 當然要先把 /data 掛到 /dev/sda5 partition,啊不然不就連到/的partition下的/data去了 • 要設定heartbeat前,當然要先把/data再umount回來 • mount /dev/sda5 /data • df -h

  17. 2.4 primary格式化 /dev/sda5 (only 01) p2 • 格式化 /dev/drbd0 & mount to /data 練習 • 影片: • http://youtu.be/bKGLKXY-GkM?hd=1

  18. 2.5 修改apache /etc/httpd/conf/httpd.conf (01 & 02) • 01 & 02 都要做(/etc並沒有同步) • DocumentRoot:原/var/www/html改為 /data • #DocumentRoot“/var/www/html“  改為DocumentRoot"/data" • #<Directory "/var/www/html"> 改為<Directory "/data"> • 然後only 01: • 建/data/index.html 內容為”<h1>jj apache ok.</h1>” • 02不需做, /data 有sync  • 但只有drbd&heartbeat看得到

  19. 2.6 啟動apache - only 01 p1 • service httpd start • 啟動apache,若出現DocumentRoot must be a directory無法啟動,是因為selinux沒有關 • sestatus(耶? selinux竟然不能用 disabled 關掉,沒關係,手動調整/data的安全機制即可) • 因/data的selinux安全機制與原來的 /var/www/html不同,必須做調整 • 執行下面兩個指令,再啟動httpd即可semanagefcontext -a -t httpd_sys_content_t "/data(/.*)?“restorecon-Rv /data

  20. 2.6 啟動apache - only 01 p2 • service httpd start • win7 test http://10.10.88.111 (apache01.abc.com) • 接下來要設Heartbeat了,設定hb之前 (only 01)做以下三件事 • 先把 apache stop • umount /data • 01 的DRBD 資源角色降為secondary • 不然heartbeat會無法設定 • 02 不用做

  21. 2.6 啟動apache - only 01 p3 • 先把 apache stop • service httpd stop • df -h • umount/data • df -h • 01 的DRBD 資源角色降為secondary • 執行前先開 watch service drbd status • drbdadmsecondary ha (觀察上面drbd status) • DRBD 設定結束

  22. DRBD是針對資料備份 • apache的DocumentRoot,就是/data • Heartbeat是針對服務偵測 • apache httpd service

  23. 3.) Heartbeat 偵測服務 • 3.1 設定 Heartbeat 通訊設定檔 /etc/ha.d/ha.cf • 3.2 設定 Heartbeat 資源設定檔/etc/ha.d/haresources • 3.3 設定 Heartbeat 驗證設定檔/etc/ha.d/authkeys • 3.4 設定 Heartbeat 偵測服務設定檔/etc/ha.d/resource.d/Apache

  24. 3.1 設定 Heartbeat 通訊設定檔(01 & 02)/etc/ha.d/ha.cf p01 • 2台 HA Server,其中一台會產生一個cluster ip,擁有cluster ip的 active node會回應client users的要求 • 當故障轉移(failover)時,新的active node會接手該cluster ip,並更新arp cache中cluster ip所對應的mac • 意即:改成自己的mac, client就可以”無斷線感地”持續要求服務.

  25. 3.1 設定 Heartbeat 通訊設定檔 /etc/ha.d/ha.cf p02 • 其實偵測對方是否死掉,就是用簡單的ping而已 • 每隔2秒互ping對方一次 • 超過15秒對方沒有回應,就認定對方死了 • 兩台server的Heartbeat通訊設定檔為 • /etc/ha.d/ha.cf (原無此檔),請自行vim • ftp://120.125.145.81/ha/ha.cf.txt • 不需改權限

  26. 3.1 設定 Heartbeat 通訊設定檔(01) /etc/ha.d/ha.cf p03 • debugfile /var/log/ha-debug //Heartbeat服務除錯記錄檔 • logfile /var/log/ha-log //Heartbeat服務記錄檔logfacilitylocal0 • autojoin none • ucastbond0 10.10.88.112 //指定對方(apache02)的bond0 ip (service) • ucastbond1 192.168.88.112 //指定對方(apache02)的bond1 ip (drbd+heartbeat) • ping 10.10.88.254 ////IP 連線偵測用,設定區網內的 Gateway (當網路或 Heartbeat 失效時測試用 • (因為有可能是 heartbeat掉了而已,所以ping一下gw是否還是通的) • respawnhacluster /usr/lib/heartbeat/ipfail • respawnhacluster /usr/lib/heartbeat/dopd • apiauthdopdgid=haclientuid=hacluster • udpport694 // 使用 udp, port 694來 做通訊 • warntime5 //網路disconnect超過5秒就warn • deadtime15 // 網路disconnect超過15秒,就判定對方主機失效 • initdead60 //初始化超過60秒沒有連上對方,就判定 heartbeat 一開始就沒有成功 • keepalive2 //每2秒互ping對方是否還活著 • node apache01.abc.com // 第一台 • node apache02.abc.com // 第二台 • auto_failbackoff // Active node 恢復也不會搶回主控權

  27. 3.1 設定 Heartbeat 通訊設定檔(02)/etc/ha.d/ha.cf p04 • debugfile /var/log/ha-debug //Heartbeat服務除錯記錄檔 • logfile /var/log/ha-log //Heartbeat服務記錄檔logfacilitylocal0 • autojoin none • ucastbond0 10.10.88.111 //指定對方(apache01)的bond0 ip (service) • ucastbond1 192.168.88.111 //指定對方(apache01)的bond1 ip (drbd+heartbeat) • ping 10.10.88.254 ////IP 連線偵測用,設定區網內的 Gateway (當網路或 Heartbeat 失效時測試用 • (因為有可能是 heartbeat掉了而已,所以ping一下gw是否還是通的) • respawnhacluster /usr/lib/heartbeat/ipfail • respawnhacluster /usr/lib/heartbeat/dopd • apiauthdopdgid=haclientuid=hacluster • udpport694 // 使用 udp, port 694來 做通訊 • warntime5 //網路disconnect超過5秒就warn • deadtime15 // 網路disconnect超過15秒,就判定對方主機失效 • initdead60 //初始化超過60秒沒有連上對方,就判定 heartbeat 一開始就沒有成功 • keepalive2 //每2秒互ping對方是否還活著 • node apache01.abc.com // 第一台 • node apache02.abc.com // 第二台 • auto_failbackoff // Active node 恢復也不會搶回主控權

  28. 3.2 設定 Heartbeat 資源設定檔 /etc/ha.d/haresources, 原為空檔(01 & 02) • 設定 01 & 02的 haresource資源設定檔 01 及 02 設定檔內容一模一樣, • 表示預設使用 01 主機擔任 Primary Node 角色,此設定檔內容可分為五段來看。(01 及 02 都必須設定) • 1.) active Node 的 FQDN >> apache01.abc.com • 2.) 指定 Cluster IP Address : 10.10.88.110 • 3.) 指定 Cluster Resource Name >> drbddisk::ha • 4.) 指定 Cluster Device, Mount Point、File System Type • >> drbddisk::ha Filesystem::/dev/drbd0::/data::ext4 • 5.) 指定 Service>> Apache • haresources設定檔內容如下 (01 & 02完全相同) • apache01.abc.com IPaddr::10.10.88.110/24/eth0 drbddisk::ha Filesystem::/dev/drbd0::/data::ext4 Apache • 檔案內容:ftp://120.125.145.81/ha/heartbeat_etc_ha.d_haresources.txt • 不需改權限

  29. 3.3 Heartbeat 驗證設定檔01 & 02均同, /etc/ha.d/authkeys p1 • 此設定檔為 Cluster Node 之間的密碼,也就是主機必須具備此一密碼檔才會被認為是同一個 Cluster 中的 Node,此次使用 sha1 編碼方式並使用 urandom指令將一堆亂數寫入檔案內當作 Cluster 密碼,此步驟在 Node1 主機執行完成後請利用 scp指令將檔案複製到 Node2 主機中以便保持密碼檔案一致。

  30. 3.3 Heartbeat 驗證設定檔01 & 02均同, /etc/ha.d/authkeys p2 • 一台執行此指令產生authkeys: • (echo -ne "auth 1\n1 sha1 ";dd if=/dev/urandombs=512 count=1 | openssl md5 | cut -d= -f2) > /etc/ha.d/authkeys • 另一台此檔,用copy-paste即可 • ftp://120.125.145.81/ha/authkeys_cmd.txt • 600 permission: • chmod 600 /etc/ha.d/authkeys

  31. 3.4 設定 Heartbeat 偵測服務設定檔(01 & 02均同) /etc/ha.d/resource.d/Apache p1 • ftp://120.125.145.81/ha/Apache.txt • Active 死掉後,standby根豦此檔決定要啟動什麼服務 • 755 permission • chmod 755 /etc/ha.d/resource.d/Apache

  32. 01 & 02新增heartbeat為系統服務 • chkconfig --add heartbeat • chkconfig heartbeaton

  33. 01 & 02 啟動 heartbeat • service heartbeat start • ifconfig eth0:0

More Related