Friday, March 30, 2012

Master-Slave Replication

For master

[mysqld]
#set-variable = max_connections=500
safe-show-database

skip-locking
key_buffer = 100M
max_allowed_packet = 64M
log-error=/var/log/mysql/mysql-error.log
long_query_time = 3
log-slow-queries=/var/log/mysql/mysql-slow.log
table_cache = 512
sort_buffer_size = 10240K
read_buffer_size = 10240K
read_rnd_buffer_size = 10240K
net_buffer_length = 10240k
myisam_sort_buffer_size = 100M
max_connections=2048
set-variable = max_user_connections=2048
set-variable = max_connect_errors=999999
set-variable = query_cache_size=512M
query_cache_limit = 512M
set-variable = join_buffer=512M
thread_cache_size = 1024

log-bin=/var/lib/mysql/binlog
#binlog-do-db=systemWcell
#binlog-ignore-db=mysql
#binlog-ignore-db=test

server-id=4

create mysql user for replication
GRANT ALL PRIVILEGES ON *.* TO repl@replication server ip ;
SET PASSWORD FOR repl@replication server ip =PASSWORD('QHeqJ3TH');
FLUSH PRIVILEGES;

mysql> show master status\G
*************************** 1. row ***************************
File: binlog.000013
Position: 453
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

For slave
[mysqld]
set-variable = max_connections=500
safe-show-database

skip-locking
key_buffer = 100M
max_allowed_packet = 64M
log-error=/var/log/mysql/mysql-error.log
long_query_time = 3
log-slow-queries=/var/log/mysql/mysql-slow.log
table_cache = 512
sort_buffer_size = 10240K
read_buffer_size = 10240K
read_rnd_buffer_size = 10240K
net_buffer_length = 10240k
myisam_sort_buffer_size = 100M
max_connections=2048
set-variable = max_user_connections=2048
set-variable = max_connect_errors=999999
set-variable = query_cache_size=512M
query_cache_limit = 512M
set-variable = join_buffer=512M
thread_cache_size = 1024

server-id=7

#binlog-do-db=systemWcell
replicate-do-db=systemWcell ---------------------------- DB Name
slave_skip_errors=all
#relay-log=/var/lib/mysql/relaylog


" CHANGE MASTER TO
" MASTER_HOST='Master IP,
" MASTER_USER='repl',
" MASTER_PASSWORD='QHeqJ3TH',
" MASTER_PORT=3306,
" MASTER_LOG_FILE='bin-log.000013',------------------------------ bin log possition
" MASTER_LOG_POS= 453;



+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000002 | 2397878 | | |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)

Mysql > Start slave;
Mysql> show slave status;

HA Configuration

Installation:

On machine1 and machine2 install Heartbeat and needed utilities. You may need to review the packages you have available using ‘yum list | grep drbd’. These are for CentOS 5.5. You may also need to reboot after this step.

# yum -y install gnutls*
# yum -y install ipvsadm*
# yum -y install heartbeat*
# yum -y install heartbeat.x86_64

Configuration:

Edit /etc/sysctl.conf and set net.ipv4.ip_forward = 1

# vi /etc/sysctl.conf

Controls IP packet forwarding net.ipv4.ip_forward = 1

# /sbin/chkconfig --level 2345 heartbeat on
# /sbin/chkconfig --del ldirectord

Configure HA:

You need to setup the following configuration files on both machines:

# vi /etc/ha.d/ha.cf

#/etc/ha.d/ha.cf content
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694 # If you have multiple HA setup in same network.. use different ports
bcast eth0 # Linux
auto_failback on # This will failback to machine1 after it comes back
ping 192.168.2.1 # The gateway
apiauth ipfail gid=haclient uid=hacluster
node db1.grennan.com
node db2.grennan.com

On both machines

NOTE: Assuming 192.168.2.15 is virtual IP for your MySQL resource and mysqld is the LSB resource agent. The host name (db2) should be the secondary server’s name.

# vi /etc/ha.d haresources

# /etc/ha.d/haresources content
db2.grennan.com LVSSyncDaemonSwap::master Paddr2::192.168.2.15/24/eth0 rbddisk::db Filesystem::/dev/drbd1::/data::ext3 mysqld

# vi /etc/ha.d/authkeys

#/etc/ha.d/authkeys content
auth 2
2 sha1 BigSecretKeyks9wjwlf9gskg905snvl

Now, make your authkeys secure:

# chmod 600 /etc/ha.d/authkeys

Check your work:

On both machines, one at a time, stop MySQL and make sure MySQL does not start when the system reboots (init 6).

If it does, you may need to remove it from the init process with:

# /sbin/chkconfig --level 2345 MySQL off

Start Heartbeat.

# service heartbeat start

These commands will give you status about this LVS setup:

# /etc/ha.d/resource.d/LVSSyncDaemonSwap master status
# ip addr sh
# service heartbeat status
# df
# service mysqld status

Access your HA-MySQL server like:

# mysql –h 192.168.2.15

Shutdown machine1 to see MySQL up on machine2. ‘shutdown now’

Start machine1 to see MySQL back on machine1.

Master-Master Replication

Master 1 IP Address : 192.168.0.2
Master 2 IP Address: 192.168.0.3
Database to replicate: db1, db2, and db3


Master 1
On 192.168.0.2

mysql> CREATE USER 'repl'@'192.168.0.3' IDENTIFIED BY 'gmi123W';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.0.3' IDENTIFIED BY 'gmi123W';
mysql> FLUSH PRIVILEGES;

mysql> CREATE USER 'repl'@'192.168.0.%' IDENTIFIED BY 'gmi123W';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.0.%' IDENTIFIED BY 'gmi123W';
mysql> FLUSH PRIVILEGES;


skip-locking
key_buffer = 100M
max_allowed_packet = 64M
log-error=/var/log/mysql/mysql-error.log
long_query_time = 3
log-slow-queries=/var/log/mysql/mysql-slow.log
table_cache = 512
sort_buffer_size = 10240K
read_buffer_size = 10240K
read_rnd_buffer_size = 10240K
net_buffer_length = 10240k
myisam_sort_buffer_size = 100M
max_connections=2048
set-variable = max_user_connections=2048
set-variable = max_connect_errors=999999
set-variable = query_cache_size=512M
query_cache_limit = 512M
set-variable = join_buffer=512M
thread_cache_size = 1024

server-id = 3

master-host = 192.168.0.3
master-user = repl
master-password = gmi123W
master-connect-retry = 30
slave-net-timeout = 30
replicate-do-db = arvind


log-bin = /var/log/mysql/mysql-bin.log
log-bin-index = /var/log/mysql/master-log-bin.index
binlog-do-db = arvind


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

mysql>USE arvind;
mysql>UNLOCK TABLES;
mysql>FLUSH TABLES WITH READ LOCK;


mysql> CHANGE MASTER TO MASTER_HOST = '192.168.0.3', MASTER_USER = 'repl', MASTER_PASSWORD = 'gmi123W', MASTER_LOG_FILE = 'mysql-bin.000001',

MASTER_LOG_POS=789;

FLUSH PRIVILEGES;

Master2

On 192.168.0.3

mysql> CREATE USER 'repl'@'192.168.0.2' IDENTIFIED BY 'gmi123W';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.0.2' IDENTIFIED BY 'gmi123W';
mysql> FLUSH PRIVILEGES;

mysql> CREATE USER 'repl'@'192.168.0.%' IDENTIFIED BY 'gmi123W';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.0.%' IDENTIFIED BY 'gmi123W';
mysql> FLUSH PRIVILEGES;

skip-locking
key_buffer = 100M
max_allowed_packet = 64M
log-error=/var/log/mysql/mysql-error.log
long_query_time = 3
log-slow-queries=/var/log/mysql/mysql-slow.log
table_cache = 512
sort_buffer_size = 10240K
read_buffer_size = 10240K
read_rnd_buffer_size = 10240K
net_buffer_length = 10240k
myisam_sort_buffer_size = 100M
max_connections=2048
set-variable = max_user_connections=2048
set-variable = max_connect_errors=999999
set-variable = query_cache_size=512M
query_cache_limit = 512M
set-variable = join_buffer=512M
thread_cache_size = 1024

server-id = 4

master-host = 192.168.0.2
master-user = repl
master-password = gmi123W
master-connect-retry = 30
slave-net-timeout = 30
replicate-do-db = arvind

log-bin = /var/log/mysql/mysql-bin.log
log-bin-index = /var/log/mysql/master-log-bin.index
binlog-do-db = arvind

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


mysql>USE arvind;
mysql>UNLOCK TABLES;
mysql>FLUSH TABLES WITH READ LOCK;

CHANGE MASTER TO MASTER_HOST = '192.168.0.2', MASTER_USER = 'repl', MASTER_PASSWORD = 'gmi123W', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS=193;

FLUSH PRIVILEGES;




To Check run below query

create database arvind;


use arvind;

INSERT INTO `citnet_patent` ( `patent_id` , `patent_no` , `patent_f_cit_depth1` , `patent_b_cit_depth1` , `patent_rel_depth1` , `patent_matrix_depth1` ,

`patent_f_cit_depth2` , `patent_b_cit_depth2` , `patent_rel_depth2` , `patent_matrix_depth2` , `patent_first_srch_date` , `patent_update_date` ,

`patent_type` )
VALUES (
'5001', 'ep717426', '', '', '', NULL , NULL , NULL , NULL , NULL , NULL , NULL , '0'
);



select * from citnet_patent;

UPDATE `citnet_patent` SET `patent_no` = 'AS717426',
`patent_matrix_depth1` = NULL ,
`patent_f_cit_depth2` = NULL ,
`patent_b_cit_depth2` = NULL ,
`patent_rel_depth2` = NULL ,
`patent_matrix_depth2` = NULL ,
`patent_first_srch_date` = NULL ,
`patent_update_date` = NULL WHERE `patent_id` =5001 LIMIT 1 ;

select * from citnet_patent;
Tuesday, March 13, 2012

SquirrelMail webmail

To install the SquirrelMail webmail client, run...

yum install squirrelmail

... and restart Apache:

/etc/init.d/httpd restart

Then configure SquirrelMail:

/usr/share/squirrelmail/config/conf.pl

We must tell SquirrelMail that we are using Courier-IMAP/-POP3:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color off
S Save data
Q Quit

Command >> <-- D


SquirrelMail Configuration : Read: config.php
---------------------------------------------------------
While we have been building SquirrelMail, we have discovered some
preferences that work better with some servers that don't work so
well with others. If you select your IMAP server, this option will
set some pre-defined settings for that server.

Please note that you will still need to go through and make sure
everything is correct. This does not change everything. There are
only a few settings that this will change.

Please select your IMAP server:
bincimap = Binc IMAP server
courier = Courier IMAP server
cyrus = Cyrus IMAP server
dovecot = Dovecot Secure IMAP server
exchange = Microsoft Exchange IMAP server
hmailserver = hMailServer
macosx = Mac OS X Mailserver
mercury32 = Mercury/32
uw = University of Washington's IMAP server
gmail = IMAP access to Google mail (Gmail) accounts

quit = Do not change anything
Command >> <-- courier


SquirrelMail Configuration : Read: config.php
---------------------------------------------------------
While we have been building SquirrelMail, we have discovered some
preferences that work better with some servers that don't work so
well with others. If you select your IMAP server, this option will
set some pre-defined settings for that server.

Please note that you will still need to go through and make sure
everything is correct. This does not change everything. There are
only a few settings that this will change.

Please select your IMAP server:
bincimap = Binc IMAP server
courier = Courier IMAP server
cyrus = Cyrus IMAP server
dovecot = Dovecot Secure IMAP server
exchange = Microsoft Exchange IMAP server
hmailserver = hMailServer
macosx = Mac OS X Mailserver
mercury32 = Mercury/32
uw = University of Washington's IMAP server
gmail = IMAP access to Google mail (Gmail) accounts

quit = Do not change anything
Command >> courier

imap_server_type = courier
default_folder_prefix = INBOX.
trash_folder = Trash
sent_folder = Sent
draft_folder = Drafts
show_prefix_option = false
default_sub_of_inbox = false
show_contain_subfolders_option = false
optional_delimiter = .
delete_folder = true

Press any key to continue... <-- press ENTER


SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color off
S Save data
Q Quit

Command >> <--S


SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color off
S Save data
Q Quit

Command >> <--Q

One last thing we need to do is modify the file /etc/squirrelmail/config_local.php and comment out the $default_folder_prefix variable - if you don't do this, you will see the following error message in SquirrelMail after you've logged in: Query: CREATE "Sent" Reason Given: Invalid mailbox name.

vi /etc/squirrelmail/config_local.php

/**
* Local config overrides.
*
* You can override the config.php settings here.
* Don't do it unless you know what you're doing.
* Use standard PHP syntax, see config.php for examples.
*
* @copyright © 2002-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: config_local.php,v 1.2 2006/07/11 03:33:47 wtogami Exp $
* @package squirrelmail
* @subpackage config
*/
//$default_folder_prefix = '';
?>


Now you can type in http://server1.example.com/webmail
Friday, March 9, 2012

How Do I Enable remote access to PostgreSQL database server

Step # 1: Login over ssh if server is outside your IDC

Login over ssh to remote PostgreSQL database server:
$ ssh user@remote.pgsql.server.com

Step # 2: Enable client authentication

Once connected, you need edit the PostgreSQL configuration file, edit the PostgreSQL configuration file /var/lib/pgsql/data/pg_hba.conf (or /etc/postgresql/8.2/main/pg_hba.conf for latest 8.2 version) using a text editor such as vi.

Login as postgres user using su / sudo command, enter:
$ su - postgres
Edit the file:
$ vi /var/lib/pgsql/data/pg_hba.conf
OR
$ vi /etc/postgresql/8.2/main/pg_hba.conf
Append the following configuration lines to give access to 10.10.29.0/24 network:
host all all 10.10.29.0/24 trust
Save and close the file. Make sure you replace 10.10.29.0/24 with actual network IP address range of the clients system in your own network.

Step # 2: Enable networking for PostgreSQL

You need to enable TCP / IP networking. Use either step #3 or #3a as per your PostgreSQL database server version.

Step # 3: Allow TCP/IP socket

If you are using PostgreSQL version 8.x or newer use the following instructions or skip to Step # 3a for older version (7.x or older).

You need to open PostgreSQL configuration file /var/lib/pgsql/data/postgresql.conf or /etc/postgresql/8.2/main/postgresql.conf.
# vi /etc/postgresql/8.2/main/postgresql.conf
OR
# vi /var/lib/pgsql/data/postgresql.conf
Find configuration line that read as follows:
listen_addresses='localhost'
Next set IP address(es) to listen on; you can use comma-separated list of addresses; defaults to 'localhost', and '*' is all ip address:
listen_addresses='*'
Or just bind to 202.54.1.2 and 202.54.1.3 IP address
listen_addresses='202.54.1.2 202.54.1.3'
Save and close the file. Skip to step # 4.


Step #3a - Information for old version 7.x or older

Following configuration only required for PostgreSQL version 7.x or older. Open config file, enter:
# vi /var/lib/pgsql/data/postgresql.conf
Bind and open TCP/IP port by setting tcpip_socket to true. Set / modify tcpip_socket to true:
tcpip_socket = true
Save and close the file.


Step # 4: Restart PostgreSQL Server

Type the following command:
# /etc/init.d/postgresql restart

Step # 5: Iptables firewall rules

Make sure iptables is not blocking communication, open port 5432 (append rules to your iptables scripts or file /etc/sysconfig/iptables):

iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d 10.10.29.50 --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s 10.10.29.50 --sport 5432 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

Restart firewall:
# /etc/init.d/iptables restart

Step # 6: Test your setup

Use psql command from client system. Connect to remote server using IP address 10.10.29.50 and login using vivek username and sales database, enter:
$ psql -h 10.10.29.50 -U vivek -d sales
Saturday, March 3, 2012

Online Virus Scan URL

http://www.avg.com.au/resources/web-page-scanner/

http://sucuri.net

https://www.virustotal.com/