16_ build memcached service, LNMP + Local Session information memcached, PHP is, PHP achieve shared session


















 








VALUE name 0 3 # output
AAA
the END
 
the Add myname 0 180 [10 # New, myname does not exist added, the presence of the error
wwwwwwwwww
STORED

SET myname 0 180 [. 5 # add or replace the variable
wwwww
STORED

Replace myname 0 180 [. 3 # Alternatively, if myname an error does not exist
TTT
STORED

GET # myname read variable
TTT
the END

the append myname. 5 180 [# 0 is added to the variable data
OOOOO
STORED
GET myname
of VALUE myname 0. 8
tttooooo

delete delete variable myname #
dELETED

stats View status #
flush_all # clear all
the OK

quit # Log                                  
 
3.LNMP + memcached (web1 web2)
3.1 to deploy nginx (front)
3.2 部署mariadb
]# yum -y install mariadb mariadb-server mariadb-devel
]# systemctl start  mariadb
]# systemctl enable mariadb
]# mysqladmin -uroot -p password "123456"
]# mysql -uroot -p123456

3.3 部署PHP
]# yum -y install php php-mysql php-fpm php-pecl-memcache
]# systemctl start php-fpm
]# systemctl enable php-fpm

nginx开启php
]# vim /etc/nginx/conf.d/default.conf
...
location / {
        root   /usr/share/nginx/html;
        index index.php  index.html index.htm;
    }
...
location ~ \.php$ {
        root           /usr/share/nginx/html;   #绝对路径
        fastcgi_pass   127.0.0.1:9000;
        the index.php fastcgi_index;
        fastcgi_param SCRIPT_FILENAME $ $ DOCUMENT_ROOT fastcgi_script_name;
        the include fastcgi_params;
    }
] # -s reload Nginx

connected memcache database
] Vim /usr/share/nginx/html/test.php #
<PHP?
$ = new new memcache the Memcache; # objects created memcache
$ memcache-> Connect ('10 .10.11.10 ', 11211) or Die (' could not Connect !! ');
$ memcache-> the SET (' Key ',' the Test '); # define a variable
$ get_values = $ memcache-> get ( 'key' ); # get the value of the variable
echo $ get_values;
>?

Client detection:
] Firefox http://10.10.11.12/test.php #
 
4.Local information PHP Session of
the load back-end Web server through two Nginx scheduler
deployment schedule for the front Nginx server
scheduling algorithm to poll
the back-end servers for the two LNMP
Deployment test page to see the local PHP Session information
 
4.1 proxy set up nginx (front)
web1
] # echo "web1"> /usr/share/nginx/html/index.html
web2
] # echo "web2"> / usr / report this content share /nginx/html/index.html
4.2 scheduling layer. 7
] # Vim /etc/nginx/nginx.conf
.. ..
HTTP {
.. ..
# define the upstream end server cluster using the cluster name arbitrary (e.g., the webserver)
# using the definition of a cluster server specific server and port
upstream the webserver {
       server 10.10.11.12:80;
       server 10.10.11.13:80;
        }
.. ..

] # Vim /etc/nginx/conf.d/default.conf
server {
        the listen 80;
        ; server_name www.a.com
# proxy_pass forwarded through the user's request to the webserver cluster
        location / {
            HTTP proxy_pass: // webserver;
        }
...
] # nginx -s reload

Client test :( default polling)
] # curl http://10.10.11.10
web1
] # curl http://10.10.11.10
web2
] # curl http://10.10.11.10
web1
] # curl http://10.10.11.10
web2
 
4.3 deployment test page (the session)
web1 web2
] # cd PHP-memcached-Demo
] # cp -a * / usr / report this content share / nginx / HTML /
] # LS
50x.html ImagesRF Royalty Free index.php README.md  
home.php index.html login.php the style.css
web1: (Proxy polling, client easy to see which server)
] # vim index.php -> <body bgcolor = "Red">
] Vim the home.php # -> <body bgcolor = "Red">
web2:
] # Vim index.php -> <body bgcolor = "Blue">
] # vim home.php -> <body bgcolor = "Blue">
real machine goole chrome View:
http://10.10.11.10/index. php (F5 to refresh the page to view the landing polling)
enter the account password (2 times to schedule in two web servers to store session information)
after landing: (F5 to refresh the page to view the landing poll)
 
5. PHP to achieve a shared session
in use 4, PHP-FPM by modifying the configuration file, implement session session sharing.
configure PHP session to use memcached server to share information.
when the client access two different back-end Web server, session consistent information
on the basis of practice on three topologies, Nginx in addition to assume the scheduler server, but also need to assume the role of memcached database, and the PHP session sharing session realize on both the back-end server LNMP.
5.1 deploy memcache
] # yum -y install memcached
] # systemctl Start memcached
] # systemctl enable memcached
] # netstat -anptu | grep memcached
5.2 deployed on a back-end server Session LNMP share
web1 web2
] # vim / etc / PHP-FPM. d / www.
 
Before modifying effect is as follows:
php_value to [session.save_handler] = Files
php_value to [the session.save_path] = / var / lib / php / the session
// original file, the default session information defines the local computer Sessoin (default / var / lib / php / session)
 
modified the following effects:
php_value to [session.save_handler] = memcache
php_value to [the session.save_path] = "TCP: //10.10.11.10: 11211"
// define Session information is stored on a common server memcached, parameters for the host memcache (no d)
// path defined by the parameters in which public memcached server (IP and port of the server)
] # systemctl restart PHP-FPM
 
real machine goole chrome View:
(F5 to refresh the page to view the landing polling)
HTTP: // 10.10.11.10/index.php
If an error to view the log from php:
] # LS / var / log / php-FPM /
error.log the WWW-error.log

Guess you like

Origin www.cnblogs.com/luwei0915/p/12158748.html