原作者:marry,联系:
示例主机: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:800M
innodb_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 完整安装完成 ###########################
按照上面的步骤两台服务器同时安装,并保证可以启动mysql
1. 理想情况,应在主服务器和从服务器上使用最近版本的MySQL。
2. 在主服务器上为服务器设置一个连接账户。
mysql> GRANT REPLICATION SLAVE ON *.* TO IDENTIFIED BY ;
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 = #主机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将创建数据库的操作也同步了,够强吧。
然后,再把数据导入即可:
# /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 |
下载: |
下载 | |
示例配置文件
阅读(3361) | 评论(2) | 转发(0) |