Apache und MYSQL optimieren

Linux Jüngling

New Member
Hallo,

ich möchte mein Apache2 und die my.cnf für mein System und Webseiten optimieren.

System: Debian 8, i5-2310 CPU @ 2.90GHz, 8GB RAM
Webseiten auf dem Server: 4. Insgesamt ca. 10.000 unique visitors täglich.

my.cnf:

Code:
[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size         = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size   = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem


MySQLTuner:

Code:
 >>  MySQLTuner 1.7.0 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials from debian maintenance account.
[OK] Currently running supported MySQL version 5.7.16
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA
[--] Data in MEMORY tables: 808K (Tables: 2)
[--] Data in MyISAM tables: 2G (Tables: 262)
[--] Data in InnoDB tables: 2M (Tables: 79)
[OK] Total fragmented tables: 0

-------- Security Recommendations ------------------------------------------------------------------
[OK] There are no anonymous accounts for any database users
[OK] All database users have passwords assigned
[--] There are 612 basic passwords in the list.

-------- CVE Security Recommendations --------------------------------------------------------------
[OK] NO SECURITY CVE FOUND FOR YOUR VERSION

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 3d 7h 6m 12s (17M q [60.007 qps], 1M conn, TX: 931G, RX: 4G)
[--] Reads / Writes: 92% / 8%
[--] Binary logging is disabled
[--] Physical Memory     : 7.7G
[--] Max MySQL memory    : 723.2M
[--] Other process memory: 870.2M
[--] Total buffers: 192.0M global + 1.1M per thread (500 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 205.8M (2.60% of installed RAM)
[OK] Maximum possible memory usage: 723.2M (9.13% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/17M)
[OK] Highest usage of available connections: 2% (13/500)
[OK] Aborted connections: 0.00%  (0/1539516)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[OK] Query cache is disabled by default due to mutex contention on multiprocessor machines.
[OK] Sorts requiring temporary tables: 0% (2K temp sorts / 1M sorts)
[!!] Joins performed without indexes: 149548
[OK] Temporary tables created on disk: 3% (10K on disk / 333K total)
[OK] Thread cache hit rate: 99% (358 created / 1M connections)
[!!] Table cache hit rate: 6% (2K open / 29K opened)
[OK] Open file limit used: 24% (1K/5K)
[OK] Table locks acquired immediately: 99% (20M immediate / 20M locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[OK] Key buffer used: 100.0% (16M used / 16M cache)
[OK] Key buffer size / total MyISAM indexes: 16.0M/607.8M
[OK] Read Key buffer hit rate: 99.4% (742M cached / 4M reads)
[!!] Write Key buffer hit rate: 40.2% (1M cached / 605K writes)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[OK] InnoDB buffer pool / data size: 128.0M/2.2M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (37.5 %): 48.0M/128.0M should be equal 25%
[OK] InnoDB buffer pool instances: 1
[--] Number of InnoDB Buffer Pool Chunk : 1 for 1 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.99% (5775503 hits/ 5776132 total)
[!!] InnoDB Write Log efficiency: 117.11% (30971 hits/ 26447 total)
[OK] InnoDB log waits: 0.00% (0 waits / 57418 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.

-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.

-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    Adjust your join queries to always utilize indexes
    Increase table_open_cache gradually to avoid file descriptor limits
    Read this before increasing table_open_cache over 64: http://bit.ly/1mi7c4C
    Beware that open_files_limit (5000) variable
    should be greater than table_open_cache (2000)
Variables to adjust:
    join_buffer_size (> 256.0K, or always use indexes with joins)
    table_open_cache (> 2000)
    innodb_log_file_size should be equals to 1/4 of buffer pool size (=32M) if possible.


mpm_prefork.conf:

Code:
<IfModule mpm_prefork_module>
    StartServers             25
    MinSpareServers          25
    MaxSpareServers          50
    MaxRequestWorkers       250
    MaxConnectionsPerChild 1000
</IfModule>

Kann mir jemand Tipps geben welche Werte ich hinzufügen oder hochschrauben kann?

LG
 
Ohne zu wissen, welche Webanwendungen da auf welcher Basis laufen (PHP usw.), ist das ein ziemlicher Tipp ins Blaue. Erzähl mal etwas mehr über Deine Konfiguration.
 
mach mal mysql so:

Code:
key_buffer_size         = 32M
max_allowed_packet      = 32M
thread_stack            = 1M
max_connections        = 500
table_cache            = 5000
table_definition_cache = 5000
join_buffer_size = 4M
open_files_limit = 64000
max_heap_table_size = 64M
tmp_table_size = 64M

Ich bezweifle mal das deine Webseiten mit php-cli interpretiert werden.

Apache erstmal so (hier auch nur die geänderten Variablen):

Code:
<IfModule mpm_prefork_module>
    ServerLimit                  5000
    MaxRequestWorkers       5000
    MaxConnectionsPerChild 10000
</IfModule>

Falls deine Seiten per fastcgi kommen sind die FcgidMaxProcesses interessant in der /etc/apache2/mods-enabled/fcgid.conf einfach mal auf 1000 oder so stellen.

Genaueres kann man nur live sagen wenn man ein wenig Gefühl für die Dienste hat..
 
mach mal mysql so:

Habe ich gemacht, aber "table_cache = 5000" musste ich auskommentieren, da MySQL nicht mehr gestartet werden kann wenn das aktiv ist.

Apache habe ich jetzt so:

Code:
<IfModule mpm_prefork_module>
    Serverlimit             5000
    StartServers              25
    MinSpareServers           25
    MaxSpareServers           50
    MaxRequestWorkers       5000
    MaxConnectionsPerChild 10000
</IfModule>
 
MySQL
Code:
myisam-recover-options          = FORCE,BACKUP
open_files_limit                = 32768
table_open_cache                = 8192
table_definition_cache          = 4096
max_allowed_packet              = 64M
key_buffer_size                 = 256M
myisam_sort_buffer_size         = 16M
bulk_insert_buffer_size         = 64M
join_buffer_size                = 512K
sort_buffer_size                = 4M
read_buffer_size                = 256K
read_rnd_buffer_size            = 512K
max_heap_table_size             = 256M
tmp_table_size                  = 256M
query_cache_type                = 0
query_cache_size                = 0
long_query_time                 = 0.5

Apache
Code:
<IfModule mpm_prefork_module>
    StartServers             16
    MinSpareServers          32
    MaxSpareServers          64
    MaxRequestWorkers       256
    MaxConnectionsPerChild 5000
</IfModule>
 
ServerLimit > 256 ist Sinnfrei, da ein Maximum von 256 hardcoded ist.

https://httpd.apache.org/docs/2.4/de/mod/mpm_common.html#serverlimit

Afaik sinds 20000, so wie auch dort beschrieben. Wie es bei Freebsd ist wirst du besser wissen..

Edit: "For non-threaded servers (i.e., prefork), MaxRequestWorkers translates into the maximum number of child processes that will be launched to serve requests. The default value is 256; to increase it, you must also raise ServerLimit."
Glaube Joe war noch nicht ganz wach und hat da was verwechselt..
 
Last edited by a moderator:
Ich bin ja kein Programmierer, aber der Code sagt meinem Verständnis nach etwas Anderes, nämlich, dass das ServerLimit effektiv bei 256 liegt (ausser man konfiguriert > 200k):
Code:
[root@devnoip:~] # egrep -in --color '(DEFAULT|MAX)_SERVER_LIMIT' httpd-2.4.23/server/mpm/prefork/prefork.c
74:#ifndef DEFAULT_SERVER_LIMIT
75:#define DEFAULT_SERVER_LIMIT 256
78:/* Admin can't tune ServerLimit beyond MAX_SERVER_LIMIT.  We want
81:#ifndef MAX_SERVER_LIMIT
82:#define MAX_SERVER_LIMIT 200000
1392:    server_limit = DEFAULT_SERVER_LIMIT;
1409:    if (server_limit > MAX_SERVER_LIMIT) {
1414:                         server_limit, MAX_SERVER_LIMIT, MAX_SERVER_LIMIT);
1419:                         server_limit, MAX_SERVER_LIMIT);
1421:        server_limit = MAX_SERVER_LIMIT;
[root@devnoip:~] # sed -n '1388,1510 p' httpd-2.4.23/server/mpm/prefork/prefork.c
    ap_listen_pre_config();
    ap_daemons_to_start = DEFAULT_START_DAEMON;
    ap_daemons_min_free = DEFAULT_MIN_FREE_DAEMON;
    ap_daemons_max_free = DEFAULT_MAX_FREE_DAEMON;
    server_limit = DEFAULT_SERVER_LIMIT;
    ap_daemons_limit = server_limit;
    ap_extended_status = 0;

    return OK;
}

static int prefork_check_config(apr_pool_t *p, apr_pool_t *plog,
                                apr_pool_t *ptemp, server_rec *s)
{
    int startup = 0;

    /* the reverse of pre_config, we want this only the first time around */
    if (retained->module_loads == 1) {
        startup = 1;
    }

    if (server_limit > MAX_SERVER_LIMIT) {
        if (startup) {
            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00175)
                         "WARNING: ServerLimit of %d exceeds compile-time "
                         "limit of %d servers, decreasing to %d.",
                         server_limit, MAX_SERVER_LIMIT, MAX_SERVER_LIMIT);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(00176)
                         "ServerLimit of %d exceeds compile-time limit "
                         "of %d, decreasing to match",
                         server_limit, MAX_SERVER_LIMIT);
        }
        server_limit = MAX_SERVER_LIMIT;
    }
    else if (server_limit < 1) {
        if (startup) {
            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00177)
                         "WARNING: ServerLimit of %d not allowed, "
                         "increasing to 1.", server_limit);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(00178)
                         "ServerLimit of %d not allowed, increasing to 1",
                         server_limit);
        }
        server_limit = 1;
    }

    /* you cannot change ServerLimit across a restart; ignore
     * any such attempts
     */
    if (!retained->first_server_limit) {
        retained->first_server_limit = server_limit;
    }
    else if (server_limit != retained->first_server_limit) {
        /* don't need a startup console version here */
        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(00179)
                     "changing ServerLimit to %d from original value of %d "
                     "not allowed during restart",
                     server_limit, retained->first_server_limit);
        server_limit = retained->first_server_limit;
    }

    if (ap_daemons_limit > server_limit) {
        if (startup) {
            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00180)
                         "WARNING: MaxRequestWorkers of %d exceeds ServerLimit "
                         "value of %d servers, decreasing MaxRequestWorkers to %d. "
                         "To increase, please see the ServerLimit directive.",
                         ap_daemons_limit, server_limit, server_limit);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(00181)
                         "MaxRequestWorkers of %d exceeds ServerLimit value "
                         "of %d, decreasing to match",
                         ap_daemons_limit, server_limit);
        }
        ap_daemons_limit = server_limit;
    }
    else if (ap_daemons_limit < 1) {
        if (startup) {
            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00182)
                         "WARNING: MaxRequestWorkers of %d not allowed, "
                         "increasing to 1.", ap_daemons_limit);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(00183)
                         "MaxRequestWorkers of %d not allowed, increasing to 1",
                         ap_daemons_limit);
        }
        ap_daemons_limit = 1;
    }

    /* ap_daemons_to_start > ap_daemons_limit checked in prefork_run() */
    if (ap_daemons_to_start < 1) {
        if (startup) {
            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00184)
                         "WARNING: StartServers of %d not allowed, "
                         "increasing to 1.", ap_daemons_to_start);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(00185)
                         "StartServers of %d not allowed, increasing to 1",
                         ap_daemons_to_start);
        }
        ap_daemons_to_start = 1;
    }

    if (ap_daemons_min_free < 1) {
        if (startup) {
            ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, APLOGNO(00186)
                         "WARNING: MinSpareServers of %d not allowed, "
                         "increasing to 1 to avoid almost certain server failure. "
                         "Please read the documentation.", ap_daemons_min_free);
        } else {
            ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, APLOGNO(00187)
                         "MinSpareServers of %d not allowed, increasing to 1",
                         ap_daemons_min_free);
        }
        ap_daemons_min_free = 1;
    }

    /* ap_daemons_max_free < ap_daemons_min_free + 1 checked in prefork_run() */

    return OK;
}
Was habe ich übersehen?
 
Soweit ich sehe DEFAULT_SERVER_LIMIT (256) wenn nichts gesetzt ist.. und MAX_SERVER_LIMIT (200000) wenn was gesetzt ist..
 
MaxRequestWorkers 256
Code:
-- Unit apache2.service has begun starting up.
Nov 13 16:32:07 xxx apache2[11761]: Starting web server: apache2.
Nov 13 16:32:07 xxx systemd[1]: Started LSB: Apache2 web server.
-- Subject: Unit apache2.service has finished start-up

MaxRequestWorkers 257
Code:
Nov 13 16:29:59 xxx apache2[11595]: Starting web server: apache2AH00180: WARNING: MaxRequestWorkers of 257 exceeds ServerLimit value of
Nov 13 16:29:59 xxx apache2[11595]: 256 servers, decreasing MaxRequestWorkers to 256.
Nov 13 16:29:59 xxx apache2[11595]: To increase, please see the ServerLimit directive.
Nov 13 16:30:00 xxx apache2[11595]: .
Nov 13 16:30:00 xxx systemd[1]: Started LSB: Apache2 web server.

ServerLimit 257
MaxRequestWorkers 257
Code:
-- Unit apache2.service has begun starting up.
Nov 13 16:31:18 xxx apache2[11680]: Starting web server: apache2.
Nov 13 16:31:18 xxx systemd[1]: Started LSB: Apache2 web server.
-- Subject: Unit apache2.service has finished start-up

Wäre dann ja alles blödsinn was der Indianer da spricht ;)
 
Ohne Patches?
Was habe ich denn im Code übersehen?
Ich möchte es gerne verstehen wo mein (Denk)Fehler liegt, danke.
 
Also soweit ich sehe kommen die Einstellungen an. Zumindest zeigt mod-info diese auch an:

Code:
Module Name: prefork.c
Content handlers: none
Configuration Phase Participation: none
Request Phase Participation: none
Module Directives:
    ListenBacklog - Maximum length of the queue of pending connections, as used by listen(2)
    Listen - A port number or a numeric IP address and a port number, and an optional protocol
    SendBufferSize - Send buffer size in bytes
    ReceiveBufferSize - Receive buffer size in bytes
    StartServers - Number of child processes launched at server startup
    MinSpareServers - Minimum number of idle children, to handle request spikes
    MaxSpareServers - Maximum number of idle children
    MaxClients - Deprecated name of MaxRequestWorkers
    MaxRequestWorkers - Maximum number of children alive at the same time
    ServerLimit - Maximum value of MaxRequestWorkers for this run of Apache
    GracefulShutdownTimeout - Maximum time in seconds to wait for child processes to complete transactions during shutdown
Current Configuration:
    In file: /etc/apache2/mods-enabled/mpm_prefork.conf
       9: StartServers 5
      10: MinSpareServers 5
      11: MaxSpareServers 10
      12: ServerLimit 1000
      13: MaxRequestWorkers 1000

Weiß jetzt nicht genau wie mod-info das ausliest.. Aber so wie du es sagst würde es doch jede Konfiguration > 256 ignorieren.. Was ich mir nun wirklich nicht vorstellen kann.. Bauen da extra Hinweise ein wenn MaxRequestWorkers > 256 und ServerLimit nicht gesetzt und dann soll es nicht tun.. Ich kann mir nur vorstellen das du den Code an der Stelle nicht richtig verstehst oder irgendeine Variablen Geschichte übersehen hast. Die Fehlermeldungen wären längst weg gepatched worden oder zumindest wäre es dokumentiert das es nur bis 256 geht..
 
Last edited by a moderator:
Back
Top