---------------------------------------------
創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)與策劃設(shè)計(jì),桂東網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:桂東等地區(qū)。桂東做網(wǎng)站價(jià)格咨詢:18982081108server2 IP:172.25.38.2
server5 IP:172.25.38.5
---------------------------------------------
1)安裝mysql [server2]、[server5]
yum install -y mysql-server
rpm -qa|grep mysql##安裝好,可見已安裝的包
mysql-libs-5.1.71-1.el6.x86_64
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
[server2] ##編輯mysql配置文件
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
server-id=2
binlog-do-db=dbtest
binlog-ignore-db=mysql
log-bin=mysql-bin
master-host=172.25.38.5
master-user=ly
master-password=westos
master-port=3306
replicate-ignore-db=mysql
replicate-do-db=dbtest
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
當(dāng)配置server2為主時(shí),server5為從時(shí),把以#開頭的,把#去掉
[server5]
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
server-id=5
log-bin=mysql-bin
binlog-do-db=dbtest
binlog-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.log
pid-file=/var/run/mysqld/mysqld.pid
log-error=/var/log/mysqld.log
/etc/init.d/mysqld start##開啟數(shù)據(jù)庫(kù)
mysqladmin -u root password westos##設(shè)置密碼
[root@server5 ~]# mysql -p##進(jìn)入數(shù)據(jù)庫(kù)設(shè)置
Enter password:
mysql> create user ly@'172.25.38.5' identified by 'westos';##創(chuàng)建用戶并設(shè)置密碼
mysql> grant all on *.* to ly@'172.25.38.5';##授予權(quán)限
mysql> flush privleges;##刷新
mysql> show master status;##主節(jié)點(diǎn)狀態(tài)
+------------------+----------+--------------+------------------+
| File |Position |Binlog_Do_DB | Binlog_Ignore_DB|
+------------------+----------+--------------+------------------+
| mysql-bin.000004| 254 | dbtest | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
[root@server2 ~]# mysql -p
Enter password:
mysql> change master to master_host='172.25.38.2',master_user='ly',master_password='westos';
mysql> start slave;##開啟從節(jié)點(diǎn)
mysql> show slave status\G;##查看從的狀態(tài)
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
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 -p
Enter password:
mysql> create user ly@'172.25.38.2' identified by 'westos';
mysql> grant all on *.* to ly@'172.25.38.2';
mysql> flush privileges;
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position| Binlog_Do_DB| Binlog_Ignore_DB|
+------------------+----------+--------------+------------------+
| mysql-bin.000012| 106 | dbtest | mysql |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
[root@server5 ~]# mysql -p
Enter password:
mysql> change master to master_host='172.25.38.2',master_user='ly',master_password='westos';
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
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.rpm
heartbeat-devel-3.0.4-2.el6.x86_64.rpm
heartbeat-libs-3.0.4-2.el6.x86_64.rpm
ldirectord-3.9.5-3.1.x86_64.rpm
yum install openssl perl-Net-SSLeay perl-TimeDate perl-libwww-perl perl-Compress-Zlib perl-HTML-Parser perl-HTML-Tagset ipvsadm -y##解決依賴性
rpm -ivh heartbeat-libs-3.0.4-2.el6.x86_64.rpm ldirectord-3.9.5-3.1.x86_64.rpm heartbeat-3.0.4-2.el6.x86_64.rpm heartbeat-devel-3.0.4-2.el6.x86_64.rpm
vim /etc/ha.d/ha.cf##編輯配置
34 logfacility local0
48 keepalive 2
56 deadtime 30
61 warntime 10
71 initdead 60
76 udpport 694##端口
91 bcast eth0 # Linux
157 auto_failback on
211 node server5.example.com
212 node server2.example.com
222 ping 172.25.38.250##一個(gè)同一網(wǎng)段可ping的IP,最好是網(wǎng)關(guān)
255 respawn hacluster /usr/lib64/heartbeat/ipfail
261 apiauth ipfail gid=haclient uid=hacluster
vim /etc/ha.d/haresources##資源配置
server5.example.com IPaddr::172.25.38.100/24/eth0 drbddisk::example Filesystem::/dev/drbd1::/var/lib/mysql::ext4 mysqld
vim /etc/ha.d/authkeys
auth 1
1 crc
#2 sha1 HI!
#3 md5 Hello!
兩臺(tái)配置一樣,直接scp過去就好。
---------------------------------------------
3)配置drbd
在兩臺(tái)主機(jī)上添加硬盤,最好一樣大小,方便操作
////////////////////
得到如下包
drbd-8.4.2.tar.gz
或者8個(gè)如下安裝包
drbd-8.4.2-2.el6.x86_64.rpm
drbd-xen-8.4.2-2.el6.x86_64.rpm
drbd-udev-8.4.2-2.el6.x86_64.rpm
drbd-utils-8.4.2-2.el6.x86_64.rpm
drbd-pacemaker-8.4.2-2.el6.x86_64.rpm
drbd-heartbeat-8.4.2-2.el6.x86_64.rpm
drbd-bash-completion-8.4.2-2.el6.x86_64.rpm
drbd-km-2.6.32_431.el6.x86_64-8.4.2-2.el6.x86_64.rpm
以tar包方式進(jìn)行安裝如下:
rpm -ivh drbd-*
yum install gcc flex rpm-build kernel-devel -y
cp /root/drbd-8.4.0.tar.gz /root/rpmbuild/SOURCES/
tar zxf drbd-8.4.0.tar.gz
cd drbd-8.4.0
./configure --enable-spec
./configure --enable-spec --with-km
在當(dāng)前目錄下得到兩個(gè)文件
drbd.spec drbd-km.spec
rpmbuild -bb drbd.spec
rpmbuild -bb drbd-km.spec
cd /root/rpmbuild/RPMS/x86_64
rpm -ivh *
scp /root/rpmbuild/RPMS/x86_64/* 172.25.38.5:/root
并且執(zhí)行 rpm -ivh drbd-*
vim /etc/drbd.d/example.res
1 resource example {
2 meta-disk internal;
3 device /dev/drbd1;
4 syncer {
5 verify-alg sha1;
6 }
7 on server5.example.com {
8 disk /dev/vdb;
9 address 172.25.38.5:7789;
10 }
11 on server2.example.com {
12 disk /dev/vdb;
13 address 172.25.38.2:7789;
14 }
15 }
drbdadm create-md example
/etc/init.d/drbd start
drbdadm primary example
cat /proc/drbd#在兩臺(tái)主機(jī)上查看同步狀態(tài)
mkfs.ext4 /dev/drbd1#數(shù)據(jù)同步結(jié)束后創(chuàng)建文件系統(tǒng)
mount /dev/drbd1 /var/www/html#掛載文件系統(tǒng)
---------------------------------------------
4)安裝jdk
得到
jdk-6u32-linux-x64.bin
sh jdk-6u32-linux-x64.bin
mv jdk-6u32-linux-x64 java
mv java /usr/local
vim /etc/profile
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/bin:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
cd /home/
測(cè)試:
vim test.java
class test {
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
java test
---------------------------------------------
5) 安裝cobar
cobar-server-1.2.6.zip
unzip cobar-server-1.2.6.zip
cd /root/cobar-server-1.2.6/conf
vim schema.xml
<!-- schema定義 -->
<schema name="dbtest" >
<table name="usertb" dataNode="server5,server2" />
</schema>
<dataSource name="dbtest" type="mysql">
<property name="location">
<location>172.25.38.5:3306/dbtest</location>
<location>172.25.38.5:3306/dbtest</location>
</property>
<property name="user">root</property>
<property name="password">westos</property>
<property name="sqlMode">STRICT_TRANS_TABLES</property>
</dataSource>
vim server.xml
<user name="root">
<property name="password">westos</property>
<property name="schemas">dbtest</property>
</user>
<!--
<user name="root">
<property name="password"></property>
</user>
<cluster>
<node name="cobar1">
<property name="host">172.25.38.5</property>
<property name="weight">1</property>
</node>
</cluster>
<cluster>
<node name="cobar2">
<property name="host">172.25.38.2</property>
<property name="weight">2</property>
</node>
</cluster>
vim rule.xml
<!DOCTYPE cobar:rule SYSTEM "rule.dtd">
<cobar:rule xmlns:cobar="http://cobar.alibaba.com/">
<!-- 路由規(guī)則定義,定義什么表,什么字段,采用什么路由算法 -->
<tableRule name="rule1">
<rule>
<columns>id</columns>
<algorithm><![CDATA[ func1(${id}) ]]></algorithm>
</rule>
</tableRule>
<!-- 路由函數(shù)定義 -->
<function name="func1" class="com.alibaba.cobar.route.function.PartitionByLong">
<property name="partitionCount">2</property>
<property name="partitionLength">512</property>
</function>
cd /root/cobar-server-1.2.6/bin
[root@server2 bin]# ./startup.sh
"/usr/local/java/bin/java" -Dcobar.home="/root/cobar-server-1.2.6" -classpath "/root/cobar-server-1.2.6/conf:/root/cobar-server-1.2.6/lib/classes:/root/cobar-server-1.2.6/lib/cobar-common-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-config-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-net-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-parser-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-route-1.2.6.jar:/root/cobar-server-1.2.6/lib/cobar-server-1.2.6.jar:/root/cobar-server-1.2.6/lib/log4j-1.2.16.jar:/root/cobar-server-1.2.6/lib/slf4j-api-1.6.4.jar:/root/cobar-server-1.2.6/lib/slf4j-log4j12-1.6.4.jar" -server -Xms1024m -Xmx1024m -Xmn256m -Xss128k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+UseFastAccessorMethods -XX:+DisableExplicitGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=75 com.alibaba.cobar.CobarStartup >> "/root/cobar-server-1.2.6/logs/console.log" 2>&1 &
[root@server2 bin]# /etc/init.d/drbd start
Starting DRBD resources: [
]
.
[root@server2 bin]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:f6:11:cd brd ff:ff:ff:ff:ff:ff
inet 172.25.38.2/24 brd 172.25.38.255 scope global eth0
inet 172.25.38.100/24 brd 172.25.38.255 scope global secondary eth0
inet6 fe80::5054:ff:fef6:11cd/64 scope link
valid_lft forever preferred_lft forever
[root@server2 bin]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 15006084 1723528 12520292 13% /
tmpfs 203008 0 203008 0% /dev/shm
/dev/vda1 495844 33452 436792 8% /boot
/dev/drbd1 4128284 95208 3823372 3% /var/lib/mysql
[root@server2 bin]#./shutdown.sh
[root@server5 conf]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root 17069948 1602508 14600320 10% /
tmpfs 251136 0 251136 0% /dev/shm
/dev/vda1 495844 33467 436777 8% /boot
/dev/drbd1 4128284 95232 3823348 3% /var/lib/mysql
[root@server5 conf]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:6e:00:88 brd ff:ff:ff:ff:ff:ff
inet 172.25.38.5/24 brd 172.25.38.255 scope global eth0
inet 172.25.38.100/24 brd 172.25.38.255 scope global secondary eth0
inet6 fe80::5054:ff:fe6e:88/64 scope link
valid_lft forever preferred_lft forever
-------------------------------------
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前標(biāo)題:cobarmysql高可用-創(chuàng)新互聯(lián)
文章鏈接:http://jinyejixie.com/article10/jjogo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、企業(yè)網(wǎng)站制作、電子商務(wù)、網(wǎng)站制作、小程序開發(fā)、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容