dbrd 8.4.6 源代码编译安装

Posted slgkaifa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dbrd 8.4.6 源代码编译安装相关的知识,希望对你有一定的参考价值。

----------------------------
0.系统环境
----------------------------
db01   192.168.50.10  /dev/sdb1  主节点

db02   192.168.50.20  /dev/sdb1  备节点


# grep -v "#" /etc/hosts
192.168.50.10 db01 db01.mysql.com
192.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/sdb
brw-rw---- 1 root disk 8, 17 Jun 24 13:37 /dev/sdb1


NOTE: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.gz

tar xzf drbd-8.4.6.tar.gz

cd 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 install
make[1]: Entering directory `/soft/drbd-8.4.6/drbd'
install -d //lib/modules/2.6.32-431.el6.x86_64/updates
install -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 || true
make[1]: Leaving directory `/soft/drbd-8.4.6/drbd'


编译成功模块安装位置
#modprobe -l | grep -i drbd
updates/drbd.ko





载入模块
# modprobe drbd

#lsmod | grep drbd

drbd                  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 only

Optional 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启动两个节点drbd

mkdir -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 [email protected], 2015-06-24 13:47:15
m:res  cs         ro                   ds                         p  mounted  fstype
0:r0   Connected  Secondary/Secondary  Inconsistent/Inconsistent  C


cs:表示连接状态
ro: 表示主从关系 上面的表示都为从
ds:硬盘状态信息 上面表示已经实时同步中。Inconsistent:不一致

# cat /proc/drbd 
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by [email protected], 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 [email protected], 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 [email protected], 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: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
10040 inodes, 40088 blocks
2004 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=41156608
5 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks: 
	8193, 24577

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 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.主备server同步的两个分区大小最好同样(网上没有关于分区大小是否一定要同样的确切说法)
2.開始同步两个节点的磁盘,须要一定时间,在同步完毕前,不要重新启动,否则会又一次同步。
3.挂载之前一定要先切换当前节点为主节点
4.两个节点中,同一时刻仅仅能有一台处于primary状态,还有一台处于secondary状态。
5.处于从节点(secondary)状态的server不能载入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+found
20481 -rw-r--r-- 1 root root 20971520 Jun 24 17:20 test.tmp

測试成功.



以上是关于dbrd 8.4.6 源代码编译安装的主要内容,如果未能解决你的问题,请参考以下文章

Android 逆向Android 逆向通用工具开发 ( Android 平台运行的 cmd 程序类型 | Android 平台运行的 cmd 程序编译选项 | 编译 cmd 可执行程序 )(代码片段

Notepad++编辑器——Verilog代码片段直接编译

导致资产预编译在heroku部署上失败的代码片段

如何有条件地将 C 代码片段编译到我的 Perl 模块?

错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段

错误记录Android Studio 编译报错 ( Could not determine java version from ‘11.0.8‘. | Android Studio 降级 )(代码片段