原作者:marry,聯絡:macrdy@126.com 樣本主機:192.168.0.1 樣本備機:192.168.0.2 ################################# mysql 完整安裝 ###########################
groupadd mysql
useradd -g mysql mysql
mv /root/mysql-5.0.51b.tar.gz /usr/local/src
tar -zxvf mysql-5.0.51b.tar.gz
cd mysql-5.0.51b
./configure --with-charset=latin1 --with-extra-charsets=all --enable-assembler --with-mysqld-ldflags=-all-static --with-mysqld-user=mysql --prefix=/usr/local/mysql-5.0.51b --localstatedir=/data/mysql5051_db
make
make install
ln -s /usr/local/mysql-5.0.51b /usr/local/mysql
mkdir -p /data/mysql5051_db/dbdata
mkdir -p /data/mysql5051_db/innodb
mkdir -p /data/mysql5051_db/binlog
chown -R mysql:mysql /data/mysql5051_db
chmod -R 775 /data/mysql5051_db
cd /usr/local/src/mysql-5.0.51b
vim ./scripts/mysql_install_db中的ldata=/data/mysql5051_db/dbdata
cp ./support-files/my-small.cnf /etc/my.cnf
/usr/local/mysql-5.0.51b/bin/mysql_install_db --basedir=/usr/local/mysql-5.0.51b --ldata=/data/mysql5051_db/dbdata --user=mysql
vim /etc/my.cnf
bind-address = 192.168.0.8
datadir = /data/mysql5051_db/dbdata/
pid-file = /data/mysql5051_db/my.pid
log-slow-queries=/data/mysql5051_db/dbdata/slowquery.sql
log-bin = /data/mysql5051_db/binlog/sortrepl.log
################innodb####################
# Uncomment the following if you are using InnoDB tables
innodb_data_home_dir = /data/mysql5051_db/innodb/
innodb_data_file_path = ibdata1:1000M;ibdata2:1000M:autoextend:max:800Minnodb_log_group_home_dir = /data/mysql5051_db/innodb/
innodb_log_arch_dir = /data/mysql5051_db/innodb/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 600M
innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_files_in_group = 4
innodb_log_file_size = 400M
innodb_log_buffer_size = 160M
innodb_flush_log_at_trx_commit = 0
innodb_thread_concurrency = 8
#innodb_flush_method = O_DSYNC
innodb_lock_wait_timeout = 50
################innodb#####################啟動服務
# /usr/local/mysql/bin/mysqld_safe -umysql &
# /usr/local/mysql-5.0.51b/bin/mysql
#關閉服務
# /usr/local/mysql/bin/mysqladmin shutdown
################################# mysql 完整安裝完成 ###########################按照上面的步驟兩台伺服器同時安裝,並保證可以啟動mysql1. 理想情況,應在主伺服器和從伺服器上使用最近版本的MySQL。
2. 在主伺服器上為伺服器設定一個串連賬戶。
mysql> GRANT REPLICATION SLAVE ON *.* TO 'test'@'192.168.0.2' IDENTIFIED BY 'db@test';
3. 關閉主從資料庫
linux-A:/data # /usr/local/mysql/bin/mysqladmin shutdown
linux-B:/data # /usr/local/mysql/bin/mysqladmin shutdown
linux-A:/etc # vi my.cnf
在[mysqld] 段內加入
server-id = 1 #設定主機id標識
binlog-do-db = test #設定需要同步的資料庫,如果有多個資料庫,每個資料庫一行
log-bin = /data/mysql5051_db/binlog/master.log #mysql日誌
7. 修改從資料庫的設定檔 my.cnf
linux-B:/etc # vi my.cnf
在[mysqld] 段內加入
server-id = 2 #設定從機id標識,如果有多個從機,可以順序增加ID為3,4...
master-host = 192.168.0.1 #主機地址
master-user = test #主機mysql資料庫使用者
master-password = db@test #主機mysql資料庫密碼
replicate-do-db = test #同步的資料庫,如果有多個資料庫,每個資料庫一行
log-bin = /data/mysql5051_db/binlog/slave.log #本機mysql日誌
relay-log = /data/mysql5051_db/binlog/relay.log #同步處理記錄
log-slave-updates #同步方式
read-only
master-connect-retry=60
8. 開啟主從資料庫
/usr/local/mysql/bin/mysqld_safe -umysql &9. 看同步情況
mysql> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
證明同步已經成功!
10.匯入資料
主:
create database test
這裡備機也會有這個庫了,也就是說MYSQL將建立資料庫的操作也同步了,夠強吧。
然後,再把資料匯入即可:
root@test:/data# /usr/local/mysql/bin/mysql test <./db.dump
上備機,查看資料,也已經OK。 mysql啟動時,如果./configure時不指定--defaults-extra-file=/usr/local/mysql/data/my-small.cnf
預設就是--defaults-extra-file=/etc/my.cnf
|
檔案: |
mysql-HA.zip |
大小: |
2KB |
下載: |
下載 |
|
樣本設定檔