Tuesday, September 29, 2009

INSTALL SHOREWALL(Configure Iptables easier )

I/INTRO

Shorewall (more appropriately the Shoreline Firewall) is an open source firewall tool for Linux that builds upon the Netfilter (iptables/ipchains) system built into the Linux kernel, making it easier to manage more complex configuration schemes.

Using an analogy understandable to programmers: Shorewall is to iptables, what C is to assembly language. It provides a higher level of abstraction for describing rules using text files.


II/INSTALL

1/ download all packages *.rpm of shorewall(http://rpm.pbone.net/ if You use Fedora can use yum ) and install with command rpm -ivh *.rpm

2/Configure Shorewall

I Configure shorewall with 3 interface and 3 zone:net,DMZ,Local

2.1/in file /etc/shorewall/zone add all lines

fw firewall

net ipv4 #

loc ipv4 #

dmz ipv4 #
2.2/ In file /etc/shorewall/interfaces add all lines

net eth1 #interface of zone net

loc eth0 # interface of Zone loc

dmz eth2 #interface of Zone dmz

2.3/In File /etc/shorewall/masq add all lines (This file use for NAT outbound)

eth1 192.168.100.0/24 172.21.1.16
eth1 192.168.111.0/24 172.21.1.16


192.168.100.0/24 subnet zone local.
192.168.111.0/24 subnet zone DMZ and ip:172.21.1.16 external address of firewall

2.4/In file etc/shorewall/policy add all lines

loc net REJECT info

net all DROP info

all all REJECT info

$FW net REJECT info

dmz net REJECT info

dmz loc REJECT info

loc dmz REJECT info


2.5/In file /etc/shorewall/rule add all lines


ACCEPT loc net tcp 80,443,25,110,53//(Permit access local->internet with protocol HTTP,HTTPS,SMTP,POP3,DNS)

ACCEPT loc net udp 53

ACCEPT loc net icmp echo-request //(
Permit ping local->internet)

ACCEPT loc fw tcp 2822 //(permit access SSH to firewall for Security I change port of SSH)

DNAT net dmz:192.168.111.2 tcp 80,443,110,25,995,465//(Nat INBOUND from internet can access protocols: HTTP,HTTPS,POP3,SMTP,POP3S,SMTPS)


Change

STARTUP_ENABLED=No -> STARTUP_ENABLED=Yes trong /etc/shorewall/shorewall.conf

start shorewall by command :shorewall start


For configure easier you can use webmin for configure shorewall with web interface.


Thursday, September 17, 2009

Active Directory/LDAP Virtual Users for RHEL/CentOS 5

This guide will show you how to integrate Active Directory/LDAP into Postfix and Dovecot. In this page, you will learn how to enable Postfix to lookup email addresses in LDAP and how to enable Dovecot to authenticate to an LDAP server.

We will be using the following attributes

  • samaccountname or uid – User Name for Active Directory or OpenLDAP respectively.
  • mail – Email Address. For Active Directory users, you need to fill-up the E-mail field of the User.
  • othermailbox – For Active Directory only. We will use this field to store email aliases. Use ADSI Edit to update this field.

Create the Virtual Mail User Account

Since the Active Directory/OpenLDAP user names are not part of the Linux system, we will have to create a user that will be the owner for all the files belonging to the LDAP user names.


1. Create a new user, we will call it vmail. Change the Login Shell to /sbin/nologin, this user account should not be used for logging in.

2. Take note of the User ID and Home Directory of vmail(example 502).

3. Now note down the Group ID of vmail. We’ll be needing all of them later.

Postfix Active Directory/LDAP Integration


1. Create the file /etc/postfix/ldap-users.cf containing the lines below
server_host = dc.test.vn
search_base = dc=test,dc=vn
version = 3
query_filter = (&(objectclass=person)(mail=%s))
result_attribute = samaccountname #Account from DC
result_format = %s/Maildir/

If you are connecting to an Active Directory server and would like to have email alias capability, change the query filter to (&(objectclass=person)(|(mail=%s)(othermailbox=%s))) to include the othermailbox field in the search.

Change samaccountname to uid if you will be connecting to an Active Directory server. If your server requires authentication, add the lines below

bind = yes
bind_dn = cn=mailuser,dc=test,dc=vn
bind_dn = mailuser@test.vn

2. Test your postfix configuration file by typing in the command

postmap -q cuibap@test.vn ldap:/etc/postfix/ldap-users.cf


If you are querying a Windows 2003 Server and postmap does
not seem to work,try
enabling the Windows 2003 Active Directory.


3. Edit the postfix configuration file /etc/postfix/main.cf and edit the line below
mydestination = $myhostname, localhost.$mydomain, localhost

and add the lines below

virtual_mailbox_domains = $mydomain
virtual_mailbox_base = /home/vmail/
virtual_mailbox_maps = ldap:/etc/postfix/ldap-users.cf
virtual_uid_maps = static:502
virtual_gid_maps = static:502
virtual_mailbox_base, virtual_uid_maps and virtual_gid_maps should contain the home directory, user id and group id of vmail respectively.

Make sure $mydomain in mydestination has been removed, otherwise the lookup will not work and you will get a “User unknown in local recipient table” error.

4. Restart the Postfix

5. You should now be able to send email to addresses found in your LDAP server. sing LDAP email addresses instead of the system user names.

Dovecot Active Directory/LDAP Integration

1. Create the file /etc/dovecot-ldap.conf containing the lines below
server_host = dc.test.vn
search_base = dc=test,dc=vn
ldap_version = 3
auth_bind_userdn = test\%u

2. Edit the file /etc/dovecot.conf and change the value of the following keys below

auth_username_format = %Lu

passdb ldap {
args = /etc/dovecot-ldap.conf
}

userdb static {
args = uid=502 gid=502 home=/home/vmail/%u
}

uid, gid and home should contain the user id, group id and home directory respectively of the vmail user account.

3. Restart the dovecot service

Friday, September 11, 2009

LOAD BALANCE AND CLUSTER FAILOVER WEBSERVER(INBOUND)USE PFSENSE

I/Intro

pfSense
is a FreeBSD-based firewall tailored for use as a firewall and router. The project started in 2004 as a fork of the m0n0wall project, but focused towards full PC installations rather than the embedded hardware focus of m0n0wall.

Common Deployments


Although mainly deployed as a perimeter firewall, pfSense is versatile enough to fill many types of deployments. Here is a short list of common deployments:

  • Perimeter Firewall - As discused earlier, this is by far the most common deployment for pfSense.
  • Router - Due to the ability to load balance connections and provide failover capabilities, pfSense makes for an ideal choice for a DIY Router for the SMB market.
  • Wireless Access Point - With the ability of Captive Portal within it, pfSense can easily be deployed as a wireless hotspot solution.
  • Special purpose appliance - Some users have decided to utilize pfSense in a unique way to helpfulfill their unique needs.
    • VPN Appliance
    • Sniffer Appliance
    • Dedicated DHCP server
    • Dedicated DNS server

Features

pfSense includes almost all the features in expensive commercial firewalls, and more in many cases. Here is a list of features taken from the pfSense Features page.

  • Firewall
  • State Table
  • NAT
  • Redundancy
    • CARP- CARP from OpenBSD allows for hardware failover. Two or more firewalls can be configured as a failover group. If one interface fails on the primary or the primary goes offline entirely, the secondary becomes active. pfSense also includes configuration synchronization capabilities, so you make your configuration changes on the primary and they automatically synchronize to the secondary firewall.
    • pfsync - pfsync ensures the firewall's state table is replicated to all failover configured firewalls. This means your existing connections will be maintained in the case of failure, which is important to prevent network disruptions.
  • Outbound and Inbound load balancing
  • VPN - IPsec, OpenVPN, PPTP
  • PPPoE Server
  • RRD Graphs Reporting
  • Real Time Information - Using AJAX
  • Dynamic DNS
  • Captive portal
  • DHCP Server and Relay
  • Live CD Version Available
II/INSTALL





Step 1:Install Pfsense from CD

Step 2:enable vlan or no(I choose "no")

Step 3:enter the lan interface name


Step 4:enter the wan interface name

Step 5: enter

Step 6 type "y"


Step 7: setup ip adrress as Diagram
III/LOAD BALANCE WEB

Step 8:Set up Load Balancing Pool

The first thing to do is create a pool (Services > Load Balancer > Add).


Step 9:Set up virtual server

Adding a new Virtual Server (Services > Load balancer > Virtual Servers > Add )


Step 10: Set up virtual ip address

Adding a new Virtual IP (Firewall > Virtual IPs > Add )



Step 11:Create Nat(Firewall > Nat > Add)


Note: open port 80 from Internet access to 192.168.0.5 and 192.168.0.6

Step 12:Access to http://192.168.20.204/ and check status load balance






Step 13:Disconnect 192.168.0.5 Access to http://192.168.20.204/ and check status load balance


IV/CLUSTER FAILOVER

As LOAD balance but choose Failover

Besides pfsense can create cluster fail over firewall and load balance outbound

Thursday, September 10, 2009

Redundant Load Balancers Using VRRP

I/INTRO

Pen offers fault tolerance by automatically rerouting traffic from servers that are offline. But what if the load balancer goes down? Using VRRP, it is possible to run two load balancers in an active-passive failover configuration



II/INSTALL VRRP



[root@ ~]wget http://downloads.sourceforge.net/project/vrrpd/vrrpd/1.0/vrrpd-1.0.tar.gz?use_mirror=biznetnetworks
1. uncompress the source
2. cd in the directory
3. type 'make'(Please install gcc* before type make by "yum -y install gcc*")
[root@ ~] cp vrrpd /usr/sbin/vrrpd

Install pen and vrrpd on the two load balancer hosts. Start pen on both load balancers and check that both work by surfing to http://102.168.0.1/ and http://102.168.0.2/.

Now start vrrpd like this on both load balancers:

[root@ ~]vrrpd -i eth1 -v 1 192.168.0.3

Now try surfing to http://192.168.0.3/. One of the load balancers will be active and respond at that address


Disconnect "MASTER" .Now "SLAVE" restoring functionality.

Connect "MASTER" .Disconnect "SLAVE" ,"MASTER" restoring functionality



Tuesday, September 8, 2009

LOAD BALANCE WEB SERVER USE PEN

I/Intro

This is pen, a load balancer for "simple" tcp based protocols such as http or smtp. It allows several servers to appear as one to the outside and automatically detects servers that are down and distributes clients among the available servers. This gives high availability and scalable performance.

The load balancing algorithm keeps track of clients and will try to send them back to the server they visited the last time. The client table has a number of slots (default 2048, settable through command-line arguments). When the table is full, the least recently used one will be thrown out to make room for the new one.

This is superior to a simple round-robin algorithm, which sends a client that connects repeatedly to different servers. Doing so breaks applications that maintain state between connections in the server, including most modern web applications.

When pen detects that a server is unavailable, it scans for another starting with the server after the most recently used one. That way we get load balancing and "fair" failover for free.

Correctly configured, pen can ensure that a server farm is always available, even when individual servers are brought down for maintenance or reconfiguration. The final single point of failure, pen itself, can be eliminated by running pen on several servers, using vrrp to decide which is active.

Refer:

http://siag.nu/pen/

II/Install

This example is based on follwing environmet.

(1) cluster.test.vn [192.168.20.101] Pen Server
(2) www1.test.vn [192.168.20.203] Web Server #1
(3) www2.test.vn [192.168.20.83] Web Server #2

1/Install and configure Pen
[root@ ~]# wget http://dag.wieers.com/rpm/packages/pen/pen-0.17.2-1.el5.rf.i386.rpm
[root@ ~]#rpm -Uvh pen-0.17.2-1.el5.rf.i386.rpm
[root@ ~]#vim /etc/rc.d/init.d/pen
# make scripts
# an example
#!/bin/bash
#
# Pen: Starting Pen
#
# chkconfig: 345 93 92
# description:Simple load-balancer
# processname: pen

. /etc/rc.d/init.d/functions

pen="/usr/local/bin/pen"
lockfile="/var/lock/subsys/pen"
prog="pen"
RETVAL=0

# PID file

PID=/var/run/pen.pid-80
# log file

LOGFILE=/var/log/pen.log
# control port

CONTROL=localhost:10080
# max connections

MAX_CONNECTIONS=500
# port

PORT=80
# number of servers

SERVERS=2
# IP of a server #1

SERVER1=192.168.20.203:80
# IP of a server #2

SERVER2=192.168.20.83:80

start() {
echo -n $"Starting $prog: "
daemon $pen -x $MAX_CONNECTIONS -S $SERVERS -p $PID -l $LOGFILE -C $CONTROL -r $PORT $SERVER1 $SERVER2
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $pen
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $lockfile
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $pen
;;
*)
echo "Usage: $prog {start|stop|restart|status}"
exit 1
esac

exit $?

[root@lan ~]#
vi /etc/logrotate.d/pen
# an example
/var/log/pen.log { daily copytruncate compress notifempty missingok postrotate /etc/rc.d/init.d/pen restart 2>&1 > /dev/null || true endscript }

[root@lan ~]#chmod 755 /etc/rc.d/init.d/pen
[root@lan ~]#/etc/rc.d/init.d/pen startStarting pen: [ OK ]
[root@lan ~]#chkconfig --add pen
[root@lan ~]#chkconfig pen on

2/Configure a tool that shows status of Pen from web browser.

[root@lan ~]#vi /etc/rc.d/init.d/pen


# line 16: specify html file
WEBFILE=/var/www/html/pen/index.html
PID=/var/run/pen.pid-80 LOGFILE=/var/log/pen.log
# add options

daemon $pen -w $WEBFILE -x $MAX_CONNECTIONS -S $SERVERS -p $PID -l $LOGFILE -C $CONTROL -r $PORT $SERVER1 $SERVER2

[root@lan ~]#cp /usr/local/doc/pen/penstats /usr/local/bin/
[root@lan ~]#vi /usr/local/bin/penstats
#!/bin/sh PENHOME=/home/ulric/Projekt/pen PIDFILE=/var/run/pen.pid-80
# change
WEBFILE=/var/www/html/pen/index.html
# change
# This will make pen save its stats kill -USR1 `cat $PIDFILE` # We don't know how long it will take; wait a few seconds sleep 2 # And display the results echo "Content-type: text/html" echo cat $WEBFILE

[root@lan ~]#/etc/rc.d/init.d/pen restart
Stopping pen:[ OK ]
Starting pen:[ OK ]
[root@lan ~]#chmod 755 /usr/local/bin/penstats
[root@lan ~]#/usr/local/bin/penstats# run
[root@lan ~]#crontab -e

*/1 * * * * /usr/local/bin/penstats


3/Access to Pen server with web browser. A backend server answers normally like below.

a/First Request


b/Second request


4/ Stop httpd on a server now and access to pen server again. Another backend server answers normally like below.

a/ Stop http in 192.168.20.203



b/ Stop http in 192.168.20.83



Note:you need configure Apache listen port 81:

change listen port 80 to 81
Besides Pen can loadbalance other service (FTP,HTTPS,SMTP,POP3...)
pen -l pen443.log -p pen443.pid 192.168.20.101:443
192.168.20.203:443 192.168.20.83:443
(LOAD BALANCE HHTPS)

pen -l pen110.log -p pen110.pid 192.168.20.101:110
192.168.20.203:110 192.168.20.83:110
(LOAD BALANCE POP3)

pen -l pen25.log -p pen25.pid 192.168.20.101:25
192.168.20.203:25 192.168.20.83:25
(LOAD BALANCE SMTP)

pen -l pen21.log -p pen21.pid 192.168.20.101:21
192.168.20.203:21 192.168.20.83:21
(LOAD BALANCE FTP)





Friday, September 4, 2009

Install ClamAV

[root@lan ~]#yum -y install clamav // (or download clamav and clam-db for install manual)
[root@lan ~]#vim /etc/freshclam.conf

#NotifyClamd /etc/clamd.conf

[root@lan ~]#freshclam // update policy file

[root@lan ~]#clamscan --infected --remove --recursive /home
[root@lan ~]#wget http://www.eicar.org/download/eicar.com
[root@lan ~]#clamscan --infected --remove --recursive .

You will detect and delete virus




INSTALL PROXY WITH ANTIVIRUS AND DB BLACKLIST

I/INSTAL SQUID PROXY
1/Install and configure squid

[root@lan ~]#yum -y install squid
[root@lan ~]#vi /etc/squid/squid.conf

http_port 8080 acl CONNECT method CONNECT
acl lan src 192.168.0.0/255.255.255.0
// (permit only LAN)
http_access allow localhost
http_access allow lan
// add (permit only LAN)
http_access deny all
visible_hostname test.vn
// add (specify hostname)
# forwarded_for on
forwarded_for off
// add (hide IP address)
header_access Referer deny all
// add

header_access X-Forwarded-For deny all
header_access Via deny all
header_access Cache-Control deny all


[root@lan ~]#/etc/rc.d/init.d/squid start
init_cache_dir /var/spool/squid... Starting squid:[ OK ]
[root@lan ~]#chkconfig squid on
II/PROXY WITH ANTI VIRUS

Configure Proxy in order to scan download files to protect from virus. Install clamav first

1/Install clamd

[root@lan ~]#yum -y install clamd ( Or download from http://rpm.pbone.net/)
[root@lan ~]#vim /etc/clamd.conf

LocalSocket /var/run/clamav/clamd.sock //change

[2] Install squidclamav

[root@lan ~]# wget http://www.darold.net/projects/squidclamav/squidclamav-4.0.tar.gz
root@lan ~]#tar zxvf squidclamav-4.0.tar.gz
[root@lan ~]#cd squidclamav-4.0
[root@lan squidclamav-4.0]#./configure
[root@lan squidclamav-4.0]#make
[root@lan squidclamav-4.0]#make install
[root@lan squidclamav-4.0]#cp squidclamav.conf.dist /etc/squidclamav.conf
[root@lan squidclamav-4.0]#cd
[root@lan ~]#vim /etc/squidclamav.conf


proxy http://127.0.0.1:8080/// change ( proxy address )
logfile /var/log/squid/squidclamav.log// change ( log file )
redirect http://www.yahoo.com/// change ( redirect URL )
# squidguard /usr/local/squidGuard/bin/squidGuard
debug 0
force 1
stat 1
clamd_local /var/run/clamav/clamd.sock// change
clamd_ip 127.0.0.1
clamd_port 3310
timeout 60
abort ^.*\.gz$
abort ^.*\.bz2$
abort ^.*\.pdf$
abort ^.*\.js$
abort ^.*\.html$
abort ^.*\.css$
abort ^.*\.xml$
abort ^.*\.xsl$
abort ^.*\.js$
abort ^.*\.ico$
aborti ^.*\.gif$
aborti ^.*\.png$
aborti ^.*\.jpg$
aborti ^.*\.swf$
content ^.*application\/.*$
whitelist .*yahoo\.com

[3] Configurarion of squid


[root@lan ~]#vim /etc/squid/squid.conf

add these 3 lines at the bottom

url_rewrite_access deny localhost
redirect_program /usr/local/bin/squidclamav
redirect_children 15


[root@lan ~]#touch /var/log/squid/squidclamav.log
[root@lan ~]#chown squid. /var/log/squid/squidclamav.log
[root@lan ~]#vim /etc/logrotate.d/squid

add at the bottom

/var/log/squid/squidclamav.log {
weekly
rotate 5
copytruncate
compress
notifempty
missingok
}


[root@lan ~]#/etc/rc.d/init.d/squid restart
Stopping squid: .............[ OK ]
Starting squid: .[ OK ]


III/PROXY WITH SQUIDGRARD

[1] Install squidguard

[root@lan ~]#yum -y install squidguard [root@lan ~]#mv /etc/squid/squidguard.conf /etc/squid/squidguard.conf.bk
[root@lan ~]#vi /etc/squid/squidguard.conf

// configure like following example

#
# CONFIG FILE FOR SQUIDGUARD
#

dbhome /var/lib/squidguard
logdir /var/log/squidguard

dest dame {

domainlist dame/domains
urllist dame/urls
}
acl {
default {
pass !dame all
redirect http://www.yahoo.com/

}

}

[root@lan ~]#mkdir /var/lib/squidguard/dame
[root@lan ~]#vi /var/lib/squidguard/dame/domains

// write domains you'd like to prohibit to access

yahoo.com
conheotiensinh.blogspot.com


[root@lan ~]#vi /var/lib/squidguard/dame/urls

// writeURLs you'd like to prohibit to access

www.yahoo.com/deny/
conheotiensinh.blogspot.com /


[root@lan ~]#squidGuard -C all// create DB
[root@lan ~]#chown -R squid. /var/lib/squidguard/dame

[root@lan ~]#vim /etc/squidclamav.conf

squidguard /usr/bin/squidguard
// line 42: make valid and change PASS


[root@lan ~]#/etc/rc.d/init.d/squid restart
Stopping squid: .............[ OK ]
Starting squid: .[ OK ]






2/Try to access to Yahoo set as prohibited domain in . Anyway, this redirect setting is an example to show action of this squidGuard, but please make your own original redirect page because it's meaningless to redirect to google like this example.



Tuesday, September 1, 2009

Cluster Linux Mail Server

1/Install heart beart for Cluster

Please refer:

http://conheotiensinh.blogspot.com/2009/08/high-availability-http-use-heartbeat.html

http://www.linux-ha.org/

USE Pfsense for load balance or Cluster FailOver(http://conheotiensinh.blogspot.com/2009/09/load-balance-and-cluster-failover.html)

Use Pen for Loadbalance(http://conheotiensinh.blogspot.com/2009/09/load-balance-web-server-use-pen.html)

2/Master-Master Replication With MySQL


1.1 System 1

Hostname: mail.test.vn
IP: 192.168.20.203


1.2 System 2

Hostname: mail1.test.vn
IP: 192.168.20.83

Step 1: MySQL Root Password

Both Systems

Set a password for the MySQL root-user on localhost.

mysqladmin -u root password 123

System 1

Set a password for the MySQL root-user on mail.test.vn.

mysqladmin -u root -h 192.168.20.203 password 123

System 2

Set a password for the MySQL root-user on mail1.test.vn.

mysqladmin -u root -h 192.168.20.83 password 123


Step2:MySQL Replication User

System 1

Create the replication user that System 2 will use to access the MySQL database on System 1.

mysql -u root -p

GRANT REPLICATION SLAVE ON *.* TO 'system'@'%' IDENTIFIED BY '123';
FLUSH PRIVILEGES;
quit;

System 2

Create the replication user that System 1 will use to access the MySQL database on System 2.

mysql -u root -p

GRANT REPLICATION SLAVE ON *.* TO 'system'@'%' IDENTIFIED BY '123';
FLUSH PRIVILEGES;
quit;


Step 3: Open port 3306 for connect

Step 4:MySQL Configuration

In the next two steps we adjust the MySQL configuration on both systems for master-master replication.

System 1

vi /etc/my.cnf

Add the following lines to the section [mysqld]:

server-id = 1
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 1

master-host = 192.168.20.83
master-user = system
master-password = 123
master-connect-retry = 60
replicate-do-db =vmail

log-bin = /var/log/mysql/mysql-bin.log
binlog-do-db = vmail

relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index

expire_logs_days = 10
max_binlog_size = 500M

Afterwards restart the MySQL server.

/etc/init.d/mysqld restart

System 2

vi /etc/my.cnf

Add the following lines to the section [mysqld]:

server-id = 2
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset = 2

master-host = 192.168.20.203
master-user = system
master-password = 123
master-connect-retry = 60
replicate-do-db =vmail

log-bin= /var/log/mysql/mysql-bin.log
binlog-do-db =vmail

relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index

expire_logs_days = 10
max_binlog_size = 500M

Afterwards restart the MySQL server.

/etc/init.d/mysqld restart

Step 5:Export MySQL Dump On System 1

Now we create a dump of the existing database and transfer it to system 2.

mysql -u root -p

USE vmail;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

+------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000007 | 30330 | vmail,vmail | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)

Open a second terminal for system 1, create the dump and transfer it to system 2. Don't leave the MySQL-shell at this point - otherwise you'll loose the read-lock.

cd /tmp/
mysqldump -u root -p123 --opt vmail > sqldump.sql
scp sqldump.sql root@192.168.20.83:/tmp/

Afterwards close the second terminal and switch back to the first. Remove the read-lock and leave the MySQL-shell.

UNLOCK TABLES;
quit;

Step 6: Import MySQL Dump On System 2

Time to import the database dump on system 2.

mysqladmin --user=root --password=123 stop-slave
cd /tmp/
mysql -u root -p123 vmail <>

Step 7:System 2 As Master

Now we need information about the master status on system 2.

mysql -u root -p
USE vmail;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

The output should look like this. Note down the file and the position - you'll need both later.

+------------------+----------+---------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+---------------------+------------------+
| mysql-bin.000009 | 28816 | vmail,vmail | |
+------------------+----------+---------------------+------------------+
1 row in set (0.00 sec)

Afterwards remove the read-lock.

UNLOCK TABLES;

At this point we're ready to become the master for system 1. Replace %mysql_slaveuser_password% with the password you choose and be sure that you replace the values for MASTER_LOG_FILE and MASTER_LOG_POS with the values that you noted down at step 5!

CHANGE MASTER TO MASTER_HOST='192.168.20.203', MASTER_USER='system', MASTER_PASSWORD='123', MASTER_LOG_FILE='mysql-bin.000007', MASTER_LOG_POS=30330;

Now start the slave ...

START SLAVE;

quit;

Step 8:System 1 As Master

Open a MySQL-shell on system 1 ...

mysql -u root -p

... and stop the slave.

STOP SLAVE;

At this point we're ready to become the master for system 2. Replace %mysql_slaveuser_password% with the password you choose and be sure that you replace the values for MASTER_LOG_FILE and MASTER_LOG_POS with the values that you noted down at step 7!

CHANGE MASTER TO MASTER_HOST='192.168.20.83', MASTER_USER='system', MASTER_PASSWORD='123', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=28816;

Now start the slave ...

START SLAVE;

quit;

Step 10:Test


create mailbox Test1@test.vn and add in mailist ug@test.vn in system1:192.168.20.203


Check in system 2:192.168.20.83

create mailbox Test2@test.vn and add in mailist ug@test.vn in system2:192.168.20.83


Check in system 1:192.168.20.203



Now i can login 2 Accounts in system1 and system 2

Beside you need replicate other DB:mysql ,policyd, roundcubemail.