Valid XHTML 1.0 TransitionalHello World to Redis & Memcached

Page: [index.html] (v2017-04-05_21-20)

  1. Redis :
    一种带有磁盘存储 (持久化) 支持的 Key-Value 型内存数据库。
    主页:https://redis.io
    1. 服务器端:
      1. 下载:
        [typhoon@TFW-CENT6-LT to_test.redis]$ axel http://download.redis.io/releases/redis-2.8.3.tar.gz -n 2 -o redis-3.2.8.tar.gz
        初始化下载: http://download.redis.io/releases/redis-2.8.3.tar.gz
        File size: 1046106 bytes
        打开输出文件 tmp2/redis-3.2.8.tar.gz
        开始下载
        
        [  0%]  .......... .......... .......... .......... ..........  [  33.3KB/s]
        [  4%]  .......... .......... .......... .......... ..........  [  52.9KB/s]
        [  9%]  .......... .......... .......... .......... ..........  [  56.8KB/s]
        [ 14%]  .......... .......... .......... .......... ..........  [  66.1KB/s]
        [ 19%]  .......... .......... .......... .......... ..........  [  71.9KB/s]
        [ 24%]  .......... .......... .......... .......... ..........  [  72.1KB/s]
        [ 29%]  .......... .......... .......... .......... ..........  [  77.1KB/s]
        [ 34%]  .......... .......... .......... .......... ..........  [  81.0KB/s]
        [ 39%]  .......... .......... .......... .......... ..........  [  84.7KB/s]
        [ 44%]  .......... .......... .......... .......... ..........  [  92.5KB/s]
        [ 48%]  .......... .
        连接 1 结束
                ,,,,,,,,,, ,......... ...
        连接超时 0
                ,,,,,,,,,, ,,,,,,,,,, ,,,....... .......... ..........  [   8.0KB/s]
        [ 53%]  .......... .......... .......... .......... ..........  [   8.7KB/s]
        [ 58%]  .......... .......... .......... .......... ..........  [   9.3KB/s]
        [ 63%]  .......... .......... .......... .......... ..........  [  10.0KB/s]
        [ 68%]  .......... .......... .......... .......... ..........  [  10.6KB/s]
        [ 73%]  .......... .......... .......... .......... ..........  [  11.3KB/s]
        [ 78%]  .......... .......... .......... .......... ..........  [  11.8KB/s]
        [ 83%]  .......... .......... .......... .......... ..........  [  12.5KB/s]
        [ 88%]  .......... .......... .......... .......... ..........  [  13.1KB/s]
        [ 92%]  .......... .......... .......... .......... ..........  [  13.6KB/s]
        [ 97%]  .......... .......... .
        
        1021.6 千字节 已下载,用时 1:13 秒。(13.92 千字节/秒)
        [typhoon@TFW-CENT6-LT to_test.redis]$ ls
        redis-3.2.8.tar.gz
        [typhoon@TFW-CENT6-LT to_test.redis]$
      2. 编译:
        [typhoon@TFW-CENT6-LT to_test.redis]$ tar zxvf redis-3.2.8.tar.gz
        redis-3.2.8/
        redis-3.2.8/.gitignore
        redis-3.2.8/00-RELEASENOTES
        ……
        ……
        ……
        redis-3.2.8/utils/releasetools/04_release_hash.sh
        redis-3.2.8/utils/speed-regression.tcl
        redis-3.2.8/utils/whatisdoing.sh
        [typhoon@TFW-CENT6-LT to_test.redis]$ ls
        redis-3.2.8  redis-3.2.8.tar.gz
        [typhoon@TFW-CENT6-LT to_test.redis]$ cd redis-3.2.8/src
        [typhoon@TFW-CENT6-LT src]$ make all;echo $?;;
        rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
        (cd ../deps && make distclean)
        make[1]: Entering directory `/home/typhoon/123/download/soft.tmp/to_test.redis/redis-3.2.8/deps'
        ……
        ……
        ……
            CC redis-check-aof.o
            LINK redis-check-aof
        
        Hint: It's a good idea to run 'make test' ;)
        
        0
        [typhoon@TFW-CENT6-LT src]$
      3. 安装:
        [typhoon@TFW-CENT6-LT src]$ su -
        密码:
        [root@TFW-CENT6-LT ~]# mount /ext/ro1 -o remount,rw
        [root@TFW-CENT6-LT ~]# cd /ext/ro1/prog
        [root@TFW-CENT6-LT prog]# mkdir -p redis-3.2.8/bin redis-3.2.8/conf
        [root@TFW-CENT6-LT prog]# ln -s redis-3.2.8 Redis
        [root@TFW-CENT6-LT prog]# cp -a /home/typhoon/123/download/soft.tmp/to_test.redis/redis-3.2.8/redis.conf Redis/conf
        [root@TFW-CENT6-LT prog]# cd /home/typhoon/123/download/soft.tmp/to_test.redis/redis-3.2.8/src
        [root@TFW-CENT6-LT src]# cp -a redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb /ext/ro1/prog/Redis/bin
        [root@TFW-CENT6-LT src]# mkdir -p /ext/rw1/prog/redis-3.2.8.var
        [root@TFW-CENT6-LT src]# cd /ext/ro1/prog/Redis
        [root@TFW-CENT6-LT Redis]# ln -s /ext/rw1/prog/redis-3.2.8.var var
        [root@TFW-CENT6-LT Redis]# ls
        bin  conf  var
        [root@TFW-CENT6-LT Redis]#
        
      4. 配置:
        1. 环境变量:
          [root@TFW-CENT6-LT Redis]# vi /etc/profile.d/tfw_09_redis.sh
          [root@TFW-CENT6-LT Redis]# cat /etc/profile.d/tfw_09_redis.sh
          #!/bin/sh
          #	Version:	2017-04-03_15-40
          export REDIS_HOME=/ext/ro1/prog/Redis;
          export PATH=$PATH:$REDIS_HOME/bin;
          [root@TFW-CENT6-LT Redis]#
          
        2. 配置文件:
          修改 /ext/ro1/prog/Redis/conf/redis.conf :
          1. 指定数据存储 (持久化) 目录:
            # The Append Only File will also be created inside this directory.
            #
            # Note that you must specify a directory here, not a file name.
            # dir ./
            dir /ext/ro1/prog/Redis/var/
            
            ################################# REPLICATION #################################
            
            # Master-Slave replication. Use slaveof to make a Redis instance a copy of
            
          2. 指定访问密码:
            # use a very strong password otherwise it will be very easy to break.
            #
            # requirepass foobared
            # TFW below:
            requirepass ********
            
            # Command renaming.
            #
            # It is possible to change the name of dangerous commands in a shared
            
        3. 便捷启动脚本:
          [root@TFW-CENT6-LT Redis]# vi bin/start_redis.sh
          [root@TFW-CENT6-LT Redis]# cat bin/start_redis.sh
          #!/bin/sh
          #	Author:	Typhoon.Free.Wolf
          "$REDIS_HOME/bin/redis-server" "$REDIS_HOME/conf/redis.conf"&
          [root@TFW-CENT6-LT Redis]#
          
        4. 权限:
          [root@TFW-CENT6-LT Redis]# chown -R typhoon.typhoon .
          [root@TFW-CENT6-LT Redis]# chmod 700 bin/*
          [root@TFW-CENT6-LT Redis]# chmod 755 bin/redis-cli
          [root@TFW-CENT6-LT Redis]# ll bin
          总用量 34120
          -rwx------. 1 typhoon typhoon 5578439 4月   3 15:20 redis-benchmark
          -rwx------. 1 typhoon typhoon   22241 4月   3 15:20 redis-check-aof
          -rwx------. 1 typhoon typhoon 7828138 4月   3 15:20 redis-check-rdb
          -rwxr-xr-x. 1 typhoon typhoon 5707371 4月   3 15:20 redis-cli
          -rwx------. 1 typhoon typhoon 7828138 4月   3 15:20 redis-sentinel
          -rwx------. 1 typhoon typhoon 7828138 4月   3 15:20 redis-server
          -rwx------. 1 typhoon typhoon   60852 2月  12 23:14 redis-trib.rb
          -rwx------. 1 typhoon typhoon     100 4月   3 16:50 start_redis.sh
          [root@TFW-CENT6-LT Redis]# chmod -R 700 conf
          [root@TFW-CENT6-LT Redis]# ll
          总用量 8
          drwxr-xr-x. 2 typhoon typhoon 4096 4月   3 16:50 bin
          drwx------. 2 typhoon typhoon 4096 4月   3 22:02 conf
          lrwxrwxrwx. 1 typhoon typhoon   29 4月   3 20:42 var -> /ext/rw1/prog/redis-3.2.8.var
          [root@TFW-CENT6-LT Redis]# chmod 700 /ext/rw1/prog/redis-3.2.8.var
          [root@TFW-CENT6-LT Redis]# ll /ext/rw1/prog
          总用量 ……
          ……
          ……
          drwx------. 2 typhoon typhoon 4096 4月   4 15:40 redis-3.2.8.var
          [root@TFW-CENT6-LT Redis]#
          
        5. 服务控制脚本:
          1. 准备:
            将密码存入文件,而非写在服务控制脚本中:
            [root@TFW-CENT6-LT Redis]# echo "********">conf/redis_passwd
            [root@TFW-CENT6-LT Redis]# ll conf/redis_passwd
            -rw-------. 1 typhoon typhoon 6 4月   3 16:56 /ext/ro1/prog/Redis/conf/redis_passwd
            [root@TFW-CENT6-LT Redis]# cat conf/redis_passwd
            ********
            [root@TFW-CENT6-LT Redis]# mount /ext/ro1 -o remount,ro
            [root@TFW-CENT6-LT Redis]# exit
            [typhoon@TFW-CENT6-LT src]#
            
          2. 编写服务控制脚本“/etc/rc.d/init.d/tfw_redis”:
            #! /bin/sh
            
            # chkconfig:  35 96 04
            # description: Redis service script.
            
            # Version:
            #	2017-04-04_12-50
            # By:
            #	Typhoon.Free.Wolf.
            
            # ========================================
            # Customized values:
            	SVC_NAME="Redis";
            	START_WAIT_SECONDS=1;
            	STOP_WAIT_SECONDS=1;
            # ========================================
            # Customized variables:
            	APP_HOME="/ext/ro1/prog/Redis";
            	APP_USER="typhoon";
            	APP_PASSWD=$(cat "$APP_HOME/conf/redis_passwd");
            	# PROC_FILTER_CMD="ps aux | grep -v \"grep\" | grep \"$APP_HOME/bin/redis-server\";";
            	# PROC_FILTER_CMD="ps aux";
            # ========================================
            # Functions with customized inner content:
            	_status() {
            		# echo "$PROC_FILTER_CMD";
            		# $("$PROC_FILTER_CMD");
            		# `"$PROC_FILTER_CMD"`;
            		ps aux | grep -v "grep" | grep "$APP_HOME/bin/redis-server";
            		return $?;
            	}
            
            	_start() {
            		su - "$APP_USER" -c "\"$APP_HOME/bin/redis-server\" \"$APP_HOME/conf/redis.conf\"&";
            		return $?;
            	}
            
            	_stop() {
            		su - "$APP_USER" -c "\"$APP_HOME/bin/redis-cli\" -a \"$APP_PASSWD\" \"shutdown\"";
            		return $?;
            	}
            # ========================================
            # Static common part.
            	……
            	……
            	……
            # ========================================
            
          3. 启停验证:
            [root@TFW-CENT6-LT Redis]# chmod u+x /etc/rc.d/init.d/tfw_redis
            [root@TFW-CENT6-LT Redis]# service tfw_redis restop;echo $?;
            Service [ Redis ] starting...
            5331:M 04 Apr 21:43:00.835 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
            5331:M 04 Apr 21:43:00.835 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
            5331:M 04 Apr 21:43:00.835 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                            _._
                       _.-``__ ''-._
                  _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
              .-`` .-```.  ```\/    _.,_ ''-._
             (    '      ,       .-`  | `,    )     Running in standalone mode
             |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
             |    `-._   `._    /     _.-'    |     PID: 5331
              `-._    `-._  `-./  _.-'    _.-'
             |`-._`-._    `-.__.-'    _.-'_.-'|
             |    `-._`-._        _.-'_.-'    |           http://redis.io
              `-._    `-._`-.__.-'_.-'    _.-'
             |`-._`-._    `-.__.-'    _.-'_.-'|
             |    `-._`-._        _.-'_.-'    |
              `-._    `-._`-.__.-'_.-'    _.-'
                  `-._    `-.__.-'    _.-'
                      `-._        _.-'
                          `-.__.-'
            
            5331:M 04 Apr 21:43:00.836 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
            5331:M 04 Apr 21:43:00.837 # Server started, Redis version 3.2.8
            5331:M 04 Apr 21:43:00.837 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
            5331:M 04 Apr 21:43:00.837 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
            5331:M 04 Apr 21:43:00.837 * DB loaded from disk: 0.000 seconds
            5331:M 04 Apr 21:43:00.837 * The server is now ready to accept connections on port 6379
            typhoon   5331  0.0  0.1 133524  7876 ?        Sl   21:43   0:00 /ext/ro1/prog/Redis/bin/redis-server 127.0.0.1:6379
            Running, successfully started.
                                                                       [确定]
            Service [ Redis ] stopping...
            typhoon   5331  1.0  0.1 133524  7876 ?        Sl   21:43   0:00 /ext/ro1/prog/Redis/bin/redis-server 127.0.0.1:6379
            5331:M 04 Apr 21:43:01.927 # User requested shutdown...
            5331:M 04 Apr 21:43:01.927 * Saving the final RDB snapshot before exiting.
            5331:M 04 Apr 21:43:02.110 * DB saved on disk
            5331:M 04 Apr 21:43:02.110 * Removing the pid file.
            5331:M 04 Apr 21:43:02.110 # Redis is now ready to exit, bye bye...
            Not running, successfully stopped.
                                                                       [确定]
            0
            [root@TFW-CENT6-LT Redis]# service tfw_redis start;echo $?;
            Service [ Redis ] starting...
            5402:M 04 Apr 21:43:14.982 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
            ……
            ……
            ……
            Running, successfully started.
                                                                       [确定]
            0
            [root@TFW-CENT6-LT Redis]#
            
          4. 访问验证:
            [guest@TFW-CENT6-LT ~]$ redis-cli -a ********
            127.0.0.1:6379> set a "AAA"
            OK
            127.0.0.1:6379> get a
            "AAA"
            127.0.0.1:6379> del a
            (integer) 1
            127.0.0.1:6379> get a
            (nil)
            127.0.0.1:6379> quit
            [guest@TFW-CENT6-LT ~]$
            
    2. Java 客户端:
      1. 下载:
        编辑“pom.xml”:
        <project ……>
        	……
        	……
        	……
        	<dependencies>
        		……
        		……
        		……
        		<dependency>
        			<!-- Use redis. -->
        			<groupId>redis.clients</groupId>
        			<artifactId>jedis</artifactId>
        			<version>2.9.0</version>
        		</dependency>
        	</dependencies>
        </project>
        
      2. 使用:
        tfw.integration_demo._07_concurrency._01_redis.RedisTestcase
        ……
        public class RedisTestcase
        {
        
        	private Jedis jedis;
        
        	@Before
        	public void init()
        	{
        		jedis = new Jedis("127.0.0.1");
        		jedis.auth("redis");
        		jedis.connect();
        	}
        
        	@After
        	public void close()
        	{
        		jedis.disconnect();
        	}
        
        	@Test
        	public void testString()
        	{
        		jedis.set("user.acl.0.text", "ALL");
        		jedis.set("user.acl.12334.text", "11,13,14,15");
        		jedis.set("user.acl.2345.text", "11,13,14");
        		jedis.set("user.acl.35611.text", "13,55,99,101,103");
        		jedis.set("user.acl.35612.text", "13,55,99,101,103");
        		jedis.set(null, "13,55,99,101,103");
        
        		System.out.println(jedis.get("user.acl.0.text"));
        		System.out.println(jedis.get("user.acl.35611.text"));
        		System.out.println(jedis.get("user.acl.35616.text"));
        		System.out.println(jedis.get((String) null));
        	}
        
        	@Test
        	public void testSerializable()
        	{
        		jedis.set("user.acl.0.array".getBytes(),
        				serialize(new String[] { "ALL" }));
        		jedis.set("user.acl.12334.array".getBytes(),
        				serialize(new String[] { "11", "13", "14", "15" }));
        		jedis.set("user.acl.2345.array".getBytes(),
        				serialize(new String[] { "11", "13", "14" }));
        		jedis.set("user.acl.35611.array".getBytes(),
        				serialize(new String[] { "13", "55", "99", "101", "103" }));
        		jedis.set("user.acl.35612.array".getBytes(),
        				serialize(new String[] { "13", "55", "99", "101", "103" }));
        		jedis.set("user.0".getBytes(), serialize(
        				new User(0, "root", "passwd", (byte) 1, "Super user.")));
        
        		System.out.println(ArrayToolE.arrayForConsole((Object[]) deserizlize(
        				jedis.get("user.acl.0.array".getBytes()))));
        		System.out.println(ArrayToolE.arrayForConsole((Object[]) deserizlize(
        				jedis.get("user.acl.35611.array".getBytes()))));
        		// System.out.println(ArrayToolE.arrayForConsole((Object[]) deserizlize(
        		// jedis.get("user.acl.35616.array".getBytes()))));
        		System.out.println(deserizlize(jedis.get("user.0".getBytes())));
        	}
        
        	private byte[] serialize(Object obj)
        	{
        		ObjectOutputStream obi = null;
        		ByteArrayOutputStream bai = null;
        		try
        		{
        			bai = new ByteArrayOutputStream();
        			obi = new ObjectOutputStream(bai);
        			obi.writeObject(obj);
        			byte[] byt = bai.toByteArray();
        			return byt;
        		}
        		catch (IOException e)
        		{
        			e.printStackTrace();
        		}
        		return null;
        	}
        
        	private Object deserizlize(byte[] byt)
        	{
        		ObjectInputStream oii = null;
        		ByteArrayInputStream bis = null;
        		bis = new ByteArrayInputStream(byt);
        		try
        		{
        			oii = new ObjectInputStream(bis);
        			Object obj = oii.readObject();
        			return obj;
        		}
        		catch (Exception e)
        		{
        			e.printStackTrace();
        		}
        		return null;
        	}
        
        }
        
      3. 检验:
        [guest@TFW-CENT6-LT ~]$ redis-cli -a redis
        127.0.0.1:6379> get user.0
        "\xac\xed\x00\x05sr\x00Ptfw.integration_demo._04_spring_web_mvc._02_crud._01_basic_jdbc_crud.entity.User\x00\x00\x00\x00\x00\x00\x00\x01\x02\x00\x05L\x00\x06bYStatt\x00\x10Ljava/lang/Byte;L\x00\x05itgIdt\x00\x13Ljava/lang/Integer;L\x00\astrNamet\x00\x12Ljava/lang/String;L\x00\tstrPasswdq\x00~\x00\x03L\x00\tstrRemarkq\x00~\x00\x03xpsr\x00\x0ejava.lang.Byte\x9cN`\x84\xeeP\xf5\x1c\x02\x00\x01B\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x01sr\x00\x11java.lang.Integer\x12\xe2\xa0\xa4\xf7\x81\x878\x02\x00\x01I\x00\x05valuexq\x00~\x00\x06\x00\x00\x00\x00t\x00\x04roott\x00\x06passwdt\x00\x0bSuper user."
        127.0.0.1:6379> exit
        [guest@TFW-CENT6-LT ~]$
        
        由此可知“tfw.integration_demo._04_spring_web_mvc._02_crud._01_basic_jdbc_crud.entity.User”型对象已存入 redis 。
  2. Memcached :
    一种不支持磁盘存储的 Key-Value 型内存数据库。
    主页:http://memcached.org
    1. 服务器端:
      1. 下载:
        [typhoon@TFW-CENT6-LT to_test.memcached]$ axel http://memcached.org/files/memcached-1.4.36.tar.gz -n 10 -o memcached-1.4.36.tar.gz
        初始化下载: http://memcached.org/files/memcached-1.4.36.tar.gz
        File size: 399047 bytes
        打开输出文件 memcached-1.4.36.tar.gz
        开始下载
        
        [  0%]  .......... .......... .......... .......... ..........  [  90.9KB/s]
        [ 12%]  .......... .......... .......... .......... ..........  [ 132.8KB/s]
        [ 25%]  .......... .......... .........
        连接 0 结束
                ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,. .......... .
        连接 5 结束
                ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,.........  [ 149.5KB/s]
        [ 38%]  ..
        连接 1 结束
                ,,........ ...
        连接 4 结束
                ,,,,,,,,,, ,,,....... .......... .......... ..........  [  67.2KB/s]
        [ 51%]  .......... .......... .......... .......... ..........  [  49.3KB/s]
        [ 64%]  .......... ....
        连接 2 结束
                ,,,,,,,,,, ,,,,...... .......... .....
        连接 7 结束
                ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,..... ..........  [  29.7KB/s]
        [ 76%]  ........
        连接 8 结束
                ,,,,,,,,.. .......... .......... .......... ..
        连接 6 结束
                ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,,,,,,,,, ,,........  [  13.4KB/s]
        [ 89%]  .......... ....
        连接 9 结束
                ,,,,,,,,,, ,,,,...... .......... .........
        
        389.7 千字节 已下载,用时 43 秒。(9.02 千字节/秒)
        [typhoon@TFW-CENT6-LT to_test.memcached]$
        [typhoon@TFW-CENT6-LT to_test.memcached]$ ls
        memcached-1.4.36.tar.gz
        [typhoon@TFW-CENT6-LT to_test.memcached]$
      2. 编译:
        [typhoon@TFW-CENT6-LT to_test.memcached]$ tar zxvf memcached-1.4.36.tar.gz
        memcached-1.4.36/                                                               
        memcached-1.4.36/config.guess                                                   
        memcached-1.4.36/assoc.h                                                        
        ……
        ……
        ……
        memcached-1.4.36/depcomp
        memcached-1.4.36/configure
        memcached-1.4.36/Makefile.in
        [typhoon@TFW-CENT6-LT to_test.memcached]$ ls
        memcached-1.4.36  memcached-1.4.36.tar.gz
        [typhoon@TFW-CENT6-LT to_test.memcached]$ cd memcached-1.4.36
        [typhoon@TFW-CENT6-LT memcached-1.4.36]$ ./configure --prefix=/opt/memcached;echo $?;
        checking build system type... x86_64-pc-linux-gnu                            
        checking host system type... x86_64-pc-linux-gnu                             
        checking for a BSD-compatible install... /usr/bin/install -c                 
        ……
        ……
        ……
        config.status: creating doc/Makefile
        config.status: creating config.h
        config.status: executing depfiles commands
        0
        [typhoon@TFW-CENT6-LT memcached-1.4.36]$ make;echo $?;                       
        make  all-recursive                                                          
        make[1]: Entering directory `/home/typhoon/123/download/soft.tmp/to_test.memcached/memcached-1.4.36'                                                
        Making all in doc                                                               
        ……
        ……
        ……
        gcc -std=gnu99  -g -O2 -pthread -pthread -Wall -Werror -pedantic -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -fno-strict-aliasing   -o timedrun timedrun.o  -levent -lrt
        make[2]: Leaving directory `/home/typhoon/123/download/soft.tmp/to_test.memcached/memcached-1.4.36'
        make[1]: Leaving directory `/home/typhoon/123/download/soft.tmp/to_test.memcached/memcached-1.4.36'
        0
        [typhoon@TFW-CENT6-LT memcached-1.4.36]$
      3. 安装:
        [typhoon@TFW-CENT6-LT memcached-1.4.36]$ su -c "make install";echo $?;
        密码:
        make  install-recursive
        make[1]: Entering directory `/home/typhoon/123/download/soft.tmp/to_test.memcached/memcached-1.4.36'
        Making install in doc
        ……
        ……
        ……
        make[3]: Leaving directory `/home/typhoon/123/download/soft.tmp/to_test.memcached/memcached-1.4.36'
        make[2]: Leaving directory `/home/typhoon/123/download/soft.tmp/to_test.memcached/memcached-1.4.36'
        make[1]: Leaving directory `/home/typhoon/123/download/soft.tmp/to_test.memcached/memcached-1.4.36'
        0
        [typhoon@TFW-CENT6-LT memcached-1.4.36]$
      4. 配置:
        1. 环境变量:
          [root@TFW-CENT6-LT ~]# vi /etc/profile.d/tfw_10_memcached.sh
          [root@TFW-CENT6-LT Redis]# cat /etc/profile.d/tfw_10_memcached.sh
          #!/bin/sh
          #	Version:	2017-04-04_10-46
          #	For:	Memcached 1.4.36
          export MEMCACHED_HOME=/opt/memcached;
          export PATH=$PATH:$MEMCACHED_HOME/bin;
          [root@TFW-CENT6-LT ~]#
          
        2. 帮助页:
          1. 在 /etc/man.config 末尾追加:
            # Otherwise the database will be updated.
            #
            #MAKEWHATISDBUPDATES    n
            
            # TFW:
            MANPATH /opt/memcached/share/man
            
          2. 验证:
            [typhoon@TFW-CENT6-LT to_test.memcached]$ man memcached
            MEMCACHED(1)                                                      MEMCACHED(1)
            
            NAME
                   memcached - high-performance memory object caching system
            
            SYNOPSIS
            ……
            ……
            ……
            :q
            [typhoon@TFW-CENT6-LT to_test.memcached]$
            
        3. 服务控制脚本:
          1. 编写服务控制脚本“/etc/rc.d/init.d/tfw_mcchd”:
            #! /bin/sh
            
            # chkconfig:  35 96 04
            # description: Memcached service script.
            
            # Version:
            #	2017-04-04_14-04
            # By:
            #	Typhoon.Free.Wolf.
            
            # ========================================
            # Customized values:
            	SVC_NAME="Memcached";
            	START_WAIT_SECONDS=1;
            	STOP_WAIT_SECONDS=1;
            # ========================================
            # Customized variables:
            	APP_HOME="/opt/memcached";
            	APP_USER="typhoon";
            	APP_PORT=6666;
            	# PROC_FILTER_CMD="ps aux | grep -v \"grep\" | grep \"$APP_HOME/bin/memcached\";";
            	# PROC_FILTER_CMD="ps aux";
            # ========================================
            # Functions with customized inner content:
            	_status() {
            		# echo "$PROC_FILTER_CMD";
            		# $("$PROC_FILTER_CMD");
            		# `"$PROC_FILTER_CMD"`;
            		ps aux | grep -v "grep" | grep "$APP_HOME/bin/memcached";
            		return $?;
            	}
            
            	_start() {
            		"$APP_HOME/bin/memcached" -d -m 256 -u "$APP_USER" -p $APP_PORT -c 1024;
            		return $?;
            	}
            
            	_stop() {
            		kill $(ps aux | grep -v "grep" | grep "$APP_HOME/bin/memcached" | gawk '{ print $2 }');
            		return $?;
            	}
            # ========================================
            # Static common part.
            	……
            	……
            	……
            # ========================================
            
          2. 启停验证:
            [root@TFW-CENT6-LT ~]# chmod u+x /etc/rc.d/init.d/tfw_mcchd
            [root@TFW-CENT6-LT ~]# service tfw_mcchd start
            Service [ Memcached ] starting...
            typhoon   8728  0.0  0.0 341892  1180 ?        Ssl  22:57   0:00 /opt/memcached/bin/memcached -d -m 256 -u typhoon -p 6666 -c 1024
            Running, successfully started.
                                                                       [确定]
            [root@TFW-CENT6-LT ~]# service tfw_mcchd stop
            Service [ Memcached ] stopping...
            typhoon   8728  0.0  0.0 341892  1180 ?        Ssl  22:57   0:00 /opt/memcached/bin/memcached -d -m 256 -u typhoon -p 6666 -c 1024
            Not running, successfully stopped.
                                                                       [确定]
            [root@TFW-CENT6-LT ~]# service tfw_mcchd restart
            Service [ Memcached ] stopping...
            Not running / already stopped, unable to stop again!
                                                                       [PASSED]
            Service [ Memcached ] starting...
            typhoon   8784  0.0  0.0 341892  1176 ?        Ssl  22:57   0:00 /opt/memcached/bin/memcached -d -m 256 -u typhoon -p 6666 -c 1024
            Running, successfully started.
                                                                       [确定]
            [root@TFW-CENT6-LT ~]#
            
          3. 访问验证:
            [guest@TFW-CENT6-LT ~]$ telnet 127.0.0.1 6666
            Trying 127.0.0.1...
            Connected to 127.0.0.1.
            Escape character is '^]'.
            set a 0 0 6
            测试
            STORED
            get a
            VALUE a 0 6
            测试
            END
            quit
            Connection closed by foreign host.
            [guest@TFW-CENT6-LT ~]$
            
    2. Java 客户端:
      1. 下载:
        [typhoon@TFW-CENT6-LT to_test.memcached]$ wget https://cloud.github.com/downloads/gwhalin/Memcached-Java-Client/java_memcached-release_2.6.6.zip
        --2017-04-04 23:22:00--  https://cloud.github.com/downloads/gwhalin/Memcached-Java-Client/java_memcached-release_2.6.6.zip
        正在解析主机 cloud.github.com... 54.192.75.89, 54.192.75.144, 54.192.75.113, ...
        正在连接 cloud.github.com|54.192.75.89|:443... 已连接。
        已发出 HTTP 请求,正在等待回应... 200 OK
        长度:197142 (193K) [.zip]
        正在保存至: “java_memcached-release_2.6.6.zip”
        
        100%[======================================>] 197,142      320K/s   in 0.6s
        
        2017-04-04 23:22:02 (320 KB/s) - 已保存 “java_memcached-release_2.6.6.zip” [197142/197142])
        
        [typhoon@TFW-CENT6-LT to_test.memcached]$ ls
        java_memcached-release_2.6.6.zip  memcached-1.4.36  memcached-1.4.36.tar.gz
        [typhoon@TFW-CENT6-LT to_test.memcached]$
        
      2. 使用:
        1. 解压,将 jar 文件加入构建路径;构建路径中已有 commons-pool-*.jar ,所以 commons-pool-1.5.6.jar 不必添加。
        2. tfw.integration_demo._07_concurrency._02_memcached.MemcachedTestcase
          ……
          public class MemcachedTestcase
          {
          
          	private MemCachedClient mcc = new MemCachedClient();
          
          	@Before
          	// @Test
          	public void init()
          	{
          		// Define servers.
          		String[] servers = { "127.0.0.1:6666" };
          
          		// Define server weights.
          		Integer[] weights = { 3 };
          
          		// Socket pool.
          		SockIOPool pool = SockIOPool.getInstance();
          		{
          			pool.setServers(servers);
          			pool.setWeights(weights);
          
          			// Some TCP settings:
          			// 1. Disable nagle.
          			pool.setNagle(false);
          			// 2. Read timeout to 3 secs.
          			pool.setSocketTO(3000);
          			// 3. No timeout for connecting.
          			pool.setSocketConnectTO(0);
          
          			// Initialization:
          			pool.initialize();
          		}
          
          		mcc = new MemCachedClient();
          	}
          
          	@Test
          	public void test()
          	{
          		mcc.set("key_a", "ABCDEFGHIJKLMN");
          		mcc.set("user.0", new User(0, "root", "passwd", (byte) 1, "Super user."));
          		mcc.set(null, "CCC");
          		mcc.set("key_d", null);
          		System.out.println(mcc.get("key_a"));
          		System.out.println(mcc.get("user.0"));
          		System.out.println(mcc.get(null));
          		System.out.println(mcc.get("key_d"));
          	}
          
          }
          
      3. 验证:
        [guest@TFW-CENT6-LT ~]$ telnet 127.0.0.1 6666
        Trying 127.0.0.1...
        Connected to 127.0.0.1.
        Escape character is '^]'.
        get user.0
        VALUE user.0 0 375
        ��srPtfw.integration_demo._04_spring_web_mvc._02_crud._01_basic_jdbc_crud.entity.UserLbYStattLjava/lang/Byte;LitgIdtLjava/lang/Integer;LstrNametLjava/lang/String;L     strPasswdq~L    strRemarkq~xpsrjava.lang.Byte�N`��P�Bvaluexrjava.lang.Number���
               ���xpsrjava.lang.Integer⠤���8Ivaluexq~troottpasswdt
                                                                  Super user.
        END
        quit
        Connection closed by foreign host.
        [guest@TFW-CENT6-LT ~]$
        
        由此可知“tfw.integration_demo._04_spring_web_mvc._02_crud._01_basic_jdbc_crud.entity.User”型对象已存入 memcached 。