The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Apache using up too much CPU.

Discussion in 'Workarounds and Optimization' started by desiguru, Nov 2, 2010.

  1. desiguru

    desiguru Well-Known Member

    Joined:
    Aug 27, 2008
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Hey guys,

    I have some major problem with my server. Up until last week, it was working really good but lately I have to wake up in the middle of the night to restart the server.

    I have tried tweaking a lot of things but not sure where to go now. I'm assuming the real problem is in mySQL but not sure what configuration I should put.

    Can someone please post/guide me on how to tweak Apache and MySQL please. Many thanks.
     
  2. GaryT

    GaryT Well-Known Member

    Joined:
    May 19, 2010
    Messages:
    321
    Likes Received:
    3
    Trophy Points:
    16
    On the time it goes bad you should check the connections to the apache, It could be possible that you may be under a Dos attack which can crash the server.

    Check apache error logs:

    Check apache connections:

    Check All connections:

    Go through your apache log and check whats gone on at the time of the server crash.

    For more help you should post the stats of your machine, Followed by your my.cnf so people can have a better idea on helping you tweek such things.

    It could be possible that your running out of memory or such, Infact it could be hundreds of things its just the matter of finding it.
     
  3. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    You could see what's happening on the machine before it has to be restarted by logging the processes and memory details using sys-snap.sh script. This is a light weight script that pulls details and logs them each minute. It can then be used when the server reboots to see the last logs information for the 5-10 minutes before it rebooted.

    To grab and run the script, you could use the following commands:

    Code:
    cd /
    wget http://sys-snap.techfiles.us/
    chmod +x sys-snap.sh
    nohup ./sys-snap.sh &
    At that point, ctrl+c after it starts, and it will start logging to system-snapshot folder location for log files every minute. When the server reboots, it will stop logging as the script will not restart on boot (you can always run the "nohup ./sys-snap.sh &" command again at any point after the reboot to start the logging again).
     
  4. desiguru

    desiguru Well-Known Member

    Joined:
    Aug 27, 2008
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    Thank you for your suggestions. Here are my initial results

    Code:
    netstat -nt | grep :80 | wc -l
    877 (This was initially 1300+ but after finding 200 connections open from a single IP I had to block it and thet brought down the number a lot))
    
    Also this thing is always using my CPU a lot how can I fix it?

    /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --log-error=/etc/httpd/logs/mysqld.err --pid-file=/var/lib/mysql/server.domainname.com.pid

    Here is my my.cnf values

    Code:
    [mysqld]
    max_allowed_packet=100M
    set-variable = max_connections=600
    safe-show-database
    # Connection timeout
    connect_timeout                   = 20
    
    # Timeout for inactive connections
    wait_timeout                      = 60
    
    # Network buffer length (I think this is the linux default)
    net_buffer_length                 = 16K
    log-error                         = /etc/httpd/logs/mysqld.err
    binlog_cache_size                 = 2M
    table_cache                       = 6588
    join_buffer_size                  = 320M
    tmp_table_size                    = 512M
    sort_buffer_size                  = 128M
    thread_cache_size                 = 6
    max_heap_table_size               = 320M
    query_cache_size                  = 312M
    key_buffer_size                   = 128M
    [client]
    socket=/var/lib/mysql/mysql.sock
    
     
Loading...

Share This Page