———————————————server2IP:172.25.38.2server5IP:172.25.38.5———————————————1)安装mysql[server2]、[server5]yuminstall-ymysql-serverrpm-qa|grepmysql##安装好,可见已安装的包mysql-libs-5.1.71-1.el6.x86_64mysql-5.1.71-1.el6.x86_64mysql-server-5.1.71-1.el6.x86_64[server2] ##编辑mysql配置文件vim /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql#Disablingsymbolic-linksisrecommendedtopreventassortedsecurityriskssymbolic-links=0server-id=2binlog-do-db=dbtestbinlog-ignore-db=mysqllog-bin=mysql-binmaster-host=172.25.38.5master-user=lymaster-password=westosmaster-port=3306replicate-ignore-db=mysqlreplicate-do-db=dbtest[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid当配置server2为主时,server5为从时,把以#开头的,把#去掉
[server5]vim /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysqlsymbolic-links=0server-id=5log-bin=mysql-binbinlog-do-db=dbtestbinlog-ignore-db=mysql#master-host=172.25.38.2#master-user=ly#master-password=westos#master-port=3306#replicate-ignore-db=mysql#replicate-do-db=dbtest[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pidlog-error=/var/log/mysqld.log
/etc/init.d/mysqld start##开启数据库mysqladmin-urootpasswordwestos##设置密码[root@server5~]#mysql-p##进入数据库设置Enterpassword:mysql>createuserly@’172.25.38.5’identifiedby’westos’;##创建用户并设置密码mysql>grantallon*.*toly@’172.25.38.5′;##授予权限mysql>flushprivleges;##刷新mysql>showmasterstatus;##主节点状态+——————+———-+————–+——————+|File |Position|Binlog_Do_DB|Binlog_Ignore_DB|+——————+———-+————–+——————+|mysql-bin.000004| 254 |dbtest | mysql |+——————+———-+————–+——————+1rowinset(0.00sec)[root@server2 ~]# mysql -pEnterpassword:mysql>changemastertomaster_host=’172.25.38.2′,master_user=’ly’,master_password=’westos’;mysql>startslave;##开启从节点mysql>showslavestatusG;##查看从的状态***************************1.row*************************** Slave_IO_State:Waitingformastertosendevent Master_Host:172.25.38.5 Master_User:ly Master_Port:3306 Connect_Retry:60 Master_Log_File:mysql-bin.000004 Read_Master_Log_Pos:254 Relay_Log_File:mysqld-relay-bin.000005 Relay_Log_Pos:399 Relay_Master_Log_File:mysql-bin.000004 Slave_IO_Running:Yes Slave_SQL_Running:Yes Replicate_Do_DB:dbtest Replicate_Ignore_DB:mysql##做同样类似操作,最后做出双向主从同步[root@server2 ~]# mysql -pEnterpassword:mysql>createuserly@’172.25.38.2’identifiedby’westos’;mysql>grantallon*.*toly@’172.25.38.2′;mysql>flushprivileges;mysql>showmasterstatus;+——————+———-+————–+——————+|File |Position|Binlog_Do_DB|Binlog_Ignore_DB|+——————+———-+————–+——————+|mysql-bin.000012| 106 |dbtest |mysql |+——————+———-+————–+——————+1rowinset(0.00sec)[root@server5 ~]# mysql -pEnterpassword:mysql>changemastertomaster_host=’172.25.38.2′,master_user=’ly’,master_password=’westos’;mysql>start slave;mysql>showslavestatusG;***************************1.row*************************** Slave_IO_State:Waitingformastertosendevent Master_Host:172.25.38.5 Master_User:ly Master_Port:3306 Connect_Retry:60 Master_Log_File:mysql-bin.0000012 Read_Master_Log_Pos:254 Relay_Log_File:mysqld-relay-bin.0000013 Relay_Log_Pos: 106 Relay_Master_Log_File:mysql-bin.0000012 Slave_IO_Running:Yes Slave_SQL_Running:Yes Replicate_Do_DB:dbtest Replicate_Ignore_DB:mysql———————————————2)安装heartbeat[server2]、[server5]得到如下安装包heartbeat-3.0.4-2.el6.x86_64.rpmheartbeat-devel-3.0.4-2.el6.x86_64.rpmheartbeat-libs-3.0.4-2.el6.x86_64.rpmldirectord-3.9.5-3.1.x86_64.rpmyuminstallopensslperl-Net-SSLeayperl-TimeDateperl-libwww-perlperl-Compress-Zlibperl-HTML-Parserperl-HTML-Tagsetipvsadm-y##解决依赖性rpm-ivhheartbeat-libs-3.0.4-2.el6.x86_64.rpmldirectord-3.9.5-3.1.x86_64.rpmheartbeat-3.0.4-2.el6.x86_64.rpmheartbeat-devel-3.0.4-2.el6.x86_64.rpmvim/etc/ha.d/ha.cf##编辑配置34logfacilitylocal048keepalive256deadtime3061warntime1071initdead6076udpport694##端口91bcasteth0#Linux157auto_failbackon211nodeserver5.example.com212nodeserver2.example.com222ping172.25.38.250##一个同一网段可ping的IP,最好是网关255respawnhacluster/usr/lib64/heartbeat/ipfail261apiauthipfailgid=haclientuid=haclustervim/etc/ha.d/haresources##资源配置server5.example.comIPaddr::172.25.38.100/24/eth0drbddisk::exampleFilesystem::/dev/drbd1::/var/lib/mysql::ext4mysqldvim/etc/ha.d/authkeysauth11crc#2sha1HI!#3md5Hello!两台配置一样,直接scp过去就好。———————————————3)配置drbd在两台主机上添加硬盘,最好一样大小,方便操作////////////////////得到如下包drbd-8.4.2.tar.gz或者8个如下安装包drbd-8.4.2-2.el6.x86_64.rpmdrbd-xen-8.4.2-2.el6.x86_64.rpmdrbd-udev-8.4.2-2.el6.x86_64.rpmdrbd-utils-8.4.2-2.el6.x86_64.rpmdrbd-pacemaker-8.4.2-2.el6.x86_64.rpmdrbd-heartbeat-8.4.2-2.el6.x86_64.rpmdrbd-bash-completion-8.4.2-2.el6.x86_64.rpmdrbd-km-2.6.32_431.el6.x86_64-8.4.2-2.el6.x86_64.rpm以tar包方式进行安装如下:rpm-ivhdrbd-*yuminstallgccflexrpm-buildkernel-devel-ycp/root/drbd-8.4.0.tar.gz/root/rpmbuild/SOURCES/tarzxfdrbd-8.4.0.tar.gzcddrbd-8.4.0./configure–enable-spec./configure–enable-spec–with-km在当前目录下得到两个文件drbd.specdrbd-km.specrpmbuild-bbdrbd.specrpmbuild-bbdrbd-km.speccd/root/rpmbuild/RPMS/x86_64rpm-ivh*scp/root/rpmbuild/RPMS/x86_64/*172.25.38.5:/root并且执行rpm-ivhdrbd-*vim/etc/drbd.d/example.res1resourceexample{2meta-diskinternal;3device/dev/drbd1;4syncer{5verify-algsha1;6}7onserver5.example.com{8disk/dev/vdb;9address172.25.38.5:7789;10}11onserver2.example.com{12disk/dev/vdb;13address172.25.38.2:7789;开发云主机域名14}15}drbdadmcreate-mdexample/etc/init.d/drbdstartdrbdadmprimaryexamplecat/proc/drbd#在两台主机上查看同步状态mkfs.ext4/dev/drbd1#数据同步结束后创建文件系统mount/dev/drbd1/var/www/html#挂载文件系统———————————————4)安装jdk得到jdk-6u32-linux-x64.binshjdk-6u32-linux-x64.binmvjdk-6u32-linux-x64javamvjava/usr/localvim/etc/profileexportJAVA_HOME=/usr/local/javaexportCLASSPATH=.:$JAVA_HOME/bin:$JAVA_HOME/jre/libexportPATH=$PATH:$JAVA_HOME/binsource/etc/profilecd/home/测试:vimtest.javaclasstest{publicstaticvoidmain(String[]args){System.out.println(“Helloworld!”);}}javatest———————————————5)安装cobarcobar-server-1.2.6.zipunzipcobar-server-1.2.6.zipcd/root/cobar-server-1.2.6/confvimschema.xml