編輯配置文件/etc/redis.conf
針對慢查詢?nèi)罩?,可以設(shè)置兩個參數(shù),一個是執(zhí)行時長,單位是微秒,另一個是慢查詢?nèi)罩镜拈L度。當(dāng)一個新的命令被寫入日志時,最老的一條會從命令日志隊(duì)列中被移除。
slowlog-log-slower-than 1000 //單位ms,表示慢于1000ms則記錄日志
slowlog-max-len 128 //定義日志長度,表示最多存128條
slowlog get //列出所有的慢查詢?nèi)罩?br />slowlog get 2 //只列出2條
slowlog len //查看慢查詢?nèi)罩緱l數(shù)
##redis慢查詢?nèi)罩灸J(rèn)是開啟的: [root@Dasoncheng ~]# vim /etc/redis.conf # The following time is expressed in microseconds, so 1000000 is equivalent # to one second. Note that a negative number disables the slow log, while # a value of zero forces the logging of every command. slowlog-log-slower-than 10000 # There is no limit to this length. Just be aware that it will consume memory. # You can reclaim memory used by the slow log with SLOWLOG RESET. slowlog-max-len 128
這里我們將執(zhí)行時常修改為10微秒,看看效果:
# The following time is expressed in microseconds, so 1000000 is equivalent # to one second. Note that a negative number disables the slow log, while # a value of zero forces the logging of every command. slowlog-log-slower-than 10 ##正常實(shí)驗(yàn)環(huán)境下,查詢都會超過10微秒 # There is no limit to this length. Just be aware that it will consume memory. # You can reclaim memory used by the slow log with SLOWLOG RESET. slowlog-max-len 128 #保存退出 [root@Dasoncheng ~]# killall redis-server [root@Dasoncheng ~]# redis-server /etc/redis.conf [root@Dasoncheng ~]# redis-cli 127.0.0.1:6379> slowlog get ##這里顯示0為1條慢查詢?nèi)罩?1) 1) (integer) 0 2) (integer) 1507942013 3) (integer) 899 4) 1) "COMMAND" 5) "127.0.0.1:40790" 6) "" 127.0.0.1:6379> keys * 1) "k3" 2) "key2" 3) "setc" 4) "hash1" 5) "s1" 6) "lista" 7) "set1" 8) "l1" 9) "setd" 10) "set2" 11) "list" 12) "key10" 13) "setb" 14) "key1" 15) "k2" 16) "sete" 17) "k1" 18) "seta" 19) "set3" 127.0.0.1:6379> get k3 "3" 127.0.0.1:6379> get key2 "200" 127.0.0.1:6379> slowlog get 1) 1) (integer) 3 2) (integer) 1507942047 3) (integer) 58 4) 1) "get" 2) "key2" 5) "127.0.0.1:40790" 6) "" 2) 1) (integer) 2 2) (integer) 1507942031 3) (integer) 29 4) 1) "keys" 2) "*" 5) "127.0.0.1:40790" 6) "" 3) 1) (integer) 1 2) (integer) 1507942021 3) (integer) 22 4) 1) "slowlog" 2) "get" 5) "127.0.0.1:40790" 6) "" 4) 1) (integer) 0 2) (integer) 1507942013 3) (integer) 899 4) 1) "COMMAND" 5) "127.0.0.1:40790" 6) "" 127.0.0.1:6379> slowlog get 2 ##只獲取最近兩條慢查詢?nèi)罩荆?1) 1) (integer) 4 2) (integer) 1507942052 3) (integer) 41 4) 1) "slowlog" 2) "get" 5) "127.0.0.1:40790" 6) "" 2) 1) (integer) 3 2) (integer) 1507942047 3) (integer) 58 4) 1) "get" 2) "key2" 5) "127.0.0.1:40790" 6) "" 127.0.0.1:6379> slowlog len ##顯示所有慢查詢?nèi)罩緱l數(shù); (integer) 6 21.19 php安裝redis擴(kuò)展模塊
cd /usr/local/src wget https://coding.net/u/aminglinux/p/yuanke_centos7/git/raw/master/21NOSQL/phpredis.zip unzip phpredis.zip cd phpredis-develop /usr/local/php-fpm/bin/phpize ./configure --with-php-config=/usr/local/php-fpm/bin/php-config make make install vim /usr/local/php.ini//增加extension=redis.so /usr/local/php-fpm/bin/php -m|grep redis//看是否有redis模塊 重啟php-fpm服務(wù) 21.20 redis存儲session vim /usr/local/php-fpm/etc/php.ini//更改或增加
session.save_handler = "redis"
session.save_path = "tcp://127.0.0.1:6379" 或者apache虛擬主機(jī)配置文件中也可以這樣配置:
php_value session.save_handler " redis"
php_value session.save_path " tcp://127.0.0.1:6379" 或者php-fpm配置文件對應(yīng)的pool中增加:
php_value[session.save_handler] = redis
php_value[session.save_path] = " tcp://127.0.0.1:6379 "
wgt http://study.lishiming.net/.mem_se.txt
mv .mem_se.txt /usr/local/apache2/htdocs/session.php
其中session.php內(nèi)容可以參考https://coding.net/u/aminglinux/p/yuanke_centos7/git/blob/master/21NOSQL/session.php
curl localhost/session.php //結(jié)果類似于1443702394<br><br>1443702394<br><br>i44nunao0g3o7vf2su0hnc5440
命令行連接redis,也可以查看到該key以及對應(yīng)的值
如果想用php連接redis cluster,需要使用predis擴(kuò)展
安裝方法類似phpredis,predis擴(kuò)展地址https://github.com/nrk/predis
為了節(jié)省資源,我們可以在一臺機(jī)器上啟動兩個redis服務(wù)
cp /etc/redis.conf /etc/redis2.conf
vim /etc/redis2.conf //需要修改port,dir,pidfile,logfile
還要增加一行
slaveof 127.0.0.1 6379
如果主上設(shè)置了密碼,還需要增加
masterauth aminglinux>com //設(shè)置主的密碼
啟動之前不要忘記創(chuàng)建新的dir目錄
redis-server /etc/redis2.conf
測試:在主上創(chuàng)建新的key,在從上查看
注意:redis主從和mysql主從不一樣,redis主從不用事先同步數(shù)據(jù),它會自動同步過去
[root@Dasoncheng ~]# vim /etc/redis2.conf [root@Dasoncheng ~]# mkdir /data/redis2 [root@Dasoncheng ~]# redis-server /etc/redis2.conf [root@Dasoncheng ~]# ps aux |grep redis root 6411 0.2 0.2 142920 2284 ? Ssl 08:46 0:02 redis-server 127.0.0.1:6379 root 6498 0.1 0.2 142788 2136 ? Ssl 09:06 0:00 redis-server 127.0.0.1:6333 root 6505 0.0 0.0 112660 964 pts/2 S+ 09:06 0:00 grep --color=auto redis [root@Dasoncheng ~]# redis-cli -h 127.0.0.1 -p 6333 127.0.0.1:6333> keys * 1) "set1" 2) "seta" 3) "key2" 4) "l1" 5) "key10" 6) "lista" 7) "s1" 8) "k1" 9) "k2" 10) "set3" 11) "key1" 12) "k3" 13) "setd" 14) "set2" 15) "sete" 16) "list" 17) "setc" 18) "setb" 19) "hash1"
名稱欄目:21.18redis慢查詢?nèi)罩?/a>
當(dāng)前URL:http://www.rwnh.cn/article30/cpjsso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、用戶體驗(yàn)、移動網(wǎng)站建設(shè)、網(wǎng)站營銷、網(wǎng)站內(nèi)鏈、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)