redis中文网
CentOS7安装redis
下载并安装
wget http://download.redis.io/releases/redis-5.0.4.tar.gz
tar -zxvf redis-5.0.4.tar.gz
mv redis-5.0.4 /usr/local/redis/
cd /usr/local/redis/
make
启动redis服务
cd /usr/local/redis/src/
./redis-server
redis-server redis服务器 redis-cli redis命令行客户端 redis-benchmark redis性能测试工具 redis-check-aof AOF文件修复工具 redis-check-rdb RDB文件检索工具
使用Redis的内置客户端进行进行redis代码的编写
[root@localhost ~]
[root@localhost src]
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
ps -ef|grep redis 查看redis服务器进程
sudo kill -9 pid 杀死redis服务器
sudo redis-server /etc/redis/redis.conf 指定加载的配置文件
配置开机启动
cd /usr/local/redis/
vim redis.conf
redis.conf文件,设置daemonize yes 复制redis配置文件到/etc/redis
mkdir /etc/redis
cp /usr/local/redis/redis.conf /etc/redis/6379.conf
复制redis启动脚本
[root@localhost redis]
/usr/local/redis/utils/redis_init_script
[root@localhost redis]
修改redis启动脚本
vi /etc/init.d/redis
REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
启动redis
打开redis命令: service redis start
关闭redis命令: service redis stop
设为开机启动: chkconfig redis on
设为开机关闭: chkconfig redis off
配置
vi /etc/redis/6379.conf
绑定ip:如果需要远程访问,可将此?注释,或绑定?个真实ip
bind 127.0.0.1
端?,默认为6379
port 6379
是否以守护进程运?
如果以守护进程运?,则不会在命令?阻塞,类似于服务
如果以?守护进程运?,则当前终端被阻塞
设置为yes表示守护进程,设置为no表示?守护进程
推荐设置为yes
daemonize yes
数据?件
dbfilename dump.rdb
数据?件存储路径
dir /var/lib/redis
?志?件
logfile /var/log/redis/redis-server.log
数据库,默认有16个
database 16
主从复制,类似于双机备份。
slaveof
遇到问题1
[root@localhost redis]
cd src && make all
make[1]: 进入目录“/usr/local/redis/src”
CC Makefile.dep
make[1]: 离开目录“/usr/local/redis/src”
make[1]: 进入目录“/usr/local/redis/src”
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
make[2]: 进入目录“/usr/local/redis/deps”
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: 离开目录“/usr/local/redis/deps”
(rm -f .make-*)
echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings
echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC='' -Wall -W -Wno-missing-field-initializers -O2 -g -ggdb -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS= -g -ggdb -rdynamic >> .make-settings
(cd ../deps && make hiredis linenoise lua jemalloc)
make[2]: 进入目录“/usr/local/redis/deps”
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
(echo "" > .make-cflags)
(echo "" > .make-ldflags)
MAKE hiredis
cd hiredis && make static
make[3]: 进入目录“/usr/local/redis/deps/hiredis”
gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
make[3]: gcc:命令未找到
make[3]: *** [net.o] 错误 127
make[3]: 离开目录“/usr/local/redis/deps/hiredis”
make[2]: *** [hiredis] 错误 2
make[2]: 离开目录“/usr/local/redis/deps”
make[1]: [persist-settings] 错误 2 (忽略)
CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 错误 127
make[1]: 离开目录“/usr/local/redis/src”
make: *** [all] 错误 2
解决办法:
yum -y install gcc gcc-c++ libstdc++-devel cpp binutils glibc glibc-kernheaders glibc-common glibc-devel make
遇到问题2
[root@localhost redis]
cd src && make all
make[1]: 进入目录“/usr/local/redis/src”
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
^
编译中断。
make[1]: *** [adlist.o] 错误 1
make[1]: 离开目录“/usr/local/redis/src”
make: *** [all] 错误 2
解决办法:
make CFLAGS="-march=x86-64"
|