Monday, March 18, 2013

Register listener manually on OCR

crs_stat -p ora.vm2.LISTENER_VM2.lsnr > /tmp/list

Modify relevent parameters on /tmp/list file after that register that profile on OCR

mv /tmp/list /tmp/ora.vm2.LISTENER_VM2_T.lsnr.cap
crs_register ora.vm2.LISTENER_VM2_T.lsnr -dir /tmp/
srvctl start listener -l LISTENER_VM2_T -n vm2

Saturday, March 16, 2013

Mysql Replication (Master-Slave)

Mysql Replication (Master - Slave):

Master Server    : 192.168.0.109
Slave Server    : 192.168.0.201

Master Node:
1. Backup the cnf file and add below entries on cnf file

key_buffer = 128m
myisam_sort_buffer_size = 32m
query_cache_size= 32M
sort_buffer_size = 128M
server-id = 1 
log-slow-queries = /applog/mysqld-slow.log
long_query_time = 2
log-bin = /applog/mysql-bin


2. Create Replication user on Master Node

GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO  repl@"192.168.0.201" IDENTIFIED BY 'repl';

Verify user and grants

select host,user from user;
MASTER >show grants for repl@"192.168.0.201";
+-------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for repl@192.168.0.201                                                                                                                   |
+-------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'repl'@'192.168.0.201' IDENTIFIED BY PASSWORD '*A424E797037BF97C19A2E88CF7891C5C2038C039' |
+-------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MASTER >


3.Restart mysql

sudo /etc/init.d/mysql restart


4.Backup Master site directory.

block the tables for updates, record bin log position as root user

mysql –u root –p mysql

MASTER>FLUSH TABLES WITH READ LOCK;

record bin log position
MASTER >show master status;
+-------------------+----------+--------------+------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000021 |      107 |              |                  |
+-------------------+----------+--------------+------------------+
1 row in set (0.00 sec)


backup mysql directory

tar -cvf /backup/mysql_bkp.tar /u04/

unlock the tables

MASTER >UNLOCK TABLES;


transfer mysql_bkp.tar backup from master to slave node

scp mysql_bkp.tar mysql@192.168.0.201:/tmp/.


SLAVE Node:

1. Stop mysql

sudo /etc/init.d/mysql stop

2. delete old mysql files
$rm –rf mysql
$tar xvf mysql_bkp.tar

3.Remove  bin log files and bin log index files
$cd /u04/mysql/data
$rm db1-bin.*

4.Add below entry on my.cnf file

server-id = 2

5.start mysql

sudo /etc/init.d/mysql start

6.Issue below statement to add master

CHANGE MASTER TO  MASTER_HOST='192.168.0.109',  MASTER_USER='repl',  MASTER_PASSWORD='repl', MASTER_LOG_FILE='master-bin.000021', MASTER_LOG_POS=107;


7. Start slave

mysql> start slave;


*Check Master staus

mysql>SHOW MASTER STATUS \G
mysql>SHOW MASTER LOGS;

*Check Slave Status

mysql> SHOW SLAVE STATUS \G
If we will see below status means slave is running fine

Slave_IO_Running: Yes
Slave_SQL_Running: Yes,


Test:

create table emp (name char(10),age integer(2));
insert into emp(name,age) values('Tommy',20);


MASTER >use test;
Database changed
MASTER >create table emp (name char(10),age integer(2));
Query OK, 0 rows affected (0.27 sec)

MASTER >insert into emp(name,age) values('Tommy',20);
Query OK, 1 row affected (0.01 sec)

MASTER >

Verify on Slave site

SLAVE >use test;
Database changed
SLAVE >show tables;
+----------------+
| Tables_in_test |
+----------------+
| customers      |
| emp            |
+----------------+
2 rows in set (0.00 sec)

SLAVE >select * from emp;
+-------+------+
| name  | age  |
+-------+------+
| Tommy |   20 |
+-------+------+
1 row in set (0.00 sec)



Notes:

Using MySQL 5.0 and back
SHOW VARIABLES LIKE 'Slave_running';

Using MySQL 5.1+/5.5
select COUNT(1) SlaveThreads
from information_schema.processlist
where user = 'system user';


show slave status;

How To Repair MySQL Replication

SHOW SLAVE STATUS \G

STOP SLAVE;

 simply skip the invalid SQL query:

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;

 If you'd like to skip two queries, you'd use SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 2; instead and so on.



mysql> START SLAVE;

Check Slave status

mysql> SHOW SLAVE STATUS \G

mysql> SHOW SLAVE STATUS \G

Tuesday, March 12, 2013

How to enable SSL on MYSQL?

Verify SSL status:

MASTER >show variables like "%ssl%";
+---------------+-----------------------------------+
| Variable_name | Value                             |
+---------------+-----------------------------------+
| have_openssl  | DISABLED                          |
| have_ssl      | DISABLED                          |
| ssl_ca        |                                   |
| ssl_capath    |                                   |
| ssl_cert      |                                   |
| ssl_cipher    |                                   |
| ssl_key       |                                   |
+---------------+-----------------------------------+

Disabled means --> mysql has ssl support but it's not enabled.

NO means --> don't have ssl support.



Create SSL Certificate:

cd /home/mysql/certs
openssl genrsa -out ca-key.pem 2048;
openssl req -new -x509 -nodes -days 3 -key ca-key.pem -out ca-cert.pem;
openssl req -newkey rsa:2048 -days 3 -nodes -keyout server-key.pem -out server-req.pem;
openssl x509 -req -in server-req.pem -days 3 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem;
openssl req -newkey rsa:2048 -days 3 -nodes -keyout client-key.pem -out client-req.pem;
openssl x509 -req -in client-req.pem -days 3 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem;


Add configuration:

Add below configuration in /etc/my.cnf


[mysqld]

ssl
ssl-cipher=DHE-RSA-AES256-SHA
ssl-ca=/home/mysql/certs/ca-cert.pem
ssl-cert=/home/mysql/certs/server-cert.pem
ssl-key=/home/mysql/certs/server-key.pem


[client]
ssl-ca=/home/mysql/certs/ca-cert.pem
ssl-cert=/home/mysql/certs/client-cert.pem
ssl-key=/home/mysql/certs/client-key.pem



Restart mysql:

sudo /etc/init.d/mysql restart

Test SSL :

MASTER >show variables like "%ssl%";
+---------------+-----------------------------------+
| Variable_name | Value                             |
+---------------+-----------------------------------+
| have_openssl  | YES                               |
| have_ssl      | YES                               |
| ssl_ca        | /home/mysql/certs/ca-cert.pem     |
| ssl_capath    |                                   |
| ssl_cert      | /home/mysql/certs/server-cert.pem |
| ssl_cipher    | DHE-RSA-AES256-SHA                |
| ssl_key       | /home/mysql/certs/server-key.pem  |
+---------------+-----------------------------------+



How to check ssl certificate validation?

$ openssl x509 -noout -in server-cert.pem -dates
notBefore=Mar 12 15:36:27 2013 GMT
notAfter=Mar 15 15:36:27 2013 GMT
 

$ openssl x509 -noout -in client-cert.pem  -dates
notBefore=Mar 12 15:36:52 2013 GMT
notAfter=Mar 15 15:36:52 2013 GMT




ERROR 2026 (HY000): SSL connection error: ASN: after date in the past

ssl certificate might be expired




Enable Auditing Mysql:

MASTER >show variables like '%audit%';
Empty set (0.00 sec)

MASTER >install plugin audit_log soname 'audit_log.so';
Query OK, 0 rows affected (0.23 sec)

MASTER >show variables like '%audit%';
+--------------------------+--------------+
| Variable_name            | Value        |
+--------------------------+--------------+
| audit_log_buffer_size    | 1048576      |
| audit_log_file           | audit.log    |
| audit_log_flush          | OFF          |
| audit_log_policy         | ALL          |
| audit_log_rotate_on_size | 0            |
| audit_log_strategy       | ASYNCHRONOUS |
+--------------------------+--------------+
6 rows in set (0.00 sec)



Mysql Monitor Agent Starting Issue:

Verify Agent Logfile.

2013-07-10 12:55:14: (critical) [unix:/var/lib/mysql/mysql.sock] the hostid from `mysql`.inventory doesn't match our agent's host-id (ssh:{9d:d3:97:9f:1f:3e:cc:c4:cf:a6:63:00:9f:08:2a:04} != ssh:{80:c0:99:c4:fc:6d:d4:eb:ed:70:80:07:cb:df:3b:ec}). Shutting down
2013-07-10 12:55:14: (critical) agent_mysqld.c:1349: agent_mysqld.c:1127: operation canceled as we are shutting down
2013-07-10 12:55:14: (critical) last message repeated 37 times
2013-07-10 12:55:14: (critical) job_collect_mysql.c:428: [unix:/var/lib/mysql/mysql.sock] executing 'SHOW /*!50000 ENGINE */ INNODB STATUS' failed:  (0)
2013-07-10 12:55:14: (critical) agent_mysqld.c:1349: agent_mysqld.c:1127: operation canceled as we are shutting down


Workaround :

Truncate truncate mysql.inventory table then start agent