一、安装
wget http://download.redis.io/releases/redis-6.0.8.tar.gz
tar xzf redis-6.0.8.tar.gz
cd redis-6.0.8
make
make install
(1)第1行可以上redis官网找对应版本安装包地址,然后替换;
(2)make之前需要确定安装了gcc;
(3)最后一行会把Redis安装到/usr/local/bin下。
二、配置Redis
1、官方给的默认配置为redis-6.0.8/redis.conf,为了防止自己不小心把配置改崩了可以复制一份到上面的安装目录下。
mkdir /usr/local/bin/myconfig
cp redis-6.0.8/redis.conf /usr/local/bin/myconfig
cd /usr/local/bin/myconfig
vim redis.conf
在命令模式下用/daemonize查找关键字,修改为默认运行后为守护进程。
daemonize yes
2、为了防止被其他人拿去挖矿,最好在配置文件中配置密码。
requirepass [password]
三、启动服务器和客户端
redis-server /usr/local/bin/myconfig/redis.conf
redis-cli -p 6379 -a [password]
ping
四、redis-benchhmark(并发测试)
redis-benchmark -h
查看redis-benchmark的参数选项:
Usage: redis-benchmark [-h <host>] [-p <port>] [-c <clients>] [-n <requests>] [- k <boolean>]
-h <hostname> Server hostname (default 127.0.0.1)
-p <port> Server port (default 6379)
-s <socket> Server socket (overrides host and port)
-a <password> Password for Redis Auth
--user <username> Used to send ACL style 'AUTH username pass'. Needs -a.
-c <clients> Number of parallel connections (default 50)
-n <requests> Total number of requests (default 100000)
-d <size> Data size of SET/GET value in bytes (default 3)
--dbnum <db> SELECT the specified db number (default 0)
--threads <num> Enable multi-thread mode.
--cluster Enable cluster mode.
--enable-tracking Send CLIENT TRACKING on before starting benchmark.
-k <boolean> 1=keep alive 0=reconnect (default 1)
-r <keyspacelen> Use random keys for SET/GET/INCR, random values for SADD,
random members and scores for ZADD.
Using this option the benchmark will expand the string __rand_int__
inside an argument with a 12 digits number in the specified range
from 0 to keyspacelen-1. The substitution changes every time a command
is executed. Default tests use this to hit random keys in the
specified range.
-P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline).
-e If server replies with errors, show them on stdout.
(no more than 1 error per second is displayed)
-q Quiet. Just show query/sec values
--precision Number of decimal places to display in latency output (defau lt 0)
--csv Output in CSV format
-l Loop. Run the tests forever
-t <tests> Only run the comma separated list of tests. The test
names are the same as the ones produced as output.
-I Idle mode. Just open N idle connections and wait.
在保持服务器运行的情况下,运行redis-benchmark,100个并发连接和100000个请求:
redis-benchmark -a [password] -p 6379 -c 100 -n 100000