19 Mart 2014 Çarşamba

Mysql database cluster and Nginx web server high availability and scalability part 2

Wordpress high availability and scalability part2

Nginx Kurulumu;


Nginx kurmak için Debian’nın kendi reposundan yararlanabilirsiniz fakat son stabil sürümüne erişemiyebilirsiniz.
Bu durum da ya Nginx’in kendi reposunu yada http://www.dotdeb.org/instructions/ reposunu kullanabilirsiniz ;)
Burada biz dotdeb reposunu kullandık.
#wget http://www.dotdeb.org/dotdeb.gpg
#sudo apt-key add dotdeb.gpg
#vi /etc/apt/source.list
deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all
#apt-get update
#apt-get install nginx
#apt-get install php5-fpm  php5-mysql php-pear php-apc php5-cgi php5-gd
Kurulumlar bittikten sonra , önce nginx sonra da php-fpm ayarlarını yapalım;
İlk önce nginx.conf ayarları;
#vi /etc/nginx/nginx.conf
user www-data;
worker_processes 2;
pid /var/run/nginx.pid;
events {
        worker_connections 768;
        multi_accept on;
}
http {
        ##
        # Basic Settings
        ##
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;
        server_names_hash_bucket_size 128;
        # server_name_in_redirect off;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ##
        # Logging Settings
        ##
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        ##
        # Gzip Settings
        ##
        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;
        ##
        # fs cache
        ##
#       open_file_cache max=1000 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 2;
#       open_file_cache_errors on;
        ##
        # Virtual Host Configs
        ##
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
Aşağıdaki ayarlar wp için hazırlanmıştır.
#vi /etc/nginx/sites-available/domain.net
fastcgi_cache_path /tmp/nginx_cache levels=1:2 keys_zone=WORDPRESS:128m inactive=5m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

server {
                        listen 80;
                        server_name domain.net;
                        access_log /var/log/nginx/access.log combined;
                        error_log /var/log/nginx/error.log info;
                        root /var/www/;

                        location / {
                                               index index.php;
                                               try_files $uri $uri/ /index.php?$args;
                        }

        location ~ "\.(js|ico|gif|jpg|png|css|jpeg)$" {
                                               root    /var/www/domain/;
                                               expires       1y;
                                               add_header Cache-Control public;
                                               access_log off;
                        }

                        location = /favicon.ico {
                                               log_not_found off;
                                               access_log off;
                        }
                        location = /robots.txt {
                                               allow all;
                                               log_not_found off;
                                               access_log off;
                        }

                        location ~ /\. {
                                               deny all;
                        }

                        location ~* /(?:uploads|files)/.*\.php$ {
                                               deny all;
                        }

                        set $skip_cache 0;
                        ## POST requests and urls with a query string should always go to PHP
                        if ($request_method = POST) {
                                               set $skip_cache 1;
                        }
                        if ($query_string != "") {
                                               set $skip_cache 1;
                        }

                        # Don't cache uris containing the following segments
                        if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
                                               set $skip_cache 1;
                        }

                        # Don't use the cache for logged in users or recent commenters
                        if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
                                               set $skip_cache 1;
                        }

                        location ~ .php$ {
                                               include fastcgi_params;
                                               fastcgi_pass unix:/var/run/php5-fpm.sock;

                                               fastcgi_cache_bypass $skip_cache;
                                fastcgi_no_cache $skip_cache;

                                               fastcgi_cache WORDPRESS;
                                               fastcgi_cache_valid  5m;
                        }

                        location ~ /purge(/.*) {
                            fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
                        }
}

Sembolik link oluşturmamız gerekiyor /etc/nginx/sites-enabled/ altına
#ln -s /etc/nginx/sites-available/domain.net /etc/nginx/sites-enabled/domain.net
Yaptığımız ayarlarda hata varmı test edelim.
#nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
#service restart nginx
Php ayarları ;
#vi /etc/php5/fpm/php.ini
[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]
502 bad gateway türü bir hata ile karşılaşmak istemiyorsanız , Php’nin 9000 porttan çalıştığına emin olun.
#vi /etc/php5/fpm/pool.d/www.conf
listen = /var/run/php5-fpm.sock  “dan”  listen = 127.0.0.1:9000

NFS kurulumu;
Biz nfs sunucusunu cluster controller  kurduk siz isterseniz başka bir makinaya sadece nfs kurabilirsiniz.
Nfs kurulumu ve nfs ten export edeceğmiz dizini web sunucularının /var/www dizinine bağlıyacağız ve wordpress dosyalarına 2 sunucuda erişebilecek.herhangi bir dosya değişikliğinde 2 sunucuda aynı anda dosyalar güncellenmiş olacak.
# apt-get install nfs-kernel-server nfs-common
#mkdir  -p /opt/wp
# chmod 755 wp/
#vi /etc/exports
/opt/wp                  nginx1-ip-adresi(rw,sync) nginx2-ip-adresi (rw,sync)
2 web sunucusunada gidip,
#apt-get install nfs-common
# mount -t nfs nfs-sunucu-ip:/opt/wp /var/www
Nfs sunucusunda aşağıdaki komutu yazdığınızda sunucuya bağlı olan clientları göreceksiniz.
# showmount –e
Wordpress dosyalarını indirelim ve nfs sunucuda ki paylaşıma atalım.(Nfs sunucu da read ,write ve sync izini verdiğimiz için bağlı olan web sunucularından birine de dosyalarınızı atabilirsiniz. )
#tar xvfz latest.tar.gz




Hiç yorum yok:

Yorum Gönder