标签:redis
安装准备
环境:CentOS release 6.8
本次安装版本:redis-3.2.7
redis tar包下载
https://redis.io
[root@ppt tools]# tar xf redis-3.2.7.tar.gz [root@ppt tools]# cd redis-3.2.7 [root@ppt redis-3.2.7]# less README.md --->通过查看readme.md,了解安装方式
Selecting a non-default memory allocator when building Redis is done by setting the `MALLOC` environment variable. Redis is compiled and linked against libc malloc by default, with the exception of jemalloc being the default on Linux systems. This default was picked because jemalloc has proven to have fewer fragmentation problems than libc malloc. To force compiling against libc malloc, use: % make MALLOC=libc To compile against jemalloc on Mac OS X systems, use: % make MALLOC=jemalloc Verbose build -------------
[root@ppt redis-3.2.7]# make MALLOC=jemalloc --->通过jemalloc方式make
编译过程中,可能会发生报错,报错如下,不报下步可忽略
undefined reference to `clock_gettime‘
由于clock_gettime在实时库librt(real time)里面,没有链接这个库导致报错。
需要在Makefile文件里面添加动态链接库librt ( -lrt ),从新编译。
[root@ppt redis-3.2.7]# find / -name ‘*librt*‘ /usr/lib64/librt.a /usr/lib64/librt.so /usr/lib/librt.a /usr/lib/x86_64-redhat-linux5E/lib64/librt.a /usr/lib/x86_64-redhat-linux5E/lib64/librt.so /lib64/rtkaio/librtkaio-2.12.so /lib64/rtkaio/librt.so.1 /lib64/librt-2.12.so /lib64/librt.so.1 /lib/rtkaio/librtkaio-2.12.so /lib/rtkaio/librt.so.1 /lib/rtkaio/i686/nosegneg/librtkaio-2.12.so /lib/rtkaio/i686/nosegneg/librt.so.1 /lib/librt-2.12.so /lib/librt.so.1 /lib/i686/nosegneg/librt-2.12.so /lib/i686/nosegneg/librt.so.1
找到librt.so路径
[root@ppt redis-3.2.7]# ll /usr/lib64/librt.so lrwxrwxrwx. 1 root root 22 Nov 9 11:48 /usr/lib64/librt.so -> ../../lib64/librt.so.1
随后在redis解压的路径下找到Makefile,并进行添加编辑
/app/tools/redis-3.2.7/src [root@ppt src]# vim Makefile
:set nu找到108行,并在108行下添加一行内容
FINAL_LIBS+= /usr/lib64/librt.so 以下是配置文件 ifeq ($(MALLOC),jemalloc) DEPENDENCY_TARGETS+= jemalloc FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a FINAL_LIBS+= /usr/lib64/librt.so --->刚刚添加的部分 endif 保存完毕后从新编译安装
编译通过后,设置安装路径进行安装
make PREFIX=/app/redis-3.2.7 install ---> 我把redis安装在/app/redis-3.2.7下
随后我设置了软连接,把版本号去掉了,方便启动
ln -s /app/redis-3.2.7/ app/redis
在软连接redis路径下,将redis配置文件redis.conf从解压下redis-3.2.7文件夹下拷贝过来
[root@ppt redis]# mkdir conf ---> 首先先在redis下创建conf文件夹 [root@ppt conf]# cp /app/tools/redis-3.2.7/redis.conf /app/redis/conf/ [root@ppt conf]# sysctl vm.overcommit_memory=1
设置环境变量
[root@ppt conf]# echo "export PATH=/app/redis/bin:$PATH" >> /etc/profile [root@ppt conf]# source /etc/profile
以上步骤redis已经安装完毕,随后进行启动
[root@ppt ~]# redis-server /app/redis/conf/redis.conf & [1] 5395 _._ _.-``__ ‘‘-._ _.-`` `. `_. ‘‘-._ Redis 3.2.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ‘‘-._ ( ‘ , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|‘` _.-‘| Port: 6379 | `-._ `._ / _.-‘ | PID: 5395 `-._ `-._ `-./ _.-‘ _.-‘ |`-._`-._ `-.__.-‘ _.-‘_.-‘| | `-._`-._ _.-‘_.-‘ | http://redis.io `-._ `-._`-.__.-‘_.-‘ _.-‘ |`-._`-._ `-.__.-‘ _.-‘_.-‘| | `-._`-._ _.-‘_.-‘ | `-._ `-._`-.__.-‘_.-‘ _.-‘ `-._ `-.__.-‘ _.-‘ `-._ _.-‘ `-.__.-‘ 5395:M 10 Feb 10:34:20.747 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 5395:M 10 Feb 10:34:20.747 # Server started, Redis version 3.2.7 5395:M 10 Feb 10:34:20.747 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled‘ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 5395:M 10 Feb 10:34:20.747 * The server is now ready to accept connections on port 6379
此时表示redis已经安装成功。
检查一下进程和端口。
[root@ppt ~]# ps -ef | grep redis root 5395 1955 0 10:34 pts/0 00:00:00 redis-server 127.0.0.1:6379 root 5527 1955 0 10:36 pts/0 00:00:00 grep redis [root@ppt ~]# netstat -anp | grep 6379 tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 5395/redis-server 1
关闭redis服务
[root@ppt ~]# redis-cli shutdown 5395:M 10 Feb 10:37:17.969 # User requested shutdown... 5395:M 10 Feb 10:37:17.969 * Saving the final RDB snapshot before exiting. 5395:M 10 Feb 10:37:18.047 * DB saved on disk 5395:M 10 Feb 10:37:18.047 * Removing the pid file. 5395:M 10 Feb 10:37:18.047 # Redis is now ready to exit, bye bye... [1]+ Done redis-server /app/redis/conf/redis.conf
本文出自 “xiaobao” 博客,谢绝转载!
标签:redis
原文地址:http://baoyc.blog.51cto.com/9092507/1896605