Warning: mysql_connect() [function.mysql-connect]:
I’ve had a problem of this kind too. I will start from the beginning and I don’t want to understate you.
In cases like this you have to follow the start of the problem. The slow loading of a website in combination with the above means you have slow queries and your mysql server just can’t handle. The apache service starts to overload the server. I hope you have a root access so you can do this:
Open the config file which is placed in /etc/my.cnf Add the following lines (this will save all the queries to the database which need longer than 5 seconds to execute)
Код:
log-slow-queries = /var/log/mysql-slow.log
long_query_time = 5
2. Add this into the file - max_connections=300 (this will make the limit for max connections to the base more liberal – from the default value of 100 to 300. This will help you find the problem.
3. Now you have to create the following file with the touch command- touch /var/log/mysql-slow.log Give him rights to write on the server - chmod 755 /var/log/mysql-slow.log
4. Restart mysqld with /etc/init.d/mysqld restart
5. With the help of phpmyadmin optimize every table in your data bases. It is really possible that a broken table causes the slow queries.
6. Now you have to just sit back and wait for something to pop in the log above.
Consider that the limit we’ve upped above will make the server use more ram for the mysqld
If you are using a shared server, most of the services are letting users to use custom config file for mysql. Well, you can’t log the information there but you can get the parameter from step two running on the server by putting the file in /home/caprice/public_html/
Again, if you have root access to the server and if you don’t want to watch the terminal all day, you can use the script below, which will send you mail notifications when the server is overloaded. Here are the steps for using it.
1. Create a file /home/caprice/restart.sh, which contains something like this:
Код:
#!/bin/sh
check=`cat /proc/loadavg | sed 's/\./ /' | awk '{print $1}'`
if [ $check -gt 8 ]
then
[email protected]
host=`hostname`
res=`top -bn 1`
/usr/sbin/sendmail -f $ADMIN -t << sendemail
To: $ADMIN
Subject: High load on [$host]
Load Average : $check
Top command :
$res
sendemail
killall httpd
killall mysqld
wait 10
/etc/init.d/httpd restart
/etc/init.d/mysqld restart
fi
The script checks the load level of the server and if the value is above 8, you will get an e-mail. After that it stops all the mysqld and apache processes, waits 10 seconds for the load to get back in normal state and turns everything on again. If you want to just get an e-mail, without the restart module of the service, the script looks like this:
Код:
#!/bin/sh
check=`cat /proc/loadavg | sed 's/\./ /' | awk '{print $1}'`
if [ $check -gt 8 ]
then
[email protected]
host=`hostname`
res=`top -bn 1`
/usr/sbin/sendmail -f $ADMIN -t << sendemail
To: $ADMIN
Subject: High load on [$host]
Load Average : $check
Top command :
$res
sendemail
fi
2. Give it rights to run chmod 744 /home/caprice/restart.sh
3. Create a file /etc/cron.d/auto_restart which has:
Код:
* * * * * root /home/caprice/restart.sh >> /dev/null 2>&1
This will start the script every minute. It will check the server loads without bothering you with notifications you don’t want to see.
4. Restart the cron demon /etc/init.d/crond restart
If you have other problems write them here or send me a message at Skype, because we will solve the problems faster.