Page 1 of 1

Error connecting to db after MySQL migration

Posted: Tue Nov 15, 2016 10:15 am
by corkyman
I have a dev Nagios environment with two Nagios XI servers -- primary and backup. Both used to have an internal MySQL db deployed. I have recently migrated MySQL db to the external db server and observing the following:
1. The primary Nagios server works just fine
2. The backup Nagios server works fine in XI portion of the GUI but when I switch to Core and when I make selections on the navigational panel on the left it takes about 2 min before it displays the information and also it displays "Error connecting to database" in the top left corner.

I verified the access manually from the backup server lie this

[c601018@vhlgnngxi072 ~]$ mysqladmin --host=10.7.123.76 --user=nagiosxi --password=n@gweb --socket=/mynagiosxi/data/mysql/mysql_nagiosxi.sock --port=3382 ping
mysqld is alive
[c601018@vhlgnngxi072 ~]$ mysqladmin --host=10.7.123.76 --user=nagiosql --password=n@gweb --socket=/mynagiosxi/data/mysql/mysql_nagiosxi.sock --port=3382 ping
mysqld is alive
[c601018@vhlgnngxi072 ~]$ mysqladmin --host=10.7.123.76 --user=ndoutils --password=n@gweb --socket=/mynagiosxi/data/mysql/mysql_nagiosxi.sock --port=3382 ping
mysqld is alive

My DBA is unsure about what is going on and asks the following:

"For now, I have just increased the number of connections from 151 to 200, I did not double it to 300
I need to understand if your passive server will have all the connections to the database?? I need to understand your existing HA.
Does the app use connection pooling and release connections as appropriate?

Also, by any chance, does the app try to connect to the database as root? I did not use your password for root, it is DBA admin account.
I changed the password for root, wondering if that is the issue since I did not find any error like “TOO MANY CONNECTIONS” in error log"

Please advise.

Re: Error connecting to db after MySQL migration

Posted: Tue Nov 15, 2016 11:07 am
by rkennedy
Could you run a tail -f /var/log/httpd/*_log for a bit, and then click around the pages? Please post this for us to look at.

Re: Error connecting to db after MySQL migration

Posted: Wed Nov 16, 2016 11:27 am
by corkyman
There is a error "Can't connect to MySQL server" in the tailed log attached. I could not paste here b/c the number of URLs exceeded 10.

Re: Error connecting to db after MySQL migration

Posted: Wed Nov 16, 2016 3:52 pm
by rkennedy
I am seeing the error pop out -

Code: Select all

Can't connect to MySQL server on '10.7.123.76' (4) in /usr/local/nagiosxi/html/includes/components/ccm/classes/Db.php on line 6
Now, with your commands you ran above it looks like you specified port 3382 - since the default is 3306 was it updated properly everywhere?

Code: Select all

grep -R '3306' cd /usr/local/nagios
grep -R '3306' cd /usr/local/nagiosxi
Does anything look like it was missing the port modification? The error doesn't point to which port, and based on what you've said it sounds like things are setup correctly.

Re: Error connecting to db after MySQL migration

Posted: Thu Nov 17, 2016 12:26 am
by corkyman
I ran the commands on primary and backup servers-- see attached files for outputs. The only interesting place is in the /usr/local/nagiosxi/etc/components/ccm_config.inc.php files. The section from both files where 3306 is specified is here:

Primary server (that works)
// Nagios Core file locations
$CFG['plugins_directory'] = '/usr/local/nagios/libexec';
$CFG['command_file'] = '/usr/local/nagios/var/rw/nagios.cmd';
$CFG['lock_file'] = '/usr/local/nagios/var/nagios.lock';

// MySQL database connection info
$CFG['db'] = array(
'server' => 'localhost',
'port' => '3306',
'database' => 'nagiosql',
'username' => 'nagiosql',
'password' => 'n@gweb'
);


Backup server (that gives an error)
// Nagios Core file locations
$CFG['plugins_directory'] = '/usr/local/nagios/libexec';
$CFG['command_file'] = '/usr/local/nagios/var/rw/nagios.cmd';
$CFG['lock_file'] = '/usr/local/nagios/var/nagios.lock';

// MySQL database connection info
$CFG["db"] = array(
"server" => "10.7.123.76",
"port" => "3306",
"database" => "nagiosql",
"username" => "nagiosql",
"password" => "n@gweb"
);

Both files are wrong: the primary's file point to localhost instead of 10.7.123.76 and both files have the wrong port 3306 instead of 3382.
But I can explain what I am observing -- the reason it works on primary server is that it points to the old db which is still not taken down. The reason it does not work on a backup server is that the port is wrong.

The question is when does this file get updated? There are no instruction to update it directly and I understand it should not be manually updated anyway.

Re: Error connecting to db after MySQL migration

Posted: Thu Nov 17, 2016 10:38 am
by rkennedy
I spoke with the developers, and the ccm_config.inc.php should be updating based off of config.inc.php. Did you enter the port in this file to reflect 3382?

Could you attach the files again for me to look at?

Re: Error connecting to db after MySQL migration

Posted: Thu Nov 17, 2016 1:04 pm
by corkyman
Is there a way to force rebuilding of this config? /usr/local/nagiosxi/html/config.inc.php is attached from both primary and backup servers.

Re: Error connecting to db after MySQL migration

Posted: Thu Nov 17, 2016 2:11 pm
by rkennedy
The config is fine, if you're going to specify a different port that is not 3306, the developers have mentioned to me that you'll want to update your offloaded IP/hostname to include the port.

So in config.inc.php,

Also, take a look at /var/www/html/nagiosql/config/settings.php - make sure you specify the custom port here as well against the port = parameter.

For example -

Code: Select all

// db-specific connection information
$cfg['db_info'] = array(
    "nagiosxi" => array(
        "dbtype" => 'mysql',
        "dbserver" => 'localhost',
        "user" => 'nagiosxi',
        "pwd" => 'n@gweb',
        "db" => 'nagiosxi',
Would become --

Code: Select all

// db-specific connection information
$cfg['db_info'] = array(
    "nagiosxi" => array(
        "dbtype" => 'mysql',
        "dbserver" => 'localhost:3382',
        "user" => 'nagiosxi',
        "pwd" => 'n@gweb',
        "db" => 'nagiosxi',

Re: Error connecting to db after MySQL migration

Posted: Thu Nov 17, 2016 3:25 pm
by corkyman
I think we were past this point with me providing the config file and determining that ports are specified everywhere.
Just to confirm again here is what I have on both Nagios servers:

-bash-4.1$ cat /var/www/html/nagiosql/config/settings.php
<?php
exit;
?>
[db]
server = 10.7.123.76
port = 3382
database = nagiosql
username = nagiosql
password = n@gweb
[common]
install = passed

-bash-4.1$ cat /usr/local/nagiosxi/html/config.inc.php | grep 3382
"dbserver" => '10.7.123.76:3382',
"dbserver" => '10.7.123.76:3382',
"dbserver" => '10.7.123.76:3382',

I think the question that was left unanswered is why the /usr/local/nagiosxi/etc/components/ccm_config.inc.php file contains the bad server/port info and how to fix/regenerate this config file. So I don't understand how you say that the config is fine.
I need to get this going as I need to solve the production performance issue by moving to the external db. Is it possible to have a shared session?
Please help.

Re: Error connecting to db after MySQL migration

Posted: Thu Nov 17, 2016 3:53 pm
by ssax
Locking, will continue support through the ticket.