真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

21.18redis慢查詢?nèi)罩?/h1>

21.18 redis慢查詢?nèi)罩?

編輯配置文件/etc/redis.conf
針對(duì)慢查詢?nèi)罩?,可以設(shè)置兩個(gè)參數(shù),一個(gè)是執(zhí)行時(shí)長(zhǎng),單位是微秒,另一個(gè)是慢查詢?nèi)罩镜拈L(zhǎng)度。當(dāng)一個(gè)新的命令被寫(xiě)入日志時(shí),最老的一條會(huì)從命令日志隊(duì)列中被移除。
slowlog-log-slower-than 1000 //單位ms,表示慢于1000ms則記錄日志
slowlog-max-len 128 //定義日志長(zhǎng)度,表示最多存128條
slowlog get //列出所有的慢查詢?nèi)罩?br />slowlog get 2 //只列出2條
slowlog len //查看慢查詢?nèi)罩緱l數(shù)

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供察布查爾錫伯網(wǎng)站建設(shè)、察布查爾錫伯做網(wǎng)站、察布查爾錫伯網(wǎng)站設(shè)計(jì)、察布查爾錫伯網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、察布查爾錫伯企業(yè)網(wǎng)站模板建站服務(wù),十余年察布查爾錫伯做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

##redis慢查詢?nèi)罩灸J(rèn)是開(kāi)啟的: [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í)行時(shí)常修改為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)境下,查詢都會(huì)超過(guò)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存儲(chǔ)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配置文件對(duì)應(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

1443702394

i44nunao0g3o7vf2su0hnc5440
命令行連接redis,也可以查看到該key以及對(duì)應(yīng)的值
如果想用php連接redis cluster,需要使用predis擴(kuò)展
安裝方法類似phpredis,predis擴(kuò)展地址https://github.com/nrk/predis

21.21 redis主從配置

為了節(jié)省資源,我們可以在一臺(tái)機(jī)器上啟動(dòng)兩個(gè)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è)置主的密碼
啟動(dòng)之前不要忘記創(chuàng)建新的dir目錄
redis-server /etc/redis2.conf
測(cè)試:在主上創(chuàng)建新的key,在從上查看
注意:redis主從和mysql主從不一樣,redis主從不用事先同步數(shù)據(jù),它會(huì)自動(dòng)同步過(guò)去

[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)罩?
網(wǎng)頁(yè)鏈接:http://weahome.cn/article/cpjsso.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部