dbrd 8.4.6 源碼編譯安裝,dbrd8.4.6源碼編譯
----------------------------0.系統內容----------------------------db01 192.168.50.10 /dev/sdb1 主節點db02 192.168.50.20 /dev/sdb1 備節點# grep -v "#" /etc/hosts192.168.50.10 db01 db01.mysql.com192.168.50.20 db02 db02.mysql.com#一塊新硬碟ll /dev/sd*ll /dev/sdb*brw-rw---- 1 root disk 8, 16 Jun 24 13:37 /dev/sdbbrw-rw---- 1 root disk 8, 17 Jun 24 13:37 /dev/sdb1NOTE:sdb1分區未格式化.----------------------------1.準備安裝環境----------------------------yum install -y make automak kernel kernel-devel kernel-headers gcc flex libxslt----------------------------2.編譯安裝drbd----------------------------wget http://oss.linbit.com/drbd/8.4/drbd-8.4.6.tar.gztar xzf drbd-8.4.6.tar.gzcd drbd-8.4.6------------------#開始編譯安裝drbd,和8.4.5之前版本有所不同,這裡不用./configure,直接make就可以了./configure --prefix=/usr/local/drbd --with-km --with-heartbeat --sysconfdir=/etc/#with-km開啟核心模組#with-heartbeat 開啟heart支援#ls -ld /usr/src/kernels/$(uname -r)/make KDIR=/usr/src/kernels/$(uname -r)/ #指定核心源路徑開始編譯#make install--直接結果:make -C drbd installmake[1]: Entering directory `/soft/drbd-8.4.6/drbd'install -d //lib/modules/2.6.32-431.el6.x86_64/updatesinstall -m 644 drbd.ko //lib/modules/2.6.32-431.el6.x86_64/updates/sbin/depmod -a || /sbin/depmod -e drbd.ko 2>&1 >/dev/null || truemake[1]: Leaving directory `/soft/drbd-8.4.6/drbd'編譯成功模組安裝位置#modprobe -l | grep -i drbdupdates/drbd.ko載入模組# modprobe drbd#lsmod | grep drbddrbd 376868 0 libcrc32c 1246 1 drbd----------------------------3.編譯安裝drbd-utils----------------------------#wget http://oss.linbit.com/drbd/drbd-utils-8.9.3.tar.gz-P /usr/local/src/# tar -xf drbd-utils-8.9.3.tar.gz -C /usr/local/src# cd /usr/local/src/drbd-utils-8.9.3這裡用了--without-83support,因為安裝的是8.4以上版本#./configure --prefix=/usr/local/drbd --sysconfdir=DIR --without-83support/******************參數詳解Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/drbd] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR]Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-spec Rather than creating Makefiles, create an RPM spec file onlyOptional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --without-83support Do not include support for drbd driver/module <= 8.3 --without-84support Do not include support for drbd driver/module 8.4 --with-udev Enable udev integration --with-xen Enable Xen integration --with-pacemaker Enable Pacemaker integration --with-heartbeat Enable Heartbeat v1 haresources integration scripts --with-rgmanager Enable Red Hat Cluster Suite integration --with-bashcompletion Enable programmable bash completion --with-distro Configure for a specific distribution (supported values: generic, redhat, suse, debian, gentoo, slackware; default is to autodetect) --with-initdir Override directory for init scripts (default is distribution-specific) --with-noarchsubpkg Build subpackages that support it for the "noarch" architecture (makes sense only with --enable-spec, supported by RPM from 4.6.0 forward) --with-systemdunitdir=DIR Directory for systemd service files [Auto] --with-tmpfilesdir=DIR install configuration files for management of volatile files and directories in DIR [[PREFIX/lib/tmpfiles.d]] --with-initscripttype=INIT_SCRIPT_TYPE Type of init script to install (sysv|systemd|both). [auto]********************************/#make#make install 安裝成功後drbd相關的工具(drbdadm,drbdsetup)被安裝到/usr/local/drbd-utils-8.9.3/etc/sbin目錄下#cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d/#chkconfig --add drbd#chkconfig --level 2345 drbd on#連結drbd的命令到系統命令路徑ln -s /usr/local/drbd/sbin/* /usr/bin/----------------------------4.設定drbd.conf設定檔----------------------------本次編譯安裝設定檔位置:/usr/local/drbd/etc/#vi /etc/drbd.conf----------------------------5.啟動--------------------------------5.0 在兩台機器上配置r0資源 兩台機器上分別初始化r0資源,建立DRBD分區準備初始化之前,需要分別在2個主機上的 空白分區上建立相應的中繼資料儲存的資料區塊:常見之前現將兩塊空白分區徹底清除資料,分別在兩個主機上執行dd if=/dev/zero of=/dev/sdb1 bs=1M count=128 drbdadm -c /etc/drbd.conf create-md all或drbdadm -c /etc/drbd.conf create-md r0 --5.1啟動兩個節點drbdmkdir -p /usr/local/drbd/var/run/drbd#/etc/init.d/drbd start Starting DRBD resources: no resources defined!no resources defined!no resources defined!PS:提示沒有定義“資源”,這是因為剛安裝好的DRBD,預設沒有*.res設定檔#netstat |grep 7788--5.2 查看狀態:#/etc/init.d/drbd status drbd driver loaded OK; device status:version: 8.4.6 (api:1/proto:86-101)GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by root@db01.mysql.com, 2015-06-24 13:47:15m:res cs ro ds p mounted fstype0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent Ccs:表示串連狀態ro: 表示主從關係 上面的表示都為從ds:硬碟狀態資訊 上面表示已經即時同步中,Inconsistent:不一致# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101)GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by root@db01.mysql.com, 2015-06-24 13:47:15 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:40088 nr:0 dw:0 dr:40248 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0# drbd-overview 0:r0/0 Connected Secondary/Secondary Inconsistent/Inconsistent--5.3 查看版本#cat /proc/drbd --5.4 查看位置whereis drbd ----------------------------6.操作--------------------------------6.1 設定節點為主節點#第1步:設定主從第一次執行#drbdadm -- --overwrite-data-of-peer primary all#第2步:第一次執行後平常執行下面兩個其中一個命令#drbdadm primary --force r0 #drbdadm primary all#第3步:設定當前節點為主節點# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101)GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by root@db01.mysql.com, 2015-06-24 13:47:15 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:40088 nr:0 dw:0 dr:40248 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0#drbdadm primary --force r0 # cat /proc/drbd version: 8.4.6 (api:1/proto:86-101)GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by root@db01.mysql.com, 2015-06-24 13:47:15 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:40088 nr:0 dw:0 dr:40248 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0說明:ro狀態變為ro:Primary/Secondary;ds狀態為:UpToDate/UpToDate(inconsisten) 即"即時/即時(不一致)"-----6.2 磁碟格式化(只對primary節點格式化)#drbd-overview 0:r0/0 Connected Primary/Secondary UpToDate/UpToDate 同步完畢之後,就可以對空白磁碟格式化了.#mkfs.ext4 /dev/drbd0 mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks10040 inodes, 40088 blocks2004 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=411566085 block groups8192 blocks per group, 8192 fragments per group2008 inodes per groupSuperblock backups stored on blocks: 8193, 24577Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 33 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.----6.3掛載DRBD分區到本地(只能在primary節點上掛載)# mkdir /drbd_data# mount /dev/drbd0 /drbd_data/# cd /drbd_data/#ls ----6.4 常見命令--6.4.1 查看資源角色(前面代表當前資源角色)# drbdadm role r0 Primary/Secondary---6.4.2 查看資源串連狀態#drbdadm cstate r0 Connected---6.4.3 查看硬碟資料狀態# drbdadm dstate r0 UpToDate/UpToDate----6.4.4 注意事項1.主備伺服器同步的兩個分區大小最好相同(網上沒有關於分區大小是否一定要相同的確切說法)2.開始同步兩個節點的磁碟,需要一定時間,在同步完成前,不要重啟,否則會重新同步。3.掛載之前一定要先切換當前節點為主節點4.兩個節點中,同一時刻只能有一台處於primary狀態,另一台處於secondary狀態。5.處於從節點(secondary)狀態的伺服器不能載入drbd塊裝置6.將主節點切換為從節點之前要先卸載7.一台主機切換為主節點之前,要確保另一台主機已切換為從節點。----------------------------7.測試DRBD資料鏡像--------------------------------7.1格式化掛載磁碟#mkfs.ext4 /dev/drbd0# mkdir /drbd_data# mount /dev/drbd0 /drbd_data/# cd /drbd_data/---7.2 產生測試資料#touch /drbd_data/test.txt#dd if=/dev/zero of=/drbd_data/test.tmp bs=1M count=20# drbdadm dstate r0 UpToDate/UpToDate---7.3 將主節點drbd的狀態變為從# drbdadm role r0 Primary/Secondary#umount /drbd_data#drbdadm secondary all# drbdadm role r0 Secondary/Secondary---7.4 在從節點上進行掛載#drbdadm role r0 Secondary/Secondary#drbdadm primary all#drbdadm role r0 Primary/Secondary#mkdir /drbd_data#mount /dev/drbd0 /drbd_data/# ls -ls /drbd_data/total 20493 12 drwx------ 2 root root 12288 Jun 24 17:02 lost+found20481 -rw-r--r-- 1 root root 20971520 Jun 24 17:20 test.tmp測試成功.
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。