This guide requires MySQL version 4.0.x, rsync installed and finally Apache (doh...).
Start by setting up cacti on the master server (in case you haven't done so yet). After setting up cacti its time to create the slave server for data replication.
While still logged on the Master Server perform the following steps to setup MySQL replication
1) This creates the directories and sets the permissions so only the mysql daemon can read/write to the logs.
Code: Select all
$ mkdir /var/log/mysql/binary
$ chown mysql: /var/log/mysql/binary
$ chmod 770 /var/log/mysql/binary
This turns on the binary logging, tells it where to store the logs, and creates a server id.
Code: Select all
$ vim /etc/mysql/my.cnf
It doesn't matter what the value for server-id is, as long as it is different from the slave's (which you will set later).
Also make sure that "bind ip_address" and "skip-networking" are commented out, so that the slave user can log in remotely.
Code: Select all
log-bin=/var/log/mysql/binary/mysql_binary_log
binlog-do-db=database_name
server-id=1
Code: Select all
/etc/init.d/mysql restart
5) Grant Replication of the Database to the Slave database (this is done still in on the Master server).
Code: Select all
# mysql -u db_admin -p
mysql> GRANT REPLICATION SLAVE ON database_name TO 'slave_user_name'@'hostname_or_ipaddress' IDENTIFIED BY 'slave_password';
Before getting the database dump you need to lock the tables to prevent any updates.
Code: Select all
mysql> USE database_name;
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS;
Code: Select all
+----------------------+----------+--------------+------------------+
| File | Position | Binlog_do_db | Binlog_ignore_db |
+----------------------+----------+--------------+------------------+
| mysql_binary_log.025 | 796947 | database_name| |
+----------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
$ mysqldump --opt database_name > database_name.sql
7) Unlock the tables
From the original shell where you locked the tables:
Code: Select all
mysql> UNLOCK TABLES;
Now on to the Slave server for the rest of the replication setup:
1) Import the mysqldump from the master server:
Code: Select all
mysql database_name < database_name.sql
Code: Select all
$ vim /etc/mysql/my.cnf
Add under the [mysqld] section.
It doesn't matter what the value for server-id is, as long as it is different from the master's.
Code: Select all
server-id=2
# master server settings
master-host=masterhost.com
master-user=slave_user_name
master-password=slave_password
master-connect-retry=60 # num of seconds, default is 60
replicate-do-db=database_name
replicate-ignore-table=cacti.poller_reindex
replicate-ignore-table=cacti.poller_output
replicate-ignore-table=cacti.poller_time
The last 3 lines (replicate-ignore-table) should be added so that the slave DB works properlly with its own poller (Master will try to send poller data to Slave and if you are running a poller on the Slave it will try to update).
3) Restart the MySQL server (This does not start the slaving yet)
Code: Select all
/etc/init.d/mysql restart
This is where you use the data from SHOW MASTER STATUS; from the master mysql database.
Code: Select all
mysql> CHANGE MASTER TO MASTER_HOST='master_host_name', MASTER_USER='slave_user_name', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql_binary_log.025', MASTER_LOG_POS=796947;
5) Start the Slave Process
Code: Select all
mysql> START SLAVE;
On the Master Server
Code: Select all
mysql> SHOW PROCESSLIST;
It should be reading:
Has sent all binlog to slave; waiting for binlog to be updated
This means that our Master Server has sent all the updates to the slave server and that its waiting for the data to update (inside the DB) to replicate the updates again.
On the slave server
Code: Select all
mysql> SHOW PROCESSLIST;
Again you should be looking after the State field. It should have an entry:
Waiting for master to send event
If it says Connecting then there is something wrong with the configuration you created or the username password you are using.
NOW ON WITH FILE REPLICATION.
This part is not mandatory, allthough cacti's database are in sync the poller will not have any problems fetching the polled items from the Database and then proceed with polling the hosts.
A initial replication should ok so that the files do get synced on each host.
To proceed with this replication i used the "cheap" way of rsync. I setup an rsync daemon on the Master Server and then proceeded with a rsync process from the Slave server to get the files synced.
This step as i mentioned above is only needed 1 time, since all data used by the poller is inside the MySQL server, if you are using any custom scripts just make sure the scripts are also available on the slave server and they are inside the cronjob (Unless you are using the slave sever only for backup purposes and you don't mind if data are up to date).