LNMP+Redis

redis

优点:支持数据的永久存储。比memcache好。还支持很多类型的数据。

经常访问的数据就放入redis,因为它和memcache一样,默认从内存读取,会很快!

客户端访问网站"输入"数据--->redis先存入内存--->然后再存入硬盘实现永久存储。
客户端访问网站"查找"数据--->网站从redis里找,如果找到就直接返回给客户端。如果找不到就再到硬盘里找,到/var/www/html/里找,到数据库里找。找到后,先放入内存,之后再返回给客户端。

配置文件: /etc/redis/6379.conf
能"执行命令"的"可执行文件":/etc/init.d/redis_6379

# /etc/init.d/redis_6379 start
# /etc/init.d/redis_6379 stop
# /etc/init.d/redis_6379 status
###########################################################
RDBMS

关系数据库管理系统
Relational Database Management System
按照预先设置的组织结构,将数据存储到物理介质上。数据之间可以做关联操作。
###########################################################
真机传redis文件夹给50
# scp -r '/root/桌面/公共ftp所有资源/软件包集合/redis2' root@192.168.4.50:/root/

# systemctl stop mysqld 先关闭mysql服务,如果已经启动的话。
# cd redis/ 进入真机传过来的redis文件夹
# ls
redis-4.0.8.tar.gz ... 里面有这个软件包

# history -c 清空历史缓存
# rpm -q gcc 查看是否安装了依赖包gcc,如果没有安装,就yum -y install gcc
gcc-4.8.5-16.el7.x86_64 如果安装了,会显示gcc这个软件的版本信息

# tar -zxvf redis-4.0.8.tar.gz 解包
# ls
redis-4.0.8 目录下会产生一个同名的文件夹
redis-4.0.8.tar.gz
... ...

# cd redis-4.0.8/ 进入这个同名目录里面
# ls
00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README.md runtest-cluster src

# make
# make install

# cd /root/redis2/redis-4.0.8
# ls 会发现有个叫utils的文件夹
00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README.md runtest-cluster src

# ls /root/redis2/redis-4.0.8/utils/ 同名目录里有个utlis的文件夹,里面有初始化的脚本
install_server.sh ... 这是初始化的脚本

# cd /root/redis2/redis-4.0.8
# ./utils/install_server.sh 执行这个初始化的脚本,一路回车,让它默认设置就行
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 默认端口号
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 默认配置文件名
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 默认日志名
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 默认存放数据的目录
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 可执行文件的路径
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 可执行文件
Cli Executable : /usr/local/bin/redis-cli 提供redis-cli这个命令的可执行文件
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server... 安装后,它会默认运行这个程序
Installation successful! 显示安装成功
######################################################################
# netstat -tunlp | grep :6379 可以查到端口号pid是6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 5224/redis-server 1

# /etc/init.d/redis_6379 stop 用脚本来停止服务。
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped

# netstat -tunlp | grep :6379 停止服务后,查不到pid号

# /etc/init.d/redis_6379 status 用脚本来查看状态
cat: /var/run/redis_6379.pid: 没有那个文件或目录
Redis is running () 这里虽然显示运行,但括号里没有pid号,说明服务没启动。之所以有显示运行,是脚本决定的。

# /etc/init.d/redis_6379 start 用脚本来运行服务。
Starting Redis server...

# /etc/init.d/redis_6379 status 用脚本来查看状态
Redis is running (5312) 已经运行了,所以括号里有pid号


# which redis-cli 查看是哪个程序提供了redis-cli这个命令
/usr/local/bin/redis-cli 提供redis-cli这个命令的可执行文件
################################################################################
# redis-cli --help 查看redis-cli这个命令的帮助信息
redis-cli 4.0.8

Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
-h <hostname> Server hostname (default: 127.0.0.1). 这里默认主机是本机127.0.0.1
-p <port> Server port (default: 6379). 这里默认端口号是6379
-s <socket> Server socket (overrides hostname and port).
-a <password> Password to use when connecting to the server.
-u <uri> Server URI.
-r <repeat> Execute specified command N times.
-i <interval> When -r is used, waits <interval> seconds per command.
It is possible to specify sub-second times like -i 0.1.
-n <db> Database number.
-x Read last argument from STDIN.
-d <delimiter> Multi-bulk delimiter in for raw formatting (default: \n).
-c Enable cluster mode (follow -ASK and -MOVED redirections).
--raw Use raw formatting for replies (default when STDOUT is
not a tty).
--no-raw Force formatted output even when STDOUT is not a tty.
--csv Output in CSV format.
--stat Print rolling stats about server: mem, clients, ...
--latency Enter a special mode continuously sampling latency.
If you use this mode in an interactive session it runs
forever displaying real-time stats. Otherwise if --raw or
--csv is specified, or if you redirect the output to a non
TTY, it samples the latency for 1 second (you can use
-i to change the interval), then produces a single output
and exits.
--latency-history Like --latency but tracking latency changes over time.
Default time interval is 15 sec. Change it using -i.
--latency-dist Shows latency as a spectrum, requires xterm 256 colors.
Default time interval is 1 sec. Change it using -i.
--lru-test <keys> Simulate a cache workload with an 80-20 distribution.
--slave Simulate a slave showing commands received from the master.
--rdb <filename> Transfer an RDB dump from remote server to local file.
--pipe Transfer raw Redis protocol from stdin to server.
--pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
no reply is received within <n> seconds.
Default timeout: 30. Use 0 to wait forever.
--bigkeys Sample Redis keys looking for big keys.
--hotkeys Sample Redis keys looking for hot keys.
only works when maxmemory-policy is *lfu.
--scan List all keys using the SCAN command.
--pattern <pat> Useful with --scan to specify a SCAN pattern.
--intrinsic-latency <sec> Run a test to measure intrinsic system latency.
The test will run for the specified amount of seconds.
--eval <file> Send an EVAL command using the Lua script at <file>.
--ldb Used with --eval enable the Redis Lua debugger.
--ldb-sync-mode Like --ldb but uses the synchronous Lua debugger, in
this mode the server is blocked and script changes are
are not rolled back from the server memory.
--help Output this help and exit.
--version Output version and exit.

Examples:
cat /etc/passwd | redis-cli -x set mypasswd
redis-cli get mypasswd
redis-cli -r 100 lpush mylist x
redis-cli -r 100 -i 1 info | grep used_memory_human:
redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
redis-cli --scan --pattern '*:12345*'

(Note: when using --eval the comma separates KEYS[] from ARGV[] items)

When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands
and settings.
#######################################################
redis-cli的使用

# redis-cli
127.0.0.1:6379> 出现这个提示,说明进入到了redis里面了
127.0.0.1:6379> set key value [EX seconds] [PX milliseconds] [NX|XX] 输入set,它会自动出现后面的提示
127.0.0.1:6379> get key 输入get,它会自动出现后面的提示
127.0.0.1:6379> keys pattern 输入key,它会自动出现后面的提示

# redis-cli
127.0.0.1:6379> set name bob
OK
127.0.0.1:6379> get name
"bob"
127.0.0.1:6379> get age
(nil)
127.0.0.1:6379> keys *
1) "name"
127.0.0.1:6379> get name
"bob"
127.0.0.1:6379> exit
#################################################################
# ls /var/lib/redis/6379/ 这是默认用来存储永久数据的文件
dump.rdb

# redis-cli
127.0.0.1:6379> select 1 进入库1
OK
127.0.0.1:6379[1]> select 0 可看到当前库是1, 进入库0
OK
127.0.0.1:6379> keys * 当前库是0时,无提示
1) "haha"
2) "age"
3) "name"
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> keys *
(empty list or set)
127.0.0.1:6379[1]>


127.0.0.1:6379> select 0
OK
127.0.0.1:6379> keys ?
(empty list or set)
127.0.0.1:6379> keys ???
1) "age"
127.0.0.1:6379> keys ????
1) "haha"
2) "name"
127.0.0.1:6379> keys a
(empty list or set)
127.0.0.1:6379> keys a??
1) "age"
127.0.0.1:6379> keys n???
1) "name"
127.0.0.1:6379> keys *
1) "haha"
2) "age"
3) "name"
127.0.0.1:6379> get name
"bob"
127.0.0.1:6379> set name jim
OK
127.0.0.1:6379> get name
"jim"
127.0.0.1:6379> exists sex class
(integer) 0
127.0.0.1:6379> exists name
(integer) 1
127.0.0.1:6379> set sex lili
OK
127.0.0.1:6379> set sex school

127.0.0.1:6379> keys *
1) "age"
2) "haha"
3) "sex"
4) "name"
127.0.0.1:6379> type sex 用set赋值时,默认都是字符类型的
string
127.0.0.1:6379> get age
"19"
127.0.0.1:6379> set age 20
OK
127.0.0.1:6379> type age 用set赋值时,默认都是字符类型的
string

127.0.0.1:6379> ttl sex
(integer) -1 用ttl查看变量的有效期。 -1代表永不过期。默认都是永不过期

127.0.0.1:6379> ttl age
(integer) -1
127.0.0.1:6379> expire age 20 手动更改变量age的有效期为20秒。单位是秒
(integer) 1
127.0.0.1:6379> ttl age
(integer) 17 有效期还有17秒
127.0.0.1:6379> ttl age
(integer) 16 有效期还有16秒
127.0.0.1:6379> ttl age -2代表变量过期,它已经删除了这个变量
(integer) -2


127.0.0.1:6379> keys *
1) "haha"
2) "sex"
3) "name"
127.0.0.1:6379> del haha 手动删除变量haha
(integer) 1
127.0.0.1:6379> keys *
1) "sex"
2) "name"

127.0.0.1:6379> flushall 清空redis内存服务器里的所有数据!谨慎使用这个命令!
OK
127.0.0.1:6379> flushdb
OK


127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set age 20
OK
127.0.0.1:6379> get age
"20"
127.0.0.1:6379> keys *
1) "age"
127.0.0.1:6379> save
OK
127.0.0.1:6379> shutdown 停止redis服务
not connected> exit
[root@client50 ~]# ss -tunlp | grep :6379 查不到端口号了
# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit

# /etc/init.d/redis_6379 stop 用脚本来停止服务
# /etc/init.d/redis_6379 start
Starting Redis server...

# redis-cli shutdown 用命令来停止服务,其实用脚本来停止服务也是调用了这条命令来停服务的。但没有命令来启动服务
# ss -tunlp | grep :6379
###################################################
# redis-cli
127.0.0.1:6379> select 1 进入库1
OK
127.0.0.1:6379[1]> keys * 当前在库1,里面是空的,没有变量
(empty list or set)

127.0.0.1:6379[1]> select 0 进入库0
OK
127.0.0.1:6379> keys * 当前在库0,里面有个变量age
1) "age"

127.0.0.1:6379> move age 1 用move来移动库0里的变量age到库1里去
(integer) 1

127.0.0.1:6379> keys * 当前在库0,移动后已经是空的了,没有原来的变量age了
(empty list or set)

127.0.0.1:6379> select 1 进入库1
OK
127.0.0.1:6379[1]> keys * 当前在库1,移动后有了变量age
1) "age"
###################################################
# vim /etc/redis/6379.conf

:set nu 显示行号
12 # 1k => 1000 bytes
13 # 1kb => 1024 bytes
14 # 1m => 1000000 bytes
15 # 1mb => 1024*1024 bytes
16 # 1g => 1000000000 bytes
17 # 1gb => 1024*1024*1024 bytes
18 #
19 # units are case insensitive so 1GB 1Gb 1gB are all the same.
####################################################################
改redis的端口号为6350

# cp /etc/redis/6379.conf /root/ 先备份配置文件到root下

# vim /etc/redis/6379.conf
93 port 6350 修改93行的端口号为6350

# ss -tunlp | grep :6379 当前6379端口号还在运行
tcp LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=5842,fd=6))

# /etc/init.d/redis_6379 stop 用脚本来停止服务
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped

# /etc/init.d/redis_6379 start 用脚本来启动服务
Starting Redis server...

# ss -tunlp | grep :6350 修改后的6350端口号正在运行
tcp LISTEN 0 128 127.0.0.1:6350 *:* users:(("redis-server",pid=6462,fd=6))

# redis-cli 这个命令默认还用6379端口号运行,所以无法登陆
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit

# redis-cli -p 6350 加-p来指定端口号为6350
127.0.0.1:6350> keys *
(empty list or set)
127.0.0.1:6350> select 1 进入库1
OK
127.0.0.1:6350[1]> keys * 之前库1的数据还有
1) "age"
127.0.0.1:6350[1]> exit
###############################################################
# /etc/init.d/redis_6379 stop 改了端口后,用脚本不能停止服务了
Stopping ...
Could not connect to Redis at 127.0.0.1:6379: Connection refused 它显示现在想要连接的端口还是6379来停止
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
^C

# /etc/init.d/redis_6379 status 查看状态时,还是运行的
Redis is running (6462)

# redis-cli -p 6350 shutdown 改了端口号后,只能用命令来停止服务

# /etc/init.d/redis_6379 start 改了端口号后,用脚本来启动还是可以的。只是不能用脚本来停止服务而已。
Starting Redis server...
[root@client50 ~]# ss -tunlp | grep :6350
tcp LISTEN 0 128 127.0.0.1:6350 *:* users:(("redis-server",pid=6513,fd=6))

# redis-cli -p 6350 shutdown
###############################################################
改redis的IP

# vim /etc/redis/6379.conf
:set nu
70 bind 192.168.4.50 修改70行,改ip为192.168.4.50。以后连接必须要指定这个ip,否则它默认还是连127.0.0.1,就会连不上了。

备注:如果还想像之前一样不指定ip就能登陆,可是又想改ip,可以这样写:
bind 192.168.4.50 127.0.0.1 可以写多个ip,不同ip之间,有空格!
------------------------------------------------------------------------------------------
# /etc/init.d/redis_6379 start 启动服务
Starting Redis server...

# ss -tunlp | grep :6350 查看状态,端口还是要写修改后的6350
tcp LISTEN 0 128 192.168.4.50:6350 *:* users:(("redis-server",pid=6717,fd=6))

这里显示服务的IP已经变成了192.168.4.50
-------------------------------------------------------------------------------------------
# redis-cli -p 6350 改了服务ip后,登陆时只指定了改后的端口号,是无法进入的。因为没指定改后的IP啊。
Could not connect to Redis at 127.0.0.1:6350: Connection refused 它默认还是连127.0.0.1这个网址
Could not connect to Redis at 127.0.0.1:6350: Connection refused
not connected> exit

# redis-cli -h 192.168.4.50 -p 6350 改了服务ip后,登陆时要指定改后的ip和端口号,2者都要指定,才能进入
192.168.4.50:6350> select 1 进入库1
OK
192.168.4.50:6350[1]> keys * 查看修改IP前,就已经有的变量,发现这些数据都还在
1) "age"
192.168.4.50:6350[1]> exit


# /etc/init.d/redis_6379 stop 改了服务ip后,无法用脚本来停止服务。
Stopping ...
Could not connect to Redis at 127.0.0.1:6379: Connection refused 它显示还在连接127.0.0.1
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
^C

# redis-cli -p 6350 shutdown 改了服务ip后,用命令来停止服务时,只加上改后的端口号是无法停止的。因为没指定改后的IP啊。
Could not connect to Redis at 127.0.0.1:6350: Connection refused 它显示还在连接127.0.0.1

# redis-cli -h 192.168.4.50 -p 6350 shutdown 用命令来加上改后的ip和端口号,2者都要指定!才能停止服务!

# /etc/init.d/redis_6379 start 仍然可以用脚本来启动
Starting Redis server...
##############################################################
设置连接密码 (redis默认不设置密码)

# redis-cli -h 192.168.4.50 -p 6350 shutdown

# vim /etc/redis/6379.conf
501 requirepass 123456 把501行注释去掉,把密码改为123456


# /etc/init.d/redis_6379 start 用脚本开启服务
Starting Redis server...

# ss -tunlp | grep :6350
tcp LISTEN 0 128 192.168.4.50:6350 *:* users:(("redis-server",pid=8049,fd=6))

# ps -C redis-server
PID TTY TIME CMD
8049 ? 00:00:00 redis-server

# redis-cli -h 192.168.4.50 -p 6350 连接时不加密码
192.168.4.50:6350> keys * 会没有权限
(error) NOAUTH Authentication required.
192.168.4.50:6350> ping
(error) NOAUTH Authentication required.
192.168.4.50:6350> auth 123456 输入密码。格式:auth 密码
OK
192.168.4.50:6350> ping 用ping来查看当前是否能正常使用这个服务
PONG

# redis-cli -h 192.168.4.50 -p 6350 -a 123456 连接时加上密码,就用-a
192.168.4.50:6350>

# /etc/init.d/redis_6379 stop 改密码后,无法用脚本停止服务
Stopping ...
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Waiting for Redis to shutdown ...

# redis-cli -h 192.168.4.50 -p 6350 -a 123456 shutdown 改了密码后,要这样停止服务
# ss -tunlp | grep :6350

#################################################################
修改脚本,实现改IP,端口号,密码后,仍然能用脚本来停止服务。

# vim /etc/init.d/redis_6379
43 $CLIEXEC -h 192.168.4.50 -p 6350 -a 123456 shutdown 改43行的命令,改成现在的IP,端口和密码


# /etc/init.d/redis_6379 start 用脚本来启动服务
Starting Redis server...

# ss -tunlp | grep :6350 查看到现在服务已经启动,能找到端口号
tcp LISTEN 0 128 192.168.4.50:6350 *:* users:(("redis-server",pid=8210,fd=6))

# /etc/init.d/redis_6379 stop 可以用脚本来停止服务了,说明修改脚本成功!
Stopping ...
Redis stopped
#############################################################
主机51

也跟50一样,安装redis,改IP,端口和密码


systemctl stop mysqld
# rpm -q gcc
# yum -y install gcc
# tar -zxvf redis-4.0.8.tar.gz
# cd redis-4.0.8/

# make

页面显示如下,比50的显示信息少,但是也安装成功了!
cd src && make all
make[1]: 进入目录“/root/redis2/redis-4.0.8/src”

Hint: It's a good idea to run 'make test' ;)

make[1]: 离开目录“/root/redis2/redis-4.0.8/src”


# make install
cd src && make install
make[1]: 进入目录“/root/redis2/redis-4.0.8/src”

Hint: It's a good idea to run 'make test' ;)

INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: 离开目录“/root/redis2/redis-4.0.8/src”

# cd utils/
# ./install_server.sh 一定要./来执行。一路回车!
...
Starting Redis server... 显示启动服务
Installation successful! 说明安装成功

# ss -tunlp |grep :6379
tcp LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=4809,fd=6))


# /etc/init.d/redis_6379 stop

# vim /etc/redis/6379.conf
70 bind 192.168.4.51 这里写ip是51,也就是本机的主机名数字51
93 port 6351 端口也写51,也就是本机的主机名数字51
501 requirepass 123456 密码123456


# /etc/init.d/redis_6379 start
Starting Redis server...

# ss -tunlp |grep :6351
tcp LISTEN 0 128 192.168.4.51:6351 *:* users:(("redis-server",pid=4963,fd=6))

# redis-cli -h 192.168.4.51 -p 6351 -a 123456
192.168.4.51:6351> keys *
(empty list or set)
192.168.4.51:6351> set x 9
OK
192.168.4.51:6351> keys *
1) "x"
192.168.4.51:6351> get x
"9"
192.168.4.51:6351> exit

# redis-cli -h 192.168.4.51 -p 6351 -a 123456 shutdown
# ss -tunlp |grep :6351

# vim /etc/init.d/redis_6379 改脚本
43 $CLIEXEC -h 192.168.4.51 -p 6351 -a 123456 shutdown


# /etc/init.d/redis_6379 start
Starting Redis server...

# ss -tunlp |grep :6351
tcp LISTEN 0 128 192.168.4.51:6351 *:* users:(("redis-server",pid=5053,fd=6))

# /etc/init.d/redis_6379 stop
Stopping ...
Redis stopped

# ss -tunlp |grep :6351

# /etc/init.d/redis_6379 start
Starting Redis server...

# ss -tunlp |grep :6351
tcp LISTEN 0 128 192.168.4.51:6351 *:* users:(("redis-server",pid=5053,fd=6))
#################################################
给redis开启服务和关闭服务,设置软连接和别名,方便使用。

ln -s /etc/init.d/redis_6379 /sbin/

vim /root/.bashrc
alias start='redis_6379 start'
alias stop='redis_6379 stop'
... ...
#################################################
如果已经先解压,然后进入同名目录,make之后报错了,才想起没有安装gcc!
那么退出目录,删掉已经生成的同名目录,然后再安装gcc,然后再进入目录,make,然后make install就行了!


# /etc/init.d/redis_6379 status
Redis is running (5212) 查看到进程的pid号是5212

# kill -9 5212 用非正常手段杀掉进程5212

# /etc/init.d/redis_6379 start 想用脚本启动进程
/var/run/redis_6379.pid exists, process is already running or crashed 提示pid号已经存在

# rm -rf /var/run/redis_6379.pid 因为不按常规的用进程关掉服务,所以它不会删除相应的pid文件,必须手动删除。

# /etc/init.d/redis_6379 start 用脚本启动进程,成功!
Starting Redis server...
##################################################
了解一下配置文件的配置选项内容,只是看看,先不要改。

:set nu
70 bind 192.168.4.50 设置IP
93 port 6389 设置端口号
102 tcp-backlog 511 tcp连接的总数(已经建立的连接+正在建立的连接)
114 timeout 0 连接超时时间
131 tcp-keepalive 300 长时间连接
137 daemonize yes 守护进程的方式运行
187 databases 16 数据库的个数
172 logfile /var/log/redis_6379.log 日志文件
533 # maxclients 10000 最大连接数
264 dir /var/lib/redis/6379 redis服务的数据库目录
501 requirepass 123456 设置密码


565-572行 是redis清除内存的策略
565 # volatile-lru -> Evict using approximated LRU among the keys with an expire set.
566 # allkeys-lru -> Evict any key using approximated LRU.
567 # volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
568 # allkeys-lfu -> Evict any key using approximated LFU.
569 # volatile-random -> Remove a random key among the ones with an expire set.
570 # allkeys-random -> Remove a random key, any key.
571 # volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
572 # noeviction -> Don't evict anything, just return an error on write operations.

备注:
volatile-lru 最近最少使用(针对设置了ttl的key) volatile(易变的,不稳定的)
allkeys-lru 删除最少使用的key
volatile-random 在设置了ttl的key里随机移除 random(随机的)
allkeys-random 随机移除key
volatile-ttl 移除最近过期的key
noeviction 不删除,写满时报错 no(不)eviction(收回)


560 # maxmemory <bytes> 最大内存
591 # maxmemory-policy noeviction 永远都不清内存。定义使用策略
602 # maxmemory-samples 5 设置的越多,找的就越精准,但是时间也会越长。(只对设置了lru和ttl策略有用)
################################################################
56 作为网站服务器

# /usr/local/mycat/bin/mycat stop
Stopping Mycat-server...
Mycat-server was not running.

# systemctl stop mysqld

# rpm -q httpd 如果装了,还运行了,要停止httpd服务 systemctl stop httpd
未安装软件包 httpd

# hostname lnmp56 改主机名为lnmp56
# exit
登出

真机重新远程
# ssh -X root@192.168.4.56
##############################################
56 安装nginx

# rpm -ivh nginx-1.12.2-10.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:nginx-1.12.2-10 ################################# [100%]

# cp /usr/local/nginx/sbin/nginx /sbin/
# nginx

# ss -tunlp | grep :80
tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=1842,fd=6),("nginx",pid=1841,fd=6))

# echo 123 > /usr/local/nginx/html/a.html
# curl http://localhost/a.html 用curl来访问刚才创建的网页
123

# cat /usr/local/nginx/html/b.php
<?php
echo "hello world";
?>

真机访问http://192.168.4.56/b.php
会发现它并不出现网页,而是跳出来一个是否要下载b.php的提醒,因为我们没有安装php,所以它无法解读这个php网页

# yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm
# ss -tunlp | grep :9000 php-fpm的端口号,发现当前没有运行

# systemctl start php-fpm 启动php-fpm
# ss -tunlp | grep :9000 发现php-fpm的端口号了
tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=2222,fd=0),("php-fpm",pid=2221,fd=0),("php-fpm",pid=2220,fd=0),("php-fpm",pid=2219,fd=0),("php-fpm",pid=2218,fd=0),("php-fpm",pid=2217,fd=6))


# vim /usr/local/nginx/conf/nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi.conf;
71 }

# nginx -s reload

真机访问测试
# firefox http://192.168.4.56/b.php
网页显示hello world
######################################################
# vim /usr/local/nginx/html/link.php
<?php
$redis = new redis();
$redis->connect('192.168.4.50',6350);
$redis->auth("123456"); 50设置了连接密码,所以这里要写。单引号或双引号都行!
$redis->set('school','tarena');
echo $redis->get('redistest');
?>


# which php
/usr/bin/which: no php in (/root/perl5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)

# yum -y install php
# which php
/usr/bin/php

# php -m | grep -i redis 查看php功能模块里是否有,有关redis的模块

firefox http://192.168.4.56/link.php
页面显示一片空白


# yum -y install autoconf automake.noarch
# yum -y install php-devel-5.4.16-42.el7.x86_64.rpm
# cd /root/redis2/lnmp/phpredis-2.2.4
# phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525

yum -y install gcc

# ls /usr/bin/php-config php的配置信息


# ./configure --with-php-config=/usr/bin/php-config
# make install
Installing shared extensions: /usr/lib64/php/modules/ 记住这个放模块的目录,等下改配置文件时要用到

# cd /usr/lib64/php/modules/ 进到这个放模块的目录里,可以看到有个叫redis.so的模块,就是支持redis的模块
# ls
curl.so fileinfo.so json.so phar.so redis.so zip.so

# php -m | grep redis 查看php的所有功能模块,发现已经有了支持redis的模块
redis

# vim /etc/php.ini
这个配置文件,注释是用;分号来表示。
728 extension_dir = "/usr/lib64/php/modules/" 改728行,打开注释,放模块的目录,写刚才提示的目录名称
729 ; On windows:
730 extension = "redis.so" 改729行,打开注释,等号前= 要去掉"_dir",只留extension ,引号里是

# systemctl restart php-fpm
# curl http://192.168.4.56/link.php
##############################################
# ./configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... no
checking for gcc... no
configure: error: in `/root/redis2/lnmp/phpredis-2.2.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

 

posted @ 2019-04-30 22:36  安于夏  阅读(260)  评论(0编辑  收藏  举报