LNMP+Redis

redisphp

優勢:支持數據的永久存儲。比memcache好。還支持不少類型的數據。html

常常訪問的數據就放入redis,由於它和memcache同樣,默認從內存讀取,會很快!mysql

客戶端訪問網站"輸入"數據--->redis先存入內存--->而後再存入硬盤實現永久存儲。
客戶端訪問網站"查找"數據--->網站從redis裏找,若是找到就直接返回給客戶端。若是找不到就再到硬盤裏找,到/var/www/html/裏找,到數據庫裏找。找到後,先放入內存,以後再返回給客戶端。nginx

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

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

關係數據庫管理系統
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 ... 裏面有這個軟件包json

# history -c 清空歷史緩存
# rpm -q gcc 查看是否安裝了依賴包gcc,若是沒有安裝,就yum -y install gcc
gcc-4.8.5-16.el7.x86_64 若是安裝了,會顯示gcc這個軟件的版本信息vim

# tar -zxvf redis-4.0.8.tar.gz 解包
# ls
redis-4.0.8 目錄下會產生一個同名的文件夾
redis-4.0.8.tar.gz
... ...windows

# 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-configchecking for grep that handles long lines and -e... /usr/bin/grepchecking for egrep... /usr/bin/grep -Echecking for a sed that does not truncate output... /usr/bin/sedchecking for cc... nochecking for gcc... noconfigure: error: in `/root/redis2/lnmp/phpredis-2.2.4':configure: error: no acceptable C compiler found in $PATHSee `config.log' for more details

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息