mysql etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
mysql etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

9 Aralık 2014 Salı

Nginx, Django, Gunicorn & Mysql Installation and Configuration on Debian 7

Nginx, Django, Gunicorn & Mysql Installation and Configuration

Step One;
Update packages
#apt-get update
#apt-get upgrade

Step Two;
Install and create virtualenv
#apt-get install python-virtualenv python-dev
#source virtualenv /opt/myenv
Notice that a new directory "myenv" was created in the "/opt" directory. This is where our virtualenv will live. Make sure to replace "/opt/myenv" with the path to where you want your virtualenv installed. I typically put my env's in /opt, but this is strictly preference. Some people create a directory named "webapps" at the root of the VPS. Choose whatever method makes the most sense to you.

Step Three ;
Install Django
#source /opt/myenv/bin/activate
You should now see that "(myenv)" has been appended to the beginning of your terminal prompt. This will help you to know when your virtualenv is active and which virtualenv is active should you have multiple virtualenv's on the VPS.
With your virtualenv active, we can now install Django. To do this, we will use pip, a Python package manager much like easy_install. Here is the command you will run:
(myenv)root@Django:/opt/myenv/bin#pip install django
You now have Django installed in your virtualenv! Now let's get our database server going.

Step Four ;
Install Mysql Server
Since we don't need our virtualenv active for this part, run the following command to deactivate:
(myenv)root@Django:/opt/myenv/bin#deactivate
This will always deactivate whatever virtualenv is active currently. Now we need to install dependencies for Mysql to work with Django with this command:
#apt-get install python-mysqldb libmysqlclient-dev mysql-server


Step Five;
Install Nginx
#apt-get install nginx

Step Six;
Install Gunicorn
Gunicorn is a very powerful Python WSGI HTTP Server. Since it is a Python package we need to first activate our virtualenv to install it. Here is how we do that:
#source /opt/myenv/bin/activate
Make sure you see the added "myenv" at the beginning of your terminal prompt. With your virtualenv now active, run this command:
(myenv)root@Django:/opt/myenv/bin# pip install gunicorn
Gunicorn is now installed within your virtualenv.
If all you wanted was to get everything installed, feel free to stop here. Otherwise, please continue for instructions on how to configure everything to work together and make your app accessible to others on the web.
(myenv)root@Django:/opt/myenv/bin#deactivate

Step Seven;
Configure Mysql
#mysql -u root -p 
>CREATE DATABASE djangodb;
>CREATE USER 'django'@'localhost' IDENTIFIED BY 'passwd';
>GRANT ALL PRIVILEGES ON djangodb . * TO 'django'@'localhost';
>FLUSH PRIVILEGES;

Step Eight;
Create a Django project
In order to go any further we need a Django project to test with. This will allow us to see if what we are doing is working or not. Change directories into the directory of your virtualenv (in my case /opt/myenv) like so:
#cd /opt/myenv
Now make sure your virtualenv is active. If you're unsure then just run the following command to ensure you're activated:
#source /opt/myenv/bin/activate
With your virtualenv now active, run the following command to start a new Django project:
(myenv)root@Django:/opt/myenv/bin#django-admin.py startproject myproject
You should see a new directory called "myproject" inside your virtualenv directory. This is where our new Django project files live.
In order for Django to be able to talk to our database we need to install a backend for Mysql. Make sure your virtualenv is active and run the following command in order to do this:
(myenv)root@Django:/opt/myenv/bin# pip install mysql-python
Change directories into the new "myproject" directory and then into it's subdirectory which is also called "myproject" like this:
(myenv)root@Django:/opt/myenv/bin#cd /opt/myenv/myproject/myproject
Edit the settings.py file with your editor of choice:
(myenv)root@Django:/opt/myenv/myproject/myproject#nano settings.py
Find the database settings and edit them to look like this:
DATABASES = {
        'default': {
'ENGINE': 'django.db.backends.mysql', 
'NAME': 'djangodb',
'USER': 'django',
'PASSWORD': 'passwd',
'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
'PORT': '3306',
  }
}
Save and exit the file. Now move up one directory so your in your main Django project directory 
#cd /opt/myenv/myproject
Activate your virtualenv if you haven't already with the following command:
#source /opt/myenv/bin/activate
With your virtualenv active, run the following command so that Django can add it's initial configuration and other tables to your database:
(myenv)root@Django:/opt/myenv/myproject/#python manage.py syncdb
You should see some output describing what tables were installed, followed by a prompt asking if you want to create a superuser. This is optional and depends on if you will be using Django's auth system or the Django admin.

Step Nine;
Configure Gunicorn
First lets just go over running Gunicorn with default settings. Here is the command to just run default 
#gunicorn_django --bind yourdomainorip.com:8001
Be sure to replace "yourdomainorip.com" with your domain, or the IP address of your VPS if you prefer. Now go to your web browser and visit yourdomainorip.com:8001 and see what you get. You should get the Django welcome screen.
If you look closely at the output from the above command however, you will notice only one Gunicorn worker booted. What if you are launching a large-scale application on a large VPS? Have no fear! All we need to do is modify the command a bit like so:
#gunicorn_django --workers=3 --bind yourdomainorip.com:8001
Now you will notice that 3 workers were booted instead of just 1 worker. You can change this number to whatever suits your needs.
Since we ran the command to start Gunicorn as root, Gunicorn is now running as root. What if you don't want that? Again, we can alter the command above slightly to accomodate:
#gunicorn_django --workers=3 --user=nobody --bind yourdomainorip.com:8001
If you want to set more options for Gunicorn, then it is best to set up a config file that you can call when running Gunicorn. This will result in a much shorter and easier to read/configure Gunicorn command.
You can place the configuration file for gunicorn anywhere you would like. For simplicity, we will place it in our virtualenv directory. Navigate to the directory of your virtualenv like so:
#cd /opt/myenv
Now open your config file with your preferred editor (nano is used in the example below):
#nano gunicorn_config.py
Add the following contents to the file:
command = '/opt/myenv/bin/gunicorn'
pythonpath = '/opt/myenv/myproject'
bind = '127.0.0.1:8001'
workers = 3
user = 'nobody'
Save and exit the file. What these options do is to set the path to the gunicorn binary, add your project directory to your Python path, set the domain and port to bind Gunicorn to, set the number of gunicorn workers and set the user Gunicorn will run as.
In order to run the server, this time we need a bit longer command. Enter the following command into your prompt:
#/opt/myenv/bin/gunicorn -c /opt/myenv/gunicorn_config.py myproject.wsg
You will notice that in the above command we pass the "-c" flag. This tells gunicorn that we have a config file we want to use, which we pass in just after the "-c" flag. Lastly, we pass in a Python dotted notation reference to our WSGI file so that Gunicorn knows where our WSGI file is.
Running Gunicorn this way requires that you either run Gunicorn in its own screen session (if you're familiar with using screen), or that you background the process by hitting "ctrl + z" and then typing "bg" and "enter" all right after running the Gunicorn command. This will background the process so it continues running even after your current session is closed. This also poses the problem of needing to manually start or restart Gunicorn should your VPS gets rebooted or were it to crash for some reason. To solve this problem, most people use supervisord to manage Gunicorn and start/restart it as needed. Installing and configuring supervisord has been covered in another article which can be found here.
Lastly, this is by no means an exhaustive list of configuration options for Gunicorn. Please read the Gunicorn documentation found at gunicorn.org for more on this topic.

Step Ten;
Configure Nginx
#service nginx restart
Since we are only setting NGINX to handle static files we need to first decide where our static files will be stored. Open your settings.py file for your Django project and edit the STATIC_ROOT line to look like this:
STATIC_ROOT = "/opt/myenv/static/" 
Add to /opt/myenv/myproject/myproject/settings.py
#nano /etc/nginx/sites-available/myproject
server {
        server_name yourdomainorip.com;

        access_log off;

        location /static/ {
            alias /opt/myenv/static/;
        }

        location / {
                proxy_pass http://127.0.0.1:8001;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
        }
    }
#cd /etc/nginx/sites-enabled
#ln -s ../sites-available/myproject
#rm default
#service nginx restart
And that's it! You now have Django installed and working with Mysql and your app is web accessible with NGINX serving static content and Gunicorn serving as your app server. If you have any questions or further advice, be sure to leave it in the comments section.








15 Ağustos 2014 Cuma

Mysql Cluster Auto Installer Video Tutorial

Mysql Cluster Installation


Easy way for mysql cluster installation.

9 Temmuz 2014 Çarşamba

OpenStack Icehouse Kurulumu Ubuntu 12.04 part 3

Configure Compute Node

Compute node ayarları;
Aşağıda ki paketleri indirirken Supermin evet dememiz gerekiyor.

#apt-get install nova-compute-kvm python-guestfs
""Supermin 'Yes'

#
#dpkg-statoverride --update --add root root 0644 /boot/vmlinuz-$(uname -r)
Statoverride dosyasını oluşturalım açılışta yukarıda ki komut çalışması için.
# nano /etc/kernel/postinst.d/statoverride
#!/bin/sh
version="$1"
# passing the kernel version is required
[ -z "${version}" ] && exit 0
dpkg-statoverride --update --add root root 0644 /boot/vmlinuz-${version}


# chmod +x /etc/kernel/postinst.d/statoverride

#nano /etc/nova/nova.conf
/etc/nova/nova.conf
[DEFAULT]
rpc_backend = rabbit
rabbit_host = Controller
rabbit_password = RABBIT_PASS
auth_strategy = keystone
my_ip = 10.0.0.31
vnc_enabled = True
vncserver_listen = 0.0.0.0
vncserver_proxyclient_address = 10.0.0.31
novncproxy_base_url = http://Controller:6080/vnc_auto.html
glance_host = Controller

[database]
# The SQLAlchemy connection string used to connect to the database
connection = mysql://nova:nova@Controller/nova
[keystone_authtoken]
auth_uri = http://Controller:5000
auth_host = Controller
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = nova
admin_password = NOVA_PASS


#nano /etc/nova/nova-compute.conf
[libvirt]
...
virt_type = qemu

#egrep -c '(vmx|svm)' /proc/cpuinfo
#rm /var/lib/nova/nova.sqlite
#service nova-compute restart

Network (Legacy)

###Controller Node
#nano  /etc/nova/nova.conf
[DEFAULT]
...
network_api_class = nova.network.api.API
security_group_api = nova
###
# service nova-api restart ; service nova-scheduler restart ; service nova-conductor restart

####Compute Node

#apt-get install nova-network nova-api-metadata

#
#nano /etc/nova/nova.conf
[DEFAULT]
...
network_api_class = nova.network.api.API
security_group_api = nova
firewall_driver = nova.virt.libvirt.firewall.IptablesFirewallDriver
network_manager = nova.network.manager.FlatDHCPManager
network_size = 254
allow_same_net_traffic = False
multi_host = True
send_arp_for_ha = True
share_dhcp_address = True
force_dhcp_release = True
flat_network_bridge = br100
flat_interface = eth1
public_interface = eth0
#
#service nova-network restart ; service nova-api-metadata restart

##########Controller node
#source admin-openrc.sh

#nova network-create demo-net --bridge br100 --multi-host T \
--fixed-range-v4 10.1.0.0/24

Servislerin çalıştığından emin olmak için ;
#nova-manage service list

Dashboard

#apt-get install apache2 memcached libapache2-mod-wsgi openstack-dashboard
Eğer ubuntu temasını kaldırmak istiyorsanız ;
# apt-get remove --purge openstack-dashboard-ubuntu-theme

http://controller/horizon


OpenStack Icehouse Kurulumu Ubuntu 12.04 part 2

Kaldığımız yerden devam edelim ;)

Open stack services

#apt-get install python-pip

#apt-get install python-novaclient

Image services (Glance)
#apt-get install glance python-glanceclient
#nano /etc/glance/glance-api.conf
#nano /etc/glance/glanceregistry.conf
[database]
connection = mysql://glance:glance@Controller/glance
#
#nano /etc/glance/glance-api.conf
[DEFAULT]
...
rpc_backend = rabbit
rabbit_host = Controller
rabbit_password = RABBIT_PASS

# rm /var/lib/glance/glance.sqlite
#mysql -u root -p
mysql> CREATE DATABASE glance;
mysql> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \
IDENTIFIED BY 'GLANCE_DBPASS';
mysql> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \
IDENTIFIED BY 'GLANCE_DBPASS';

# su -s /bin/sh -c "glance-manage db_sync" glance

#keystone user-create --name=glance --pass=glance \
--email=glance@example.com

#keystone user-role-add --user=glance --tenant=service --role=admin

#nano /etc/glance/glance-api.conf
#nano /etc/glance/glance-registry.conf

[keystone_authtoken]
auth_uri = http://Controller:5000
auth_host = Controller
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = glance
admin_password = GLANCE_PASS

[paste_deploy]
flavor = keystone

#keystone service-create --name=glance --type=image \
--description="OpenStack Image Service"

#keystone endpoint-create \
--service-iid=$(keystone service-list | awk '/ image / {print $2}') \
--publicurl=http://Controller:9292 \
--internalurl=http://Controller:9292 \

--adminurl=http://Controller:9292

#service glance-registry restart ; service glance-api restart
Image Service installation
#mkdir /tmp/images

#cd /tmp/images/
wget http://cdn.download.cirros-cloud.net/0.3.2/cirros-0.3.2-x86_64-disk.img
#glance image-create --name "cirros-0.3.2-x86_64" --disk-format qcow2 \
--container-format bare --is-public True --progress < cirros-0.3.2-x86_64-disk.img

#glance image-list

webden direkt olarak image yüklemek için.
#glance image-create --name="cirros-0.3.2-x86_64" --disk-format=qcow2 \
--container-format=bare --is-public=true \
--copy-from http://cdn.download.cirros-cloud.net/0.3.2/cirros-0.3.2-x86_64-disk.img

Install Compute controller services
#apt-get install nova-api nova-cert nova-conductor nova-consoleauth \

nova-novncproxy nova-scheduler python-novaclient

#nano /etc/nova/nova.conf
rpc_backend = rabbit
rabbit_host = Controller
rabbit_password = rabbit
connection = mysql://nova:nova@Controller/nova
my_ip = 10.0.0.11
vncserver_listen = 10.0.0.11
vncserver_proxyclient_address = 10.0.0.11

## rm /var/lib/nova/nova.sqlite
#mysql -u root -p
mysql> CREATE DATABASE nova;
mysql> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' \
IDENTIFIED BY 'NOVA_DBPASS';
mysql> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' \
IDENTIFIED BY 'NOVA_DBPASS';

# su -s /bin/sh -c "nova-manage db sync" nova
# keystone user-create --name=nova --pass=NOVA_PASS --email=nova@example.
com
#keystone user-role-add --user=nova --tenant=service --role=admin
#nano /etc/nova/nova.conf
[DEFAULT]
...
auth_strategy = keystone
auth_uri = http://Controller:5000
auth_host = Controller
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = nova
admin_password = NOVA_PASS
#
#nano /etc/nova/api-paste.ini
auth_uri = http://Controller:5000
auth_host = Controller
auth_port = 35357
auth_protocol = http
admin_tenant_name = service
admin_user = nova
admin_password = NOVA_PASS

#keystone service-create --name=nova --type=compute \
--description="OpenStack Compute"
#
#keystone endpoint-create \
--service-id=id=$(keystone service-list | awk '/ compute / {print $2}') \
--publicurl=http://Controller:8774/v2/%\(tenant_id\)s \
--internalurl=http://Controller:8774/v2/%\(tenant_id\)s \
--adminurl=http://Controller:8774/v2/%\(tenant_id\)s

#service nova-api restart ; service nova-cert restart ;service nova-consoleauth restart ; service nova-scheduler restart ; service nova-conductor restart ;service nova-novncproxy restart

#nova image-list


19 Mart 2014 Çarşamba

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

Wordpress high availability and scalability part 3

Haproxy kurulumu;
Haproxy Debian wheezy reposunda bulunmamakta kurmak için backport reposunu ekliyoruz.
#vi /etc/apt/source.list
deb http://mirror.vorboss.net/debian/ wheezy-backports main
deb-src http://mirror.vorboss.net/debian/ wheezy-backports main
#apt-get update
#apt-get install haproxy
#nano /etc/default/haproxy
ENABLED=1
#mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
#vi /etc/haproxy/haproxy.cfg
global
    log 127.0.0.1 local0 notice
    maxconn 2000
    user haproxy
    group haproxy

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  10000
    timeout server  10000
listen appname 0.0.0.0:80
    mode http
    stats enable
    stats uri /haproxy?stats
    stats realm Strictly\ Private
    stats auth admin:P123456!
    balance roundrobin
    option httpclose
    option forwardfor
    server Nginx1 10.1.26.40:80 check
    server Nginx2 10.1.26.41:80 check

#service haproxy start
Keepalived kurulumu;
Kurulumun bu aşamasın da LB0 ve LB1 sanal bir interface ile birbirine bağlıyacağız , bu sanal interface dışarıdan gelen isteklere cevap verecek ve LBlardan herhangi biri down olsa dahi sistem çalışmaya devam edecek.
Her iki LB da yapacağımız
#apt-get install keepalived
#vi /etc/keepalived/keepalived.conf
LB1
vrrp_instance VI_1 {
interface eth0
state ASIL
virtual_router_id 10
priority 101   # 101 on asil, 100 on yedek
virtual_ipaddress {
10.1.26.45 #Sanal-ip-adres
}
}

LB2
vrrp_instance VI_1 {
interface eth0
state YEDEK
virtual_router_id 10
priority 100   # 101 on asil, 100 on yedek
virtual_ipaddress {
10.1.26.45 #Sanal-ip-adres
}
}
Her 2 LBda servisleri başlatıyoruz.
#service keepalived start
Asıl olanda aşağıdaki komutu çalıştırdığınız da ;
#ip addr Show eth0
Alacağınız çıktı;
Eth0:  mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:6f:ed:60 brd ff:ff:ff:ff:ff:ff
    inet 10.1.26.43/24 brd 192.168.1.255 scope global eth0
    inet 10.1.26.45/32 scope global eth0
    inet6 fe80::20c:29ff:fe6f:ed60/64 scope link
       valid_lft forever preferred_lft forever
Domain adımızı public ipmize ,firewall tarafında ise sanal interface adresine yönlendirdiğimizde wordpress’in kurulum ekranı karşımıza çıkıyor.
Eğer sistemin çalışıp çalışmadığını test etmek istiyorsanız, aşağıdaki php kodu ile test edebilirsiniz veya http://haproxy-ipadres/haproxy?stats;  yazdığınızda kullanıcı adı ve parolayı girerek haproxy durumunu grafik ekrandan izleyebilirsiniz.
<?php         
header('Content-Type: text/plain');
echo "Server IP: ".$_SERVER['SERVER_ADDR'];
echo "\nClient IP: ".$_SERVER['REMOTE_ADDR'];
echo "\nX-Forwarded-for: ".$_SERVER['HTTP_X_FORWARDED_FOR'];
?>

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




Mysql database cluster and Nginx web server high availability and scalability part1

Wordpress high availability and scalability
Yapıyı kabaca anlatmak gerekirse dışarıdan gelen bütün istekleri Load balancer(Haproxy) karşılayacak ve web sunuculardan (Nginx) alıcak, Nfs sunucusundan bir dizin export edeceğiz ve bunları web sunucuların “www” dizinine mount edeceğiz.
Özetle ,Trafik arttıkça ölçeklendirilebilen bir yapı.
Kullanılan işletim sistemi ve yazılımlar;
·         Debian 7.4 ,
·         Wordpress,
·         Haproxy- Loadbalancer,
·         Nginx-Webserver, php5
·         Nfs server,
·         Galera Cluster (Percona)-Mysql 5.6 Database Cluster.
Galera Cluster kurulumu;
Kurulan bu yapı toplam da 4 Vm üzerine kurulmuştur 1 controler diğer 3’ü node olarak.
Cluster ve Node yapısı;
2 core cpu,
1 gb ram,
30 gb disk alanı.
Scripti oluşturmak için ;
Gerekli alanları doldurduktan sonra Cluster controller’a ‘wget’ indirip.
* tar xvfz s9s-galera-percona-3.2.0.tar
* cd s9s-galera-3.2.0/mysql/scripts/install
* bash ./deploy.sh  2>&1  |tee cc.log

Kurulumu çok kolay sadece sizden nodeların root veya kullanıcı passwordlerini girmenizi istiyor ve kurulumu kendi gerçekleştirmiş oluyor.

Not:
3.2.0 sürümün de olan bir bug var,(nodelar da ki ayarları yaparken my.cnf dosyasından dolayı hata vermekte ) onun çözümü de şöyle;
s9s-galera-percona*/mysql/config/my.cnf
my.cnf dosyasını açın deployment scripttin de:
evs.consensus_timeout=X
değişkenini aşağıdaki gibi değiştirin
evs.install_timeout=X
Yukarıda ki değişikleri yaptıktan sonra;
cd s9s-galera-percona*/mysql/scripts/install/
./bootstrap.sh
./install-cmon.sh -s
cat .s9s/greetings
Sorun çözülmüş ve kurulum bitmiş oluyor .
Galera web arayüzüne erişmek için;

Arayüz üzerinden loadbalancerı da ekleyelim.
Ama öncesin de Haproxy’nin reposunu Cluster contorller makinasının ekleyelim yoksa repo da bulamayım kurulum tamamlanmaz.
#vi /etc/apt/source.list
deb http://mirror.vorboss.net/debian/ wheezy-backports main
deb-src http://mirror.vorboss.net/debian/ wheezy-backports main
#apt-get update
Add Loadbalancer’ı tıkladığınız da aşağıdaki  gibi bir arayüz ile karşılacaksınız.
Proxy yapmak istediğiniz Mysql serverlar ı seçiyoruz, Loadbalancerın kurulmasını istediğiniz makinanın ip adresini yazıyoruz ve ya Cluster controllera kurabilirsiniz.
Haproxy nin çalışmasını istediğiniz portu giriyorsunuz.
Ve install haproxy dedikten sonra sizin yerinize Galera controller kurulumu yapıyor.
Not: Mysql’in default portunu girmeyiniz .

Herhangi bir node’a bağlanıp wordpress için bir database oluşturalım .Diğer nodelar kısa bir süre sonra güncellenecektir ve bir yerde oluşturduğunuz veritabanına diğer 2 nodedan da erişebileceksiniz.
#mysql –u root –p
> CREATE DATABASE  wordpress;
> CREATE USER 'kullanici_adi'@'%' IDENTIFIED BY 'sifre';
> GRANT SELECT,INSERT,UPDATE,DELETE ON wordpress.* TO 'kullanici_adi'@'%';
> FLUSH PRIVILEGES;