How to build a memcached server

Source: Internet
Author: User
Tags install php memcached session id

The goal of this experiment is to build a memcached server to verify how the test site client

Connect the memcached server and use the cluster to verify session ID



First, preparatory work, prepare two servers, one to do memcached server (a:4.123), a Web server (b:4.124)

1. Install the software on a: yum-y Install memcached.x86_64 telnet (for remote server testing)

2. Configure the installation LNMP environment on B


Second, the operation on Server A

1. Configuration profile: vim/etc/sysconfig/memcached

port= "11211"//service port number

User= "Memcached"

Maxconn= "1024x768"// Maximum number of connections

Cachesize= "64"//size of storage space

Options= ""//Optional parameter configuration

2, start the service, set boot from:

Systemctl Start Memcached.service

Systemctl Enable Memcached.service

3, connection, simple statement test

telnet 127.0.0.1 11211//Connect the database under the shell

Verify that you can read and write:

Set name 0 180 3//New name variable, not compressed, live 180 seconds, 3 character length

123//Input variable contents

STORED

Get name//Read the value of the name variable

VALUE Name 0 3

123

END

4, memcached some simple statements:

add--new (does not overwrite the previous content) set--new (overwrites the previous content)

append--Append (Append content to existing variable) flush_all--empty all content


Third, the operation on server B

1. Install Nginx, PHP, mariadb on B

Detailed installation refer to my other experiments, install the software and configure the configuration file.

Installation: yum-y install php-pecl-memcache.x86_64 to allow PHP files to connect to memcached database

Fill in the PHP file with a server's IP address information and port number: mem.php file

<?php

$memcache =new memcache;

$memcache->connect (' 192.168.4.123 ', 11211) or die (' could not connect!!  '); Connecting to a database

$memcache->set (' key ', ' test '); Write Data

$get _values= $memcache->get (' key '); Reading data

echo $get _values; Display on the page

?>

2, on Server A authentication: http://192.168.4.124/mem.php, out "test" is to demonstrate the success of the verification


Four, session sessions in Memcached

1. Prepare two servers Java+tomcat (2.100 and 2.200)//can refer to my other experiments

Prepare a proxy server, with Nginx proxy, I use Server A to do proxy,

Install Nginx on the top and configure the Web cluster to be accessed with the real machine as a client.

2, sid Session: User account, password, access history and so on.

Cookie: Store ID number, next time direct login, do not need to enter user name and password

3. Put the test page in the root directory of the two default websites: test.jsp, test in client, get different ID

<body bgcolor= "Red" >

<center>

<%string s = Session.getid ();%>

<%=s%>

</center>

</body>

2.100:e8912319c717e184712fdf56f428176a Tomcata

2.200:9c842947128b1dde593e5b30d425e2a6 TOMCATB

From the above can be seen, get a different ID number, how to solve this problem,

Let Tomcat read and write user information on memcached

4, modify the configuration file: Vim/usr/local/tomcat/conf/context.xml

Change the address above to memcached address, the IP I use here is 192.168.2.123 (A)

5. Verification: http://www.test.com/test.jsp

The resulting results are: d3866d1bc10489bc58961e3732d63863-mem1 TOMCATB

D3866d1bc10489bc58961e3732d63863-mem1 Tomcata

As you can see, in the above verification, although the server changed, but its ID number is unchanged


































How to build a memcached server

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.