Linux Advanced Transport Koriyuki memcache Service

Source: Internet
Author: User
Tags curl define session fpm install php id3 memcached php session nginx server

Linux Advanced Transport Koriyuki memcache Service

案例1:构建memcached服务案例2:LNMP+memcached案例3:PHP的本地Session信息案例4:PHP实现session共享

Memcache Introduction and Theoretical basis:

  relational database: MySQL mariadb RDBMS (relational database Management system) NoSQL, which refers to the non-relational database kv Key=vaule number According to the library Redis mongdb Traditional Web Architecture problem: Many Web applications save data to the RDBMS, the application reads data from the server and displays it in the browser as the amount of data increases, the concentration of the access will be increased, RDBMS load, data response deterioration, site display delay and other heavy Big Impact data Storage location Comparison performance: CPU cache > Memory > Disk > Database Price: CPU cache > Memory > Disk > Database memcached is a high-performance distributed cache server used to centrally cache database query results, reducing database access times To improve the responsiveness of Dynamic Web official website: http://memcached.org/memory management mechanism: the traditional memory allocation mechanism is used to reclaim memory after allocating memory, which is easy to generate memory fragmentation and reduce the operating system management efficiency of memory slab AL The location mechanism divides the allocated memory into a specific length of memory block (chunk) by a predetermined size, and then divides the same memory block into groups (chunk collection) that memory is not freed and can be reused memcached using the name least recently Used (LRU) mechanism to allocate space to delete "least recently used" records when memcached has insufficient memory space, search from records that have not been used recently and allocate their space to new records/usr/lib/systemd/system/this is Systemctl    The directory for the configuration (startup script) file. This directory has a corresponding service in order to start the service successfully systemctl start memcached have this command to start all of the options are affected by the script file in this directory, you can add Nginx to use this Kai, refer to the Apache template. Execstart (function Connection) =/usr/bin/memcached-u $USER-P $PORT-M $CACHESIZE-c $MAXCONN $OPTIONS/etc/sysconfig/memcached  /pre>

Building memcached Services

Install the Memcached software, and start the service to use Telnet test memcached service to memcached, delete, change, check and other operations yum-y install memcached memcached profile (view, no need to modify) Vim/usr/lib/systemd/system/memcached.service execstart=/usr/bin/memcached-u $USER-P $PORT-M $CACHESIZE -C $MAXCONN $OPTIONS vim/etc/sysconfig/memcached port= "11211" user= "memcached" MA        xconn= "cachesize=" "options=" "start the service and see if network connection status verification is successful Systemctl start memcached  Systemctl Status memcached netstat-anptu |            grep memcached port number 11211 using Telnet to access memcached server yum-y install telnet telnet 192.168.4.5 11211            Add name 0 180 10//variable not present adds set name 0 180 10//Add or replace variable replace name 0 180 10//Replace Get name//Read variable append name 0 180 10//Append data to variable delete name//delete variable stats//view       Status Flush_all//emptying all STAT get_hits hits hit (succeeded) 14 times     STAT get_misses 7 failed 7 times hint: 0 means no compression, 180 is the data cache time, and 10 is the number of bytes of data that needs to be stored.      Cache Expiration Time: People search cache 20 database user video (music) ———— Youku people Search cache 20 databases 1 hours descendant search cache 21 databases

####################################################################

Lnmp+memcached:

Deploy LNMP implement PHP Dynamic Web site schema for PHP installation memcache extension to create PHP page, and write PHP code, to implement the memcached data operation to install the source package dependency package yum-y install GCC openssl-devel pcre -devel zlib-devel Installation Complete nginx and start the service CD LNMP_SOFT/CD nginx-1.12.2/useradd-s/sbin/nolgin/nginx./configure --help./configure--prefix=/usr/local/nginx/--user=nginx--group=nginx--with-http_ssl_module--with-stream Make &    amp;& make install ln-s/usr/local/nginx/sbin/nginx/sbin/nginx netstat-natulp |grep 80 Modify configuration file for dynamic and static separation            Location/{root HTML;        Index index.php index.html index.htm;            } location ~ \.php$ {root html;            Fastcgi_pass 127.0.0.1:9000;           Fastcgi_index index.php;            # Fastcgi_param Script_filename $document _root$fastcgi_script_name;        Include fastcgi.conf; Install PHP php-mysql (the module that calls the MARIADB database) php-fpm Php-pecl-memcache (the module that calls the Memcache database) CD php_scripts/yum-y Insta ll PHP Php-mysql YuM-y installed Php-pecl-memcache yum-y install php-fpm-5.4.16-42.el7.x86_64.rpm installation mariadb (client) mariadb-server (server side) MA Riadb-devel (dependent package) yum-y Install mariadb mariadb-server mariadb-devel installing NoSQL database yum-y installed memcached boot Services and off-firewall nginx mariadb php-fpm memcached service nginx systemctl restart mariadb systemctl enable MARIADB systemct L Restart PHP-FPM systemctl enable php-fpm systemctl restart Memcached.service systemctl enable memcached set Enforce 0 firewall-cmd--set-default-zone=trusted verify: CP mem.php/usr/local/nginx/html Curl 192.168.2.111/mem . PHP (Result is test)

####################################################

Local session information for PHP

    Deploy Nginx for foreground dispatch server scheduling algorithm set to poll backend for two LNMP Server Deployment test page, view PHP local session Information membership card ID001 person--------------------- -----------------Supermarket Member "registration information" 001.txt Information 002.txt information 0                           02.txt Information Membership card ID002 person--------------------------------------"supermarket member" registration information "001.txt Information 002.txt Information 002.txt Information membership card ID003 person-----------------------------------        ---Supermarket member "registration information" 001.txt Information 002.txt information 002.txt information                        Firefox-----------------------> Login session information (COOKIE=001) 001.txt Information 002.txt Information 002.txt Information Ip_hash Solution: Web1 id1.txt{                                                                Information} user (IP) proxy (proxy) WEB2 id2.txt{information} public server WEB3 id3.txt{Information}       Cookie= "hm_lvt...sessionid=287679e630584099aa29780a0f7658bd%7cp%23375184726%40qq.com%7c%7c1%7c0%7c0%7c%7c0%7c0 %7C0 "//browser can see SessionID. Step: Deploy back-end LNMP server related software (two back-end server operation same)//implement static and dynamic separation can not install memcached start LNMP Server related services and shutdown firewall deployment front-end nginx Dispatch Server installation N     Ginx Software modified nginx configuration file implementation scheduling Nginx-s reload off SELinux, Firewall curl http://192.168.4.5/index.html//test Deploy back-end LNMP Server test page (two back-end server operations same)//modify the contents of index.php and home.php two files, add page color properties to differentiate two different servers on the backend: <body b        Gcolor=blue> CD lnmp_soft/php_scripts/tar-xf php-memcached-demo.tar.gz CD Php-memcached-demo                    CP-A */usr/local/nginx/html/Modify Default homepage location/{root HTML;                  Index index.php index.html index.htm;                     This is in order to find, the first to find a second. Firefox http://192.168.2.100//fill in the Account information//This step test can only access the back end of the web cannot access the proxy and to clear the flow of the slow To/va in the store.r/lib/php/session/record ID2 ID3 etc ls/var/lib/php/session///View server local session information sess_ahilcq9bguot0            vqsjtd84k7244//Note here the ID is random browser access front-end scheduler test (different backend server session inconsistent) Google-chrome http://192.168.4.5//recommended with Google After filling in the registration information, refresh, and also need to register, indicating that two computers are using the local session//second host does not know you again the first host is logged in, the first host's login information is not passed to the second host//actual            Situation is: Can enter the login after the jump interface, a refresh will be changed from Web1 to WEB2, and can see the user name is not the same!!! Welcome:haha Welcome:xixi The user name changes here means that the user name and account number you logged in previously did not take effect on another Web server.

PHP Implementation session sharing (continue the experiment)

The 
  Nginx Server needs to assume the role of the memcached database in addition to the scheduler. And on the two back-end LNMP server implementation of PHP session sharing on the experimental front-end Nginx Dispatch server to build memcache Server installation memcached service start service and check the network connection status verification is turned on successfully shutdown SELinux, firewall in The backend LNMP server deploys session sharing yum-y install Php-pecl-memcache//Because the backend two Web servers (WEB1,WEB2) need to connect to the Memcached database, both hosts need to install PHP extension module Block vim/etc/php-fpm.d/www.conf//Modify the configuration file for the last 2 lines of the two parameters//file before modifying the effect as follows: Php_value[session.save_handler] = File s Php_value[session.save_path] =/var/lib/php/session//original file, default definition sessoin session information Local computer (default in/var/lib/php/session) ++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ modified after the effect is as follows: Php_value[session.save_handler] =        Memcache #把php的值session对话信息交给谁处理 Processor (handler) is memcache php_value[session.save_path] = "tcp://192.168.2.5:11211" #传输对话信息的路径是通过tcp协议传给memcache服务器的11211这个端口//Define session information is stored on the public memcached server, the host parameter is memcache (no d)//defined by the Path parameter public memcached Server (IP and port of the server) systemctl restart PHP-FPM  

Linux Advanced shipping Koriyuki memcache service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.