Wednesday 3 May 2017


                          



 Create jenkins server with ubuntu machine on docker


FROM ubuntu:latest
#add storage 
VOLUME /ubuntu1
#Oracle Java8 install
RUN apt-get update
RUN apt-get install software-properties-common -y
RUN apt-get update
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java8-installer
RUN apt-get install sudo
#Jenkins install
RUN wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | apt-key add -
RUN sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
RUN apt-get update
RUN apt-get install -y jenkins

#Zip support install
RUN apt-get update
RUN apt-get -y install zip

#Restart jenkins server
RUN service jenkins start

EXPOSE 8080


Wednesday 26 April 2017







Pending - Waiting for next available executor/Disk space too low on / - Jenkins



Pending - Waiting for next available executor/Disk space too low on / - Jenkins

While we were trying to execute the job, it was displaying "Pending - Waiting for next available executor". When looking into the Jenkins node from the console, the Master node is offline and the error message displayed was "Disk space too low. Only xxxGB on /" but the / folder has space around 1GB.
























The following steps are followed to resolve the issue.
STEP 1
Increase the space available in /tmp folder. If not able to increase the space in /tmp folder then TemporarySpaceMonitor can be disabled or the memory threshold value of the TemporarySpaceMonitor can be reduced in $JENKINS_HOME/nodeMonitors.xml(make sure atleast minimum memory is available)







<?xml version='1.0' encoding='UTF-8'?>
<hudson.util.DescribableList>
<hudson.node__monitors.ArchitectureMonitor>
<ignored>false</ignored>
</hudson.node__monitors.ArchitectureMonitor>
<hudson.node__monitors.ClockMonitor>
<ignored>false</ignored>
</hudson.node__monitors.ClockMonitor>
<hudson.node__monitors.DiskSpaceMonitor>
<ignored>false</ignored>
<freeSpaceThreshold>1GB</freeSpaceThreshold>
</hudson.node__monitors.DiskSpaceMonitor>
<hudson.node__monitors.SwapSpaceMonitor>
<ignored>false</ignored>
</hudson.node__monitors.SwapSpaceMonitor>
<hudson.node__monitors.TemporarySpaceMonitor>
<ignored>false</ignored>//Change to true to disable monitoring
<freeSpaceThreshold>100MB</freeSpaceThreshold>
</hudson.node__monitors.TemporarySpaceMonitor>

<hudson.node__monitors.ResponseTimeMonitor>
<ignored>false</ignored>

</hudson.node__monitors.ResponseTimeMonitor>
</hudson.util.DescribableList>










STEP 2
Increase the number of executor from default value 2


STEP 3
Remove the following content from $JENKINS_HOME/config.xml

<temporaryOfflineCause class="hudson.node_monitors.DiskSpaceMonitorDescriptor$DiskSpace">
<path>/tmp</path>
<size>966733824</size>
<triggered>true</triggered>
<trigger>hudson.node_monitors.TemporarySpaceMonitor</trigger>
</temporaryOfflineCause>


STEP 4
Restart the Jenkins server.



Monday 4 July 2016






MongoDB is a NoSQL document database system that scales well horizontally and implements data storage through a key-value system. A popular choice for web applications and websites, MongoDB is easy to implement and access programmatically.

MongoDB Sharding Topology
Sharding is implemented through three separate components. Each part performs a specific function:

Config Server: Each production sharding implementation must contain exactly three configuration servers. This is to ensure redundancy and high availability.
Config servers are used to store the metadata that links requested data with the shard that contains it. It organizes the data so that information can be retrieved reliably and consistently.

Query Routers: The query routers are the machines that your application actually connects to. These machines are responsible for communicating to the config servers to figure out where the requested data is stored. It then accesses and returns the data from the appropriate shard(s).
Each query router runs the "mongos" command.

Shard Servers: Shards are responsible for the actual data storage operations. In production environments, a single shard is usually composed of a replica set instead of a single machine. This is to ensure that data will still be accessible in the event that a primary shard server goes offline.



Initial Set Up
If you were paying attention above, you probably noticed that this configuration requires quite a few machines. In this tutorial, we will configure an example sharding cluster that contains:

3 Config Servers (Required in production environments)
1 Query Routers (Minimum of 1 necessary)
3 Shard Servers (Minimum of 2 necessary)

192.168.1.1 config1
192.168.1.2 config2
192.168.1.3 config3
192.168.1.4 Query
192.168.1.5 shard1
192.168.1.6 shard2
192.168.1.7 shard3


Login into all server and change hostname as well as mention above hosts in /etc/hosts

Config1, Config2 & Config3:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.2.7 mongodb-org-server=3.2.7 mongodb-org-shell=3.2.7 mongodb-org-mongos=3.2.7 mongodb-org-tools=3.2.7

Below configuration should be smae between all config server

root@config1:/home/ubuntu# vim /etc/mongod.conf
net:
  port: 27017
   bindIp: 0.0.0.0
sharding:
   clusterRole: configsvr
replication:
   replSetName: configReplSet

Go to config1

root@config1:~# mongo
rs.initiate( {
   _id: "configReplSet",
   configsvr: true,
   members: [
      { _id: 0, host: "config1:27017" },
      { _id: 1, host: "config2:27017" },
      { _id: 2, host: "config3:27017" }
   ]
} )

NOTE: If you want to add one more config server in replica run below command on Primery  config server:

rs.add({_id: 1, host: "config4:27017", priority: 0, hidden: true})


Shard1:

service mongod stop
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.2.7 mongodb-org-server=3.2.7 mongodb-org-shell=3.2.7 mongodb-org-mongos=3.2.7 mongodb-org-tools=3.2.7

Do on all shard node
mkdir -p /data/db1
mkdir /data/db2
mkdir /data/db3
mongod --port 27017 --dbpath /data/db1 --smallfiles --fork --logpath /var/log/mongodb/mongod.log --replSet "rs1"
mongod --port 27018 --dbpath /data/db2 --smallfiles --fork --logpath /var/log/mongodb/mongod.log --replSet "rs2"
mongod --port 27019 --dbpath /data/db3 --smallfiles --fork --logpath /var/log/mongodb/mongod.log --replSet "rs3"

Run below commands on every primary server
mongo

config = { _id: "rs1", members:[ { _id : 0, host : "shard1:27017" }, { _id : 1, host : "shard2:27017" },{ _id : 2, host : "shard3:27017" } ]};

rs.initiate(config)

mongo --port 27018
config = { _id: "rs2", members:[ { _id : 0, host : "shard1:27018" }, { _id : 1, host : "shard2:27018" },{ _id : 2, host : "shard3:27018" } ]};

rs.initiate(config)

mongo --port 27019
config = { _id: "rs3", members:[ { _id : 0, host : "shard1:27019" }, { _id : 1, host : "shard2:27019" },{ _id : 2, host : "shard3:27019" } ]};

rs.initiate(config)


Query Server:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.2.7 mongodb-org-server=3.2.7 mongodb-org-shell=3.2.7 mongodb-org-mongos=3.2.7 mongodb-org-tools=3.2.7

root@query:~# service mongod stop
root@query:~# mongos --logpath /var/log/mongo/mongo.log --configdb configReplSet/config1:27017,config2:27017,config3:27017 &
mongos> db.adminCommand( { listShards: 1 } )
{ "shards" : [ ], "ok" : 1 }
mongos> db.adminCommand({addShard : "rs1/shard1:27017,shard2:27017,shard3:27017", name : "rs1"});
{ "shardAdded" : "rs1", "ok" : 1 }
mongos> db.adminCommand({addShard : "rs2/shard1:27018,shard2:27018,shard3:27018", name : "rs2"});
{ "shardAdded" : "rs2", "ok" : 1 }
mongos> db.adminCommand({addShard : "rs3/shard1:27019,shard2:27019,shard3:27019", name : "rs3"});
{ "shardAdded" : "rs3", "ok" : 1 }


mongos> db.runCommand("getShardMap")

mongos> use raj
switched to db raj
mongos> sh.enableSharding("raj")
{ "ok" : 1 }
mongos> sh.shardCollection("raj.collections",{ "_id":"hashed" } ) ====> RUN this command for all collections
{ "collectionsharded" : "raj.collections", "ok" : 1 }

For data insert
for (var i = 1; i <= 100000; i++) {    db.collections.insert( { _id : i } ) } ====. _id should be change in prod choose date



================================================================================================================================================

Basic Commands
mongos> rs.status()
mongos> db.stats()
mongos> use database
mongos> db.stats()
mongos> sh.getBalancerState()
mongos> use admin
mongos> db.runCommand( { listshards : 1 } );
db.runCommand("getShardMap")
To check Cluster status and shrading
mongos> db.printShardingStatus();
mongos> sh.status()




Sunday 22 February 2015



NGINX SSL MYSQL APACHE


LEMP is a combination of the operating system and open-source software stack. The acronym LEMP comes from the first letters of Linux, Nginx(engine-x) HTTP Server, MySQL database, and PHP/Perl/Python.
In this tutorial, let us see how to install Nginx, MySQL on Ubuntu 14.10.


Install Nginx

root@raj:~#
apt-get install nginx
root@raj:~#
service nginx start

Configure Nginx

root@raj:~# vim /etc/nginx/nginx.conf

Set the worker_processes (i.e No. of CPU’s in your system). To see the no. of CPU’s, use the command “lscpu”. In my case it’s “1″. So I set this as ’1′.

worker_processes 1;


root@raj:~# service nginx restart

The default vhost(server block) is defined in the /etc/nginx/sites-available/default file.
Open the file /etc/nginx/sites-available/default in any editor.
root@raj:~# vim /etc/nginx/sites-available/default

upstream
web-virt { 
        server 192.168.122.245:80; 
} 
server { 
          listen 443 ssl; 

        server_name 192.168.1.110:443; 
        ssl_certificate /etc/nginx/ssl/server.crt; 
        ssl_certificate_key /etc/nginx/ssl/server.key; 

        location
/ { 
            proxy_pass http://127.0.0.1:80; 
            proxy_set_header X-Real-IP  $remote_addr; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_set_header X-Forwarded-Proto https; 
            proxy_set_header X-Forwarded-Port 443; 
            proxy_set_header Host $host; 
        }

} 

##Next
server goes here 
Save and exit the file.

Test nginx configuration

Test the nginx configuration for any syntax errors using command:

root@raj:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Install MySQL

root@raj:~# apt-get install mysql-server mysql-client

OR

root@raj:~#  apt-get install software-properties-common
root@raj:~# apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
root@raj:~# add-apt-repository 'deb http://sgp1.mirrors.digitalocean.com/mariadb/repo/5.5/ubuntu trusty main'
root@raj:~# apt-get update
root@raj:~# apt-get install mariadb-server mariadb-client -y
root@raj:~# /etc/init.d/mysqld restart
root@raj:~# mysql  -p
password:
mysql> create database test;
mysql> grant all on insuramatch_r.* to 'insuramatch_r'@'192.168.122.%'
identified by 'insuramatch_r';
mysql> flush privileges;
mysql> \q


How To Create a SSL Certificate on nginx for Ubuntu 12.04

About Self-Signed Certificates

A SSL certificate is a way to encrypt a site's information and create a more secure connection. Additionally, the certificate can show the virtual private erver's identification information to site visitors. Certificate Authorities can issue SSL certificates that verify the server's details while a self-signed certificate has no 3rd party corroboration.
root@raj:~#
mkdir /etc/nginx/ssl
root@raj:~#
cd /etc/nginx/ssl

Create the Server Key and Certificate Signing Request

root@raj:~# openssl genrsa -des3 -out server.key 1024
root@raj:~# openssl req -new -key server.key -out server.csr
You
are about to be asked to enter information that will be incorporated
into your
certificate request.
What you
are about to enter is what is called a Distinguished Name or a DN.
There are
quite a few fields but you can leave some blank
For some
fields there will be a default value,
If you
enter '.', the field will be left blank.
-----
Country
Name (2 letter code) [AU]:In
State or
Province Name (full name) [Some-State]:New Delhi
Locality
Name (eg, city) []:New delhi
Organization
Name (eg, company) [Internet Widgits Pty Ltd]:Example Inc
Organizational
Unit Name (eg, section) []:IT
Common
Name (e.g. server FQDN or YOUR name) []:sharma.com                  
Email
Address []:root@raj.sharma.com
root@raj:~# cp server.key server.key.org
root@raj:~# openssl rsa -in server.key.org -out server.key

Step Four— Sign your SSL Certificate

Your certificate is all but done, and you just have to sign it. Keep in mind that you can specify how long the certificate should remain valid by changing the 365 to the number of days you prefer. As it stands this certificate will expire after one year.
 openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Set Up the Certificate

Now we have all of the required components of the finished certificate.The next thing to do is to set up the virtual hosts to display the new certificate.

 root@raj:~# vim /etc/nginx/sites-available/default




server { listen 443 ssl;

server_name 192.168.122.76;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;

location / {
proxy_pass http://127.0.0.1:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header Host $host;
}
}




root@raj:~# ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

root@raj:~# service nginx restart

root@raj:~# elinks https://192.168.122.245/sunny

Now go to the apache server

root@sunny:/etc/apache2/sites-available# vim raj.conf

<VirtualHost *:80>
ServerAdmin root@sharma.com
ServerName sunny.com
DocumentRoot /var/www/sunny/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/sunny/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/sunny.error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/sunny.access.log combined

</VirtualHost>
save and quit

Now run comand a2ensite

a2ensite is a script that enables the specified site (which contains a <VirtualHost> block) within the apache2 configuration. It does this by creating symlinks within /etc/apache2/sites-enabled. Likewise, a2dissite disables a site by removing those symlinks

root@raj:~# a2ensite sunny.conf

Restart the apache2 service

root@raj:~# /etc/init.d/apache2 restart

Now access the site in browser

https://192.168.122.245/sunny



Friday 6 February 2015



MULTIMASTER REPLICATION MYSQL








Multi-master replication is a method of database replicaton which allows data to be stored by a group of computers, and updated by any member of the group. All members are responsive to client data queries. The multi-master replication system is responsible for propagating the data modifications made by each member to the rest of the group, and resolving any conflicts that might arise between concurrent changes made by different members.
Multi-master replication can be contrasted with master-slave replication, in which a single member of the group is designated as the "master" for a given piece of data and is the only node allowed to modify that data item. Other members wishing to modify the data item must first contact the master node. Allowing only a single master makes it easier to achieve consistency among the members of the group, but is less flexible than multi-master replication.
Multi-master replication can also be contrasted with failover clustering where passive slave servers are replicating the master data in order to prepare for takeover in the event that the master stops functioning. The master is the only server active for client interaction.

Multi-master replication is a method of database replication which allows data to be stored by a group of computers, and updated by any member of the group. All members are responsive to client data queries.Master1 acts as the master for Master2, Master2 acts as the master for master1.


We have three mysql server.

1. 192.168.122.47 (Master1/ Slave2 redhat 6.5 )
2. 192.168.122.251 (Master2 /Slave1 redhat 6.5)
3. 192.168.122.235 (Slave redhat 6.5)

Now start with master1

[root@master1~]# yum install mysql mysql­server ­y

[root@master1~]# mysql_secure_installation

[root@master1~]# yum install mysql mysql­server ­y

[root@master1~]# mysql_secure_installation

[root@master1 ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic­links=0
server­id = 1
relay­log = /var/lib/mysql/mysql­relay­bin
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin
save 

[root@master1 ~]# mysql ­u root ­p
password:

mysql> slave stop;

GRANT REPLICATION SLAVE ON *.* TO 'raj'@'%' IDENTIFIED BY 'keenable@123';

mysql> FLUSH PRIVILEGES;

mysql> FLUSH READ LOCK WITH TABLES;

mysql> salve start; 

mysql> show master status;

mysql> show master status;
+------------------+----------+--------------+-------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+-------------------------+
| mysql-bin.000004 | 331 |               |                              |

+------------------+----------+--------------+-------------------------+
mysql> \q

Now take dump of all database and copy to master2 before this once again going to master1 for 
unloack table
[root@master1 ~]# mysqldump -u root -p --all-databases > /root/dbdump.db

[root@master1 ~]# mysql -­p
password:

mysql> uloack tables;

mysql> \q

[root@master1~]# scp ­r alldb.dbroot@master2.replication.com:
password:



Now going to master2 and import db


[root@master2 ~]#mysql ­u root ­p < /root/dbdump.db

[root@master2 ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic­links is recommendedsymbolic­links=0
to prevent assorted security risks
server­id = 2
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin


##############Entry for Master#############

master­host=192.168.122.47
master­connect­retry=60
master­user=raj
master­password=keenable@123
relay­log = /var/lib/mysql/mysql­relay­bin
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin
[mysqld_safe]
log­error=/var/log/mysqld.log
pid­file=/var/run/mysqld/mysqld.pid
save & quite


NOTE: Login into master2 as root user and stop the slave. Then tell the slave to where to look for Master1 log file, that we have write down on master with SHOW MASTER STATUS; command as File (mysql­bin.000004) and Position (331) 
numbers. You must change 192.168.122.47to the IPaddress of the Master1 Server, and change the user and password accordingly.

[root@master2~]#mysql ­u root ­p
password:

mysql> STOP SLAVE;

mysql> CHANGE MASTER TO MASTER_HOST='192.168.122.47', 
MASTER_USER='raj', 
MASTER_PASSWORD='keenable@123', MASTER_LOG_FILE='mysql­bin.000004', 
MASTER_LOG_POS=331;

mysql> show slave status\G

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to sendMaster_Host: 192.168.122.47
Master_User: raj
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql­bin.000004
Read_Master_Log_Pos: 331
Relay_Log_File: mysql­relay­bin.000013
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql­bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: 
Replicate_Ignore_DB: 
Replicate_Do_Table: 
Replicate_Ignore_Table: 
Replicate_Wild_Do_Table: 
Replicate_Wild_Ignore_Table: 
Last_Errno: 0
Last_Error: 
Skip_Counter: 0
Exec_Master_Log_Pos: 331
Relay_Log_Space: 551
Until_Condition: None
Until_Log_File: 
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File: 
Master_SSL_CA_Path: 
Master_SSL_Cert: 
Master_SSL_Cipher: 
Master_SSL_Key: 
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error: 
Last_SQL_Errno: 0
Last_SQL_Error: 
1 row in set (0.00 sec)
event

mysql> show master status;


+------------------+----------+--------------+-------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+-------------------------+
| mysql-bin.000004 | 185 |               |                              |

+------------------+----------+--------------+-------------------------+

Now time to configure master master replication

Come back to msater1 and edit config file (my.cnf)

[root@master1 ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic­links=0
server­id = 1
relay­log = /var/lib/mysql/mysql­relay­bin
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin

####Second step After done Master­Slave [This entry for master]####

master­host=192.168.122.251
master­connect­retry=60
master­user=raj
master­password=keenable@123
relay­log = /var/lib/mysql/mysql­relay­bin
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin
[mysqld_safe]
log­error=/var/log/mysqld.log
pid­file=/var/run/mysqld/mysqld.pid

save & quite

restart the mysql service and check master1.

[root@master1 ~]# /etc/init.d/mysqld restart

[root@master1 ~]# mysql ­u root ­p
password:

mysql> STOP SLAVE;

mysql> CHANGE MASTER TO MASTER_HOST='192.168.122.251', MASTER_USER='raj', 
MASTER_PASSWORD='keenable@123', MASTER_LOG_FILE='mysql­bin.000004', 
MASTER_LOG_POS=185;

mysql> show slave status\G

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to sendMaster_Host: 192.168.122.251
Master_User: raj
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql­bin.000004
Read_Master_Log_Pos: 185
Relay_Log_File: mysql­relay­bin.000024
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql­bin.000006
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: 
Replicate_Ignore_DB: 
Replicate_Do_Table: 
Replicate_Ignore_Table: 
Replicate_Wild_Do_Table: 
Replicate_Wild_Ignore_Table: 
Last_Errno: 0
Last_Error: 
Skip_Counter: 0
Exec_Master_Log_Pos: 185
Relay_Log_Space: 551
Until_Condition: None
Until_Log_File: 
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File: 
Master_SSL_CA_Path: 
Master_SSL_Cert: 
Master_SSL_Cipher: 
Master_SSL_Key: 
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error: 
Last_SQL_Errno: 0
Last_SQL_Error: 
1 row in set (0.00 sec)
event

Now go to master2 and edit my.cnf file for create master­-master

[root@master2 ~]#vim /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic­linkssymbolic­links=0
is recommended to prevent assorted security risks
server­id = 2
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin

########Entry for salve server as mster#############3
master­host=192.168.122.47
master­connect­retry=60
master­user=raj
master­password=keenable@123
relay­log = /var/lib/mysql/mysql­relay­bin
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin
[mysqld_safe]
log­error=/var/log/mysqld.log
pid­file=/var/run/mysqld/mysqld.pid

save & quite 

[root@master1 ~]# /etc/init.d/mysqld restart

[root@master1 ~]# mysql -p
password:

Now create database school on master1 & keenable on master2 and check on both master server

mysql> create database school;=====[Master1]

mysql> create database keenable; ===[Master2]

mysql> show databases;
+------------------------------+
| Database                    |
+------------------------------+
| information_schema   |
| mysql                          |
| school                         |
| keenable                     |
+------------------------------+

4 rows in set (0.00 sec)

Master2

mysql -­p
password:

mysql> show databases;
+----------------------------+
| Database                  |
+-------- -------------------+
| information_schema |
| mysql                        |
| school                       |
| keenable                   |
+----------------------------+

4 rows in set (0.00 sec)

Now time to configure slave server

Slave [192.168.122.235]


[root@slave ~]# yum install mysql mysq­server

[root@slave ~]# mysql_secure_installation

[root@slave ~]# vim /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic­links is recommended to prevent assorted securitysymbolic­links=0
relay­log = /var/lib/mysql/mysql­relay­bin
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin
[mysqld_safe]
log­error=/var/log/mysqld.log
pid­file=/var/run/mysqld/mysqld.pid 
risks

#####Entry for Slave####### 
master­host=192.168.122.47
master­connect­retry=60
master­user=slave_user
master­password=keenable@123
server­id = 3
relay­log = /var/lib/mysql/mysql­relay­bin
relay­log­index = /var/lib/mysql/mysql­relay­bin.index
log­error = /var/lib/mysql/mysql.err
master­info­file = /var/lib/mysql/mysql­master.info
relay­log­info­file = /var/lib/mysql/mysql­relay­log.info
log­bin = /var/lib/mysql/mysql­bin

save & quite

Restart mysql service

[root@slave ~]# /etc/init.d/mysqldrestart

[root@slave ~]# /etc/init.d/mysqld restart

[root@slave ~]# mysq ­uroot ­p
password:

mysql> slave stop;

mysql> CHANGE MASTER TO MASTER_HOST='192.168.122.47', MASTER_USER='raj', 
MASTER_PASSWORD='keenable@123', MASTER_LOG_FILE='mysql­bin.000005', 
MASTER_LOG_POS=588;

mysql> slave start;

mysql> show slave status\G

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.122.47
Master_User: raj
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql­bin.000005
Read_Master_Log_Pos: 588
Relay_Log_File: mysql­relay­bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql­bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: 
Replicate_Ignore_DB: 
Replicate_Do_Table: 
Replicate_Ignore_Table: 
Replicate_Wild_Do_Table: 
Replicate_Wild_Ignore_Table: 
Last_Errno: 0
Last_Error: 
Skip_Counter: 0
Exec_Master_Log_Pos: 588
Relay_Log_Space: 406
Until_Condition: None
Until_Log_File: 
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File: 
Master_SSL_CA_Path: 
Master_SSL_Cert: 
Master_SSL_Cipher: 
Master_SSL_Key: 
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert:Last_IO_Errno: 0
Last_IO_Error: 
Last_SQL_Errno: 0
Last_SQL_Error: 
1 row in set (0.00 sec)
No

NOTE: All database show into slave. And check on all server  connecting master1 master2 and slave each other master to master and master 
slave.

[root@slave ~]# mysq ­u root ­p
password:

mysql> show databases;


+-------------------------+
| Database |
+-------------------------+
| information_schema |
| mysql |
| school |
| keenable |
+-------------------------+

4 rows in set (0.00 sec)

Now successfully run multi-master replication.