大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章给大家分享的是有关如何通过源码安装redis-3.0.5的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
创新互联自2013年创立以来,先为上虞等服务建站,上虞等地企业,进行企业商务咨询服务。为上虞企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
##### 安装redis-server #####
# 创建运行用户
useradd redis -s /sbin/nologin -M
# 上传软件到指定位置,我的软件保存位置为
mkdir -p /server/tools/
# 解压,配置,编译,安装
cd /server/tools/ tar -zxf redis-3.0.5.tar.gz cd redis-3.0.5 make PREFIX=/usr/local/redis make PREFIX=/usr/local/redis install
# 配置redis环境变量
echo ' ' >> /etc/profile echo 'PATH for redis-server' >> /etc/profile echo 'export PATH=/usr/local/redis/bin/:$PATH' >> /etc/profile tail -3 /etc/profile source /etc/profile echo $PATH
# 或者(重启失效)
export PATH=/usr/local/redis/bin/:$PATH echo $PATH
# 创建配置文件,数据,日志等相关目录,并拷贝配置文件
# 创建规范的目录结构有助于行成良好习惯,提高效率
mkdir -p /usr/local/redis/conf mkdir -p /usr/local/redis/data mkdir -p /usr/local/redis/logs cp redis.conf /usr/local/redis/conf/ cd /usr/local/redis/conf/ tree /usr/local/redis
# 到此redis基本配置便已完成,可以使用redis初始配置进行启动
# 启动命令
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf &
# 查看启动状态,进程和端口
ps -ef |grep redis netstat -anptl |grep redis
# 测试及使用
# 客户端连接命令为:
/usr/local/redis/bin/redis-cli -p 6379 [root@cache redis]# redis-cli -p 6379 127.0.0.1:6379> set a 1 OK 127.0.0.1:6379> get a "1" 127.0.0.1:6379> set b 2 OK 127.0.0.1:6379> set c 3 OK 127.0.0.1:6379> keys * 1) "c" 2) "a" 3) "b" 127.0.0.1:6379> exit
# 以上为简单测试,验证安装正确与否
# 安全关闭redis
/usr/local/redis/bin/redis-cli shutdown
# 关闭redis时,数据默认会保存在启动redis时候所在的位置,保存为dump.rdb
-------- 简单优化redis ---------
# 以默认配置启动redis-server会出现以下警告信息:不影响使用,
# 不过以笔者的习惯自然不会容忍此等警告信息的存在:
[root@cache redis]# redis-server /usr/local/redis/conf/redis.conf & [1] 4570 [root@cache redis]# [4570] 07 Dec 03:54:50.938 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.0.5 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in stand alone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 4570 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' [4570] 07 Dec 03:54:50.939 # Server started, Redis version 3.0.5 [4570] 07 Dec 03:54:50.939 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. [4570] 07 Dec 03:54:50.939 # 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. [4570] 07 Dec 03:54:50.939 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. [4570] 07 Dec 03:54:50.939 * The server is now ready to accept connections on port 6379
# 根据启动日志提示需要优化一些内核的参数,按提示操作:
echo never > /sys/kernel/mm/transparent_hugepage/enabled cat /sys/kernel/mm/transparent_hugepage/enabled echo 511 > /proc/sys/net/core/somaxconn cat /proc/sys/net/core/somaxconn echo "vm.overcommit_memory = 1" >>/etc/sysctl.conf sysctl -p
# 以上操作重启失效,可以按下操作配置下次开机生效,顺便设置redis开机自启动
echo " " >> /etc/rc.local echo "# redis-server by zs in $(date +%F)" >> /etc/rc.local echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local echo "echo 511 > /proc/sys/net/core/somaxconn" >>/etc/rc.local echo "/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf" >> /etc/rc.local tail -5 /etc/rc.local
# 继续优化配置文件
vim /usr/local/redis/conf/redis.conf
# 在配置文件中寻找以下关键字,可以按照以下内容修改:
daemonize yes # 是否后台运行,yes为后台运行 pidfile /usr/local/redis/logs/redis.pid # redis的pid文件保存位置 port 6379 # redis监控端口 bind 0.0.0.0 # redis监控的IP timeout 0 # 客户端连接关闭时服务端保持连接的时长,超时 # 0为不断开连接,等待客户端再次连接 logfile "/usr/local/redis/logs/redis.log" # 日志文件保存位置 dbfilename redis.rdb # redis数据文件名 dir /usr/local/redis/data/ # redis数据保存位置 appendonly yes # 是否写日志,类似于MySQL的bin-log
以上为简单的redis优化配置
感谢各位的阅读!关于“如何通过源码安装redis-3.0.5”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!