Memcached configuration

Feedback


The main function of Memcached in this solution is to realize session sharing and consistency of multiple iPortal services, so that the users will not change their logon status because of the switching between iPortal nodes in the process of using iPortal. Configure and deploy Memcached service on the deployed Nginx server.

  1. Install dependencies

The operation of Memcached relies on libevent-devel. Run the following command:

yum –y install libevent-devel

If you are not connected to the Internet and there are no related package in the local yum source, you need to manually download and install the following files:

Copy the downloaded three files to the specified directory, such as :/tmp, and then run the following command to install these dependencies:

cd /tmp

yum install libevent-*.rpm

  1. Compile and install Memcached

Copy the Memcached source file to the specified directory, such as :/usr/local/src/, and then run the following command to extract, compile, and install Memcached:

tar zxf memcached-1.4.25.tar.gz

cd memcached-1.4.25

./configure

make

make install

  1. Step 5: Make the Memcached startup script to register the Memcached as a system service and start it with the system

Create a new "Memcached" file with a text editing tool, such as NotePad++, and save the file in UNIX format and add the following code to the file:

#!/bin/sh   

#   

# memcached:    MemCached Daemon   

#   

# chkconfig:    - 90 25    

# description:  MemCached Daemon   

#   

# Source function library.   

. /etc/rc.d/init.d/functions   

. /etc/sysconfig/network   

    

start()    

{   

        echo -n $"Starting memcached: "  

        daemon /usr/local/bin/memcached -u root -d -m 10 -p 11211  

        echo   

}   

    

stop()    

{   

        echo -n $"Shutting down memcached: "  

        killproc memcached    

        echo   

}   

    

[ -f /usr/local/bin/memcached ] || exit 0  

    

# See how we were called.   

case "$1" in   

  start)   

        start   

        ;;   

  stop)   

        stop   

        ;;   

  restart|reload)   

        stop   

        start   

        ;;   

  condrestart)   

        stop   

        start   

        ;;   

  *)   

        echo $"Usage: $0 {start|stop|restart|reload|condrestart}"  

        exit 1  

esac   

exit 0

Among them, /usr/local/bin/memcached-u root-d-M 10-p 11211 is a line of code to start the memcached command. Meanings of parameters are as follows:

Copy the created memcached file to the specified directory /etc/init. D, execute the following command, register the memcached as a system service, and start it with the system.

chmod +x /etc/init.d/memcached

chkconfig --add memcached

chkconfig memcached on

If memcached starts successfully, following will display.