How to create mysql slave servers

Jephe Wu -

Environment:  CentOS 6, Mysql 5.1 64bit
Objective: create one or more mysql slaves from master server.


1.  setup master server

Some important configuration in /etc/my.cnf as follows:

log_bin             = /srv/mysql/log/mysql-bin.log 
log_bin_index       = /srv/mysql/log/mysql-bin.log.index 
relay_log           = /srv/mysql/log/mysql-relay-bin 
relay_log_index     = /srv/mysql/log/mysql-relay-bin.index 

log_slave_updates   = 1

expire_logs_days    = 2 
max_binlog_size     = 100M 

2. setup slaves

Method 1:  mysqldump
Refer to for how to setup master-slave replication.

  • since master db is running and it's necessary to flash all tables and lock database to prevent any changes before checking the binlog position.
mysql -uroot -ppassword
mysql> flush tables with read lock;
mysql>show master status\G
Note: DON'T CLOSE this mysql-shell. If you close it, the database lock will be removed. Open a second console and type:

  • export data

 $ mysqldump -uroot -ppassword --host=master_host -all-databases [
--master-data=1]  > dumpfile.sql

The  --master-data=1  will record the 'change master to ' statement and write the master database information and position into dump file, so you don't have to use 'change master to' again after import.
  • unlock tables from first point
  • mysql> UNLOCK TABLES;
  • restore dumped file to slave 
$ mysql -uroot -ppassword --host=slave_host < dumpfile.sql

Method 2:  mylvmbackup

According to ,mylvmbackup website, 
To perform a backup, mylvmbackup obtains a read lock on all tables and flushes all server caches to disk, creates a snapshot of the volume containing the MySQL data directory, and unlocks the tables again. The snapshot process takes only a small amount of time. When it is done, the server can continue normal operations, while the actual file backup proceeds.

This way, you can use LVM snapshot to do backup, master server can assume operation as quickly as possible.  we can just transfer those snapshoted data and log files to slave site, modify server-id configuration in /etc/my.cnf for slave then start mysqld.

Method 3: shutdown master, copy data
Then change /etc/my.cnf to use different server-id, then start up slave db.
then use 'change master to =' to specify the next master bin log without position, the default position is 4 , mysql knows.

Everytime, you stop then start mysql primary server, it will start from a new binary log file and slave should start to replicate from this new binary log and default position 4.

Method 4: create slave from another slave
If you have the current slave running, you might want to create another slave, you can make clone from the current slave database.

Method 4-1:  flush tables and read lock 
  •    firstly, stop slave first, mysql -uroot -ppassword, 
mysql> stop slave;
mysql> flush tables with read lock;
mysql> show slave status;

keep this one, do not close it.
  • backup data by using mysqldump
  • imported the dumped data into the second slave.
  • flush privileges for the second slave after import.
  • exit the flush table with read lock session

Method 4-2: mylvmbackup, make LVM snapshot for mysql partition.
Just leave server-id different in my.cnf, everything else should be same.

Method 4-3: stop slave process, shutdown mysqld on first slave, use mylvmbackup to make snapshot then bring server up again(optional), copy snapshot data/log to the second slave;

Method 4-4: stop slave db completely, copy data folder only to the third slave , changed /etc/my.cnf server-id, then startup third slave , that's it

3. master-master 
After you have done first slave and master, you might want to make master as slave for the current slave. You can do so.

run 'show master status\G' on current slave to record down position, then use 'change master to ' on master server to make sync with 

How to login from drac ssh console into serial port in Oracle Linux 6

Jephe Wu -

Environment: DRAC PowerEdge R610, Oracle Linux 6.3 64bit
Objective: serial login from drac ssh cli to Oracle Linux 6.3 and use Oracle VM server xm console command to access VM guest


1. create file /etc/init/ttyS1.conf based on the comment in /etc/init/serial.conf 

[root@util01 init]# more ttyS1.conf
# /etc/init/ttyS0.conf with content:
# # ttyS0 - agetty
# #
# # This service maintains a agetty on ttyS0.
stop on runlevel [S016]
start on runlevel [23]
exec agetty -h -L -w /dev/ttyS1 115200 vt102

2. start it 
initctl start ttyS1

3. enable console root login

append ttyS1 at the end of /etc/securetty

4. ssh into DRAC IP address
admin>  console com2

go back: ctrl + \

optional kernel parameter and bios boot redirection to com2

5. add the following into /etc/grub.conf current kernel parameter

timeout=5  # wait for 10s on serial console to let you to press any key, otherwise, it won't display
#splashimage=(hd0,0)/grub/splash.xpm.gz # if you are going to use serial console, comment it out to see text on serial console 
serial --unit=1 --speed=115200
#terminal --timeout=5 serial console  # if you don't have serial device connected, or you stand in the front of the server with VGA monitor connected, you should not uncomment this line, otherwise, you won't see on VGA monitor untiil it finish boot up.

console=ttyS1,115200 console=tty0   [rd_NO_PLYMOUTH] 

As the system boots, it starts udev to handle hardware devices.  The /lib/udev/rules.d/10-console.rules file tells udev to check a number of devices, including /dev/console, and run the /lib/udev/console_check helper program against each device:

 If console_check determines that /dev/console is a serial console

If console_check determines that /dev/console is a serial console (by running some ioctl() system calls on it), then it runs this command:

/sbin/initctl emit --no-wait fedora.serial-console-available DEV=ttyS0 SPEED=115200
This command sends a fedora.serial-console-available event to the init daemon.  The init daemon is configured for this event by /etc/init/serial.conf:

Note: the last console definition is the primary console.

Q: when kernel boots up, once control is transferred to init, the messages from init
only appear on the VGA console, not on the serial console.

A: The kernel prints diagnostic output to all console devices you have
configured on the kernel command line, but /dev/console, which is what
userland (such as init) uses, can only be connected to *one* device (the
last one specified).

Refer to:

6. use http://serverip:1311 after installing Dell Openmanager to change bios settings
login as root

go to system-bios-setup tab, change it as follows:

Serial Communications

Instructions: Click each BIOS setup object to set its state.

Serial Communications On with Console Redirection via COM2
Console Redirection After Boot Enabled
External Serial Connector Serial Device2
Console Redirection Failsafe BAUD Rate 115200
Serial Address Select Serial Device1=COM1, Serial Device2=COM2

or modify bios settings through Linux OS itself (Dell OpenManage must be installed first)

# racadm config -g cfgSerial -o cfgSerialBaudRate 115200
# racadm config -g cfgSerial -o cfgSerialCom2RedirEnable 1
# racadm config -g cfgSerial -o cfgSerialSshEnable 1

optional for ipmi
# racadm config -g cfgIpmiSol -o cfgIpmiSolEnable 1
# racadm config -g cfgIpmiSol -o cfgIpmiSolBaudRate 115200

7. Useful dell iDRAC 6 commands:

a.  restart server through ssh into drac and issue command racadm 

/admin1-> racadm help serveraction
serveraction -- perform system power management operations


racadm serveraction <action>

action    server power management operation to peform

Valid actions:

powerdown       - power server off
powerup         - power server on
powercycle      - perform server power cycle
hardreset       - force hard server power reset
powerstatus     - display current power status of server

/admin1-> racadm serveraction powerstatus
Server power status: ON

/admin1 -> racadm serveraction hardreset

b.  check configuration:

[root@util01 boot]# racadm getconfig -g cfgServerPowerSupply -i 1
# cfgServerPowerSupplyIndex=1
# cfgServerPowerSupplyMaxInputPower=945 W
# cfgServerPowerSupplyMaxOutputPower=717 W
# cfgServerPowerSupplyOnlineStatus=Present
# cfgServerPowerSupplyFwVer=04.18.00
# cfgServerPowerSupplyCurrentDraw=5.00 Amps
# cfgServerPowerSupplyType=AC

[root@util01 boot]# racadm getconfig -g cfgSerial

c. system event log

# racadm racresetcfg   # reset to factory default
[root@util01 boot]# racadm getsel
Record: 1
Date/Time: 08/20/2012 23:44:22
Source: system
Severity: Ok
Description: Log cleared.
Record: 2
Date/Time: 08/22/2012 13:33:40
Source: system
Severity: Critical
Description: The power input for power supply 1 is lost.
d. configure drac user and ip address

$ racadm getconfig -g cfgUserAdmin -i 2  # display root user info for drac
$ racadm config -g cfgUserAdmin -o cfgUserAdminUserName -i 2 jwu   # create user id 2 or change username to jwu
$ racadm config -g cfgUserAdmin -o cfgUserAdminPassword -i 2 newpassword  # set user id 2 new password
$ racadm config -g cfgUserAdmin -o cfgUserAdminUserName -i 2 ""    # remove user id 2
$ racadm setniccfg -s   # configure drac new ip address
Static IP configuration enabled and modified successfully

[root@util01 boot]# racadm racreset    # restart drac os
RAC reset operation initiated successfully. It may take up to a minute
for the RAC to come back online again.

[root@util01 boot]# racadm getsysinfo | grep 'Current'   # get drac ip address info
Current DNS Domain      =
Current IP Address      =
Current IP Gateway      =
Current IP Netmask      =

$ ipmitool sdr  # check hardware info realtime
$ ipmitool sel    # sel means System Event Log
$ ipmitool sel  list

8. How to access VM guest console from Oracle VM server 3.1.1 hypervisor
# /etc/grub.conf 

serial --unit=0 --speed=115200
terminal --timeout=5 serial console

Add console=hvc0 to kernel boot parameter

Add hvc0 into /etc/securetty

then reboot server

use xm console id to access console, use ctrl + ] to exit

How to access:
xm list
xm console 2

Reference: Oracle VM: How to Configure 'xm console' Access for Guests [ID 579413.1]

9. references: