本文共 3886 字,大约阅读时间需要 12 分钟。
操作系统:Linux 2.6.13 (Slackware),其它版的Linux应该也差不多.
数据库:Mysql 4.1.8 源程序安装 假设服务器名:test-db1 (IP为192.168.0.1),主 假设服务器名:test-db2 (IP为192.168.0.2),主 假设服务器名:test-db3 (IP为192.168.0.3),从 二,test-db1主服务器mysql安装准备 用mysql源程序安装,假设在安装时用的configura选择项下如,解压后: ./configure make make imstall chown mysql.mysql /usr/local/mysql/var cp ../support-files/ my-medium.cnf /etc/my.cnf cp ../support-files/mysql.server /etc/rc.d/rc.mysqld 直接启动mysql进程/etc/rc.d/rc.mysqld start 这样默认安装好之后数据库生成的目录为/usr/local/mysql/var 三,test-db2主服务器mysql安装准备 ./configure make make imstall chown mysql.mysql /usr/local/mysql/var cp ../support-files/ my-medium.cnf /etc/my.cnf cp ../support-files/mysql.server /etc/rc.d/rc.mysqld 启动mysql进程/etc/rc.d/rc.mysqld start 这样默认安装好之后数据库生成的目录为/usr/local/mysql/var 修改/etc/my.cnf文档 将port=3306改为port=3307 启动mysql进程/etc/rc.d/rc.mysqld start 至些两台主mysql服务器已经搭建好。 接下来在两台主服务器上设置replicate账号,此账号作为从服务器同步用 mysql中的使用mysqld_multi程序管理多个MySQL 服务 )。
从上述文字可看到多Mysql服务中最重要的就是my.cnf配置文件了. 现我贴出我从服务器的my.cnf文件.----------------------- [mysqld_multi] mysqld = /usr/local/mysql/bin/mysqld_safe mysqladmin = /usr/local/mysql/bin/mysqladmin user = mysql password = mysql [mysqld1] port = 3306 socket = /tmp/mysql.sock1 skip-locking pid-file=/usr/local/mysql/data1/test-db1a.pid datadir = /usr/local/mysql/data1 log=/usr/local/mysql/data1/test-db1.log user = mysql log-slow-queries=/usr/local/mysql/data/slowquery.log long_query_time = 2 key_buffer = 256M max_allowed_packet = 1M table_cache = 512 sort_buffer_size = 2M read_buffer_size = 2M myisam_sort_buffer_size = 64M thread_cache = 32 query_cache_size = 32M thread_concurrency = 2 max_connections=500 server-id = 2 master-host = 192.168.0.1 master-user = 'replcate' master-password = '1234567890' master-port = 3306 report-host = test-db3 master-connect-retry = 30 log-bin log-slave-updates [mysqld2] port = 3307 socket = /tmp/mysql.sock2 pid-file = /usr/local/mysql/data2/test-db2b.pid datadir = /usr/local/mysql/data2 log=/usr/local/mysql/data2/test-db2.log user = mysql log-slow-queries=/usr/local/mysql/data2/slowquery.log long_query_time = 10 key_buffer = 128M max_allowed_packet = 1M table_cache = 512 sort_buffer_size = 1M read_buffer_size = 1M myisam_sort_buffer_size = 32M thread_cache = 32 query_cache_size = 16M thread_concurrency = 2 max_connections=300 server-id = 2 master-host = 192.168.0.2 master-user = 'repl' master-password = '1234567890' master-port = 3307 report-host = test-db3 master-connect-retry = 30 log-bin log-slave-updates 之后通过tar命令将主服务器上test-db1的数据库放于从服务器/usr/local/mysql/data1下 再通过tar命令将主服务器上test-db2的数据库放于从服务器/usr/local/mysql/data2下 通过以下命令启动从服务器的mysql进程 /usr/local/mysq/bin/mysqld_multi --config-file=/etc/my.cnf start 1-2 查看启动: test-db3:/ # ps aux root 10467 0.0 0.2 2712 1300 pts/0 S 18:59 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --port=3306 --socket=/tmp/mysql.sock1 root 10475 0.0 0.2 2712 1300 pts/0 S 18:59 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --port=3307 --socket=/tmp/mysql.sock2 然后在两台从服务器分另建立数据库以及表做测试,会看到在从服务器中分别会有相应的数据库以及表产生。大家可以通过phpMyadmin以及EMS Mysql Manager对mysql进行管理本文出自 “” 博客,请务必保留此出处