Hallo EPVP,
da es für einen Server essentiell ist eine schnelle und ausfallsichere Homepage zu besitzen sollte bekannt sein, aber was tun wenn man mit ausfällen und hoher CPU/Memory Auslastung zu kämpfen hat?
Man sollte sich mal Gedanken machen welche Software man einsetzt, hier mal eine kleine Auflistung verschiedener WebServer.
Apache 2
Nginx (Engine X)
Lighttpd
Alle diese Server haben ihre Schwächen und Stärken, zu den Stärken meines Favoriten Nginx (Engine X ausgesprochen) gehören unteranderem die geringe CPU und RAM Auslastung und die Geschwindigkeit aufgrund Event basierter Programmierung.
Nun zum eigentlichen Tutorial:
Was wird benötigt:
Debian 6 oder 7
Zeit + Geduld + Verständnis für die meisten Befehle
Grundkentnisse in Linux Umgebungen
Tipps:
In nano lässt sich mit STRG+W nach einem Begriff suchen STRG+O speichert das Dokument und STRG+X schließt den Editor.
Schritt 1 Vorbereitungen für die NGINX Installation:
Führt bitte die folgenden Befehle aus um die neuste Version von NGINX auf euer System zu bringen.
Als erstes müsst ihr eine neue Paketquelle zu Debian hinzufügen um NGINX von der Offiziellen REPO zu beziehen.
DEBIAN 6+7 beziehen des Signing Key´s
Code:
cd /tmp/
wget http://nginx.org/keys/nginx_signing.key
apt-key add /tmp/nginx_signing.key
Debian7 hinzufügen der Repo:
Code:
echo "deb http://nginx.org/packages/debian/ wheezy nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/debian/ wheezy nginx" >> /etc/apt/sources.list
Debian6 hinzufügen der Repo:
Code:
echo "deb http://nginx.org/packages/debian/ squeeze nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/debian/ squeeze nginx" >> /etc/apt/sources.list
Jetzt noch ein
und die neuste Version von Nginx steht zur Verfügung.
Schritt2 Installieren von Nginx:
Ein einfacher Befehl reicht für diesen Schritt.
Code:
apt-get install nginx
Jetzt erstellen wir noch einen neuen Ordner unter /var/www und geben nginx die Rechte mit diesem zu Arbeiten:
Code:
mkdir -p /var/www/
chown nginx:nginx /var/www/
chmod -R 775 /var/www
Schritt 3 Konfigurieren von Nginx nach der Installation ACHTUNG ALLE CONFIGS WURDEN MIT NGINX-Version 1.4.2 unter Debian7 getestet:
Die Nginx Dateien befinden sich in /etc/nginx, hier werden wir jetzt auch die ersten Änderungen vornehmen.
Bearbeiten der /etc/nginx/nginx.conf
Code:
nano /etc/nginx/nginx.conf
Folgende Einstellungen werden hier angepasst:
Code:
worker_processes NUMMER_DER_CPU_KERNE;
UNTER EVENTS:
worker_connections 2048;
UNTER HTTP:
port_in_redirect off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
index index.html index.htm index.php;
Folgende Einstellungen werden aktiviert oder hinzugefügt (# vorm Befehl entfernen)
Code:
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Folgende Einstellungen werden auskommentiert(# vor den Befehl) sofern nicht schon deaktiviert:
Code:
access_log
error_log
Bearbeiten der /etc/nginx/conf.d/default.conf
Code:
nano /etc/nginx/conf.d/default.conf
[BEISPIEL CONFIG FÜR IPV4+6 ]
Code:
#STANDARD Server FueR ALLE REQUESTS DIE NICHT ZUGEORDNET SIND
server {
root /var/www/null; # Bitte aendern hier landen alle Anfragen die nicht definiert sind
listen 8080;
listen [::]:8080 ipv6only=on default_server;
}
server {
## EURE DOMAINS HIER.
server_name example.com; # Bitte ändern
listen 8080;
listen [::]:8080;
root /var/www/EUER_UNTERORDNER/; # Bitte aendern
location ~ \.php$ {
try_files $uri =404;
fastcgi_buffers 8 256k;
fastcgi_buffer_size 128k;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
}
Schritt 4 Installation von php5-fpm und php Erweiterungen
Code:
apt-get install php5-fpm php-pear php5-common php5-mysql php-apc php5-gd php5-curl php5-mcrypt
Schritt 4.1 Bearbeiten der Konfiguration von php-fpm
Die Dateien liegen unter /etc/php5/fpm/
Bearbeiten der /etc/php5/fpm/php.ini
Code:
nano /etc/php5/fpm/php.ini
Bitte ganz am Ende folgendes einfügen:
Code:
[apc]
apc.write_lock = 1
apc.slam_defense = 0
Bearbeiten der /etc/php5/fpm/pool.d/www.conf
Code:
nano /etc/php5/fpm/pool.d/www.conf
Ersetzt
Code:
listen = 127.0.0.1:9000
mit
Code:
listen = /dev/shm/php-fpm-www.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
und
Code:
user = www-data
group = www-data
mit
Code:
user = nginx
group = nginx
Schritt 5 Varnish installieren:
Code:
apt-get install varnish
Schritt 5.1 Varnish Konfigurieren:
Die Dateien liegen in /etc/varnish
Bearbeiten der /etc/varnish/default.vcl
Code:
nano /etc/varnish/default.vcl
[BEISPIEL KONFIG FÜR WORDPRESS]
Code:
# This is a basic VCL configuration file for varnish. See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
.max_connections = 800;
}
acl purge {
"localhost";
}
sub vcl_recv {
set req.grace = 2m;
# Set X-Forwarded-For header for logging in nginx
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;
# Remove has_js and CloudFlare/Google Analytics __* cookies.
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
# Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
# Either the admin pages or the login
if (req.url ~ "/wp-(login|admin|cron)") {
# Don't cache, pass to backend
return (pass);
}
# Remove the wp-settings-1 cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", "");
# Remove the wp-settings-time-1 cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", "");
# Remove the wp test cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", "");
# Static content unique to the theme can be cached (so no user uploaded images)
# The reason I don't take the wp-content/uploads is because of cache size on bigger blogs
# that would fill up with all those files getting pushed into cache
if (req.url ~ "wp-content/themes/" && req.url ~ "\.(css|js|png|gif|jp(e)?g)") {
unset req.http.cookie;
}
# Even if no cookies are present, I don't want my "uploads" to be cached due to their potential size
if (req.url ~ "/wp-content/uploads/") {
return (pass);
}
# Check the cookies for wordpress-specific items
if (req.http.Cookie ~ "wordpress_" || req.http.Cookie ~ "comment_") {
# A wordpress specific cookie has been set
return (pass);
}
# allow PURGE from localhost
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return (lookup);
}
# Force lookup if the request is a no-cache request from the client
if (req.http.Cache-Control ~ "no-cache") {
return (pass);
}
# Try a cache-lookup
return (lookup);
}
sub vcl_fetch {
#set obj.grace = 5m;
set beresp.grace = 2m;
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
Bearbeiten der /etc/default/varnish Konfigurationsdatei:
Code:
nano /etc/default/varnish
Ändert den folgenden Abschnitt:
Code:
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
zu
Code:
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
Schritt 6 alles neustarten und sichergehen das alles funktioniert.
Code:
service php5-fpm restart
service nginx restart
service varnish restart
Schritt 7 Mysql:
Code:
apt-get install mysql-server
ausführen und den Anweisungen folgen.
Das wars.
Schritt 8 PHPmyadmin installieren:
Folgende Befehle ausführen:
Code:
wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.0.4.1/phpMyAdmin-4.0.4.1-all-languages.tar.gz
tar -xvf phpMyAdmin-4.0.4.1-all-languages.tar.gz
mv phpMyAdmin-4.0.4.1-all-languages /usr/share/phpmyadmin
Jetzt erstellen wir die /usr/share/phpmyadmin/config.inc.php
Code:
nano /usr/share/phpmyadmin/config.inc.php
und fügen folgendes ein:
PHP Code:
<?php
/**
* phpMyAdmin sample configuration, you can use it as base for
* manual configuration. For easier setup you can use setup/
*
* All directives are explained in documentation in the doc/ folder
* or at <http://docs.phpmyadmin.net/>.
*
* @package PhpMyAdmin
*/
/*
* This is needed for cookie based authentication to encrypt password in
* cookie
*/
$cfg['blowfish_secret'] = 'asfd12312l123#-y-#-+##-+#-#-23423'; # please change required for cookie auth
/*
* Servers configuration
*/
$i = 0;
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Servers'][$i]['hide_db'] = 'information_schema';
/*
* phpMyAdmin configuration storage settings.
*/
/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = 'localhost';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'yourpassword'; # please change
/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma__designer_coords';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
?>
Bitte alle Felder bearbeiten die mit #please change gekennzeichnet sind
Jetzt erstellen wir noch die Datenbank für phpmyadmin und den controluser.
Code:
mysql -u root -p
Create Database phpmyadmin;
Use phpmyadmin;
source /usr/share/phpmyadmin/examples/create_tables.sql;
BITTE yourpassword mit eurem sicheren Passwort ersetzen, das ihr in der Config angegeben habt.
Code:
GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT SELECT (
Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv,
File_priv, Grant_priv, References_priv, Index_priv, Alter_priv,
Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv,
Execute_priv, Repl_slave_priv, Repl_client_priv
) ON mysql.user TO 'pma'@'localhost';
GRANT SELECT ON mysql.db TO 'pma'@'localhost';
GRANT SELECT ON mysql.host TO 'pma'@'localhost';
GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv)
ON mysql.tables_priv TO 'pma'@'localhost';
GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost';
Ich wünsche euch viel Spaß mit dem Endprodukt dieses Tutorials sollte es Fragen und Probleme geben meldet euch bitte.