1. Build memcached Service
NoSQL Memory-based storage (includes: MEMCACHED;REDIS;MONGODB)
[memcached Memory database, reboot, shutdown data loss pre-allocated memory, faster]
[Redis memory-based, persistent storage, data type more]
Yum-y Install memcached.x86_64 telnet
Systemctl start memcached
Netstat-anptu | grep Mem (port number: 11211)
/etc/sysconfig/memcached (config file)
Because there is no client connection database tool, you need to use Telnet
Telnet 127.0.0.1 11211
Set name 0 3 #定义变量, name of variable
0 represents uncompressed 180 data in memory only 180s 3 characters in size
PLJ//input variable value, value PLJ
STORED
Get name//Get the value of the variable
VALUE name 0 3//output result
Plj
END
Add myname 0 180 10//new, MyName does not exist then add, presence Error
Set MyName 0 180 10//Add or Replace variable
Replace MyName 0 180 10//replacement, error if myname not present
Get myname//Read variable
Append myname 0 180 10//Append data to the variable
Delete myname//Remove variable
Stats//View status
Flush_all//Clear All
Quit//Sign Out
Memcached is not connected to the database ability, need to expand the package, just like PHP to connect mariadb, so need to install
Yum List | grep mem
Yum-y Install Php-pecl-memcache
Systemctl Restart Php-fpm.service
CP lnmp_soft/html/mem.php/usr/local/nginx/html/#预先准备好的php页面
Client testing: Firefox http://192.168.4.5/mem.php
Session information, stored on the server side, save user name, password and other information
Cookie: Client information, sent by the server to the client, stored in a file on the client, including SessionID,
Account name, expiration time, path, and domain.
2, Tomcat+session
Allow Tomcat to read and write user information (session) on memcached
WEB1,WEB2 do the same
[Email protected] ~]# CD lnmp_soft/session/
[email protected] session]# CP context.xml/usr/local/tomcat/conf/#预先做好的配置文件
[email protected] session]# CP *.jar/usr/local/tomcat/lib/#让Java能够连接memcached
[Email protected] ~]# vim/usr/local/tomcat/conf/context.xml #告诉tomcat memcached where
Memcachednodes= "mem1:192.168.2.5:11211" #要保持两个web的memcached的名字一致
[Email protected] ~]#/usr/local/tomcat/bin/shutdown.sh
[Email protected] ~]#/usr/local/tomcat/bin/startup.sh
Systemctl start memcached
3, source installation Redis cache service
[Email protected]]# TAR-XF redis-3.0.6.tar.gz
[Email protected] redis-3.0.6]# CD redis-3.0.6/
[[email protected] redis-3.0.6]# yum-y install GCC
[[email protected] redis-3.0.6]# make
[[email protected] redis-3.0.6]# make install
[Email protected] redis-3.0.6]# CD utils/#该目录下官方自带脚本
[Email protected] utils]#./install_server.sh
Selected Config:
port:6379 #默认端口
Config file:/etc/redis/6379.conf #配置文件
Log file:/var/log/redis_6379.log #日志文件
Data dir:/var/lib/redis/6379 #数据文件
Executable:/usr/local/bin/redis-server #Redis服务器软件存储路径
Cli executable:/USR/LOCAL/BIN/REDIS-CLI
[Email protected] utils]# Redis-benchmark #性能测试
1) Use the REDIS-CLI Client tool to connect to the Redis server and test the cache database.
Test Ping
Command Help (SET)
2) Common operation guide for hash tables
3) List (using: all history)
4) TTL variable (-1 never expires-2 has expired) #查看变量过期时间
Specific commands you can search the Internet, not listed here
4. Configuring Redis master-Slave server
4.1 Modifying the primary server/etc/redis/6379.conf configuration file
Save 1 #900s检查一次 1 data changes are saved
Save #300s检查一次 10 Data changes
Save 10000 #60s Check once 10,000 data changes are saved
4.2 Primary Server configuration:
[Email protected] ~]# vim/etc/redis/6379.conf
Requirepass 123456 #设置主服务器密码
/etc/init.d/redis_6379 Restart #重启服务
After the password is set, the service cannot be turned off again after reloading
vim/etc/init.d/redis_6379 #打开脚本设置
CLIEXEC=/USR/LOCAL/BIN/REDIS-CLI #开关服务变量
$CLIEXEC-P $REDISPORT-a 123456 shutdown #加入设置的密码
[Email protected] ~]# redis-cli-a 123456 #输入密码登陆
4.3 Configuration from server:
[Email protected] ~]# vim/etc/redis/6379.conf
slaveof 192.168.2.100 6379 #主服务器的IP和端口
Masterauth 123456 #连接主服务器的密码
/etc/init.d/redis_6379 restart
And finally set the password for the login database.
Linux Operation Learning------Memcached/redis