如何通过源码安装redis-3.0.5-创新互联

这篇文章给大家分享的是有关如何通过源码安装redis-3.0.5的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名申请雅安服务器托管、营销软件、网站建设、铁西网站维护、网站推广。

##### 安装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”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

分享名称:如何通过源码安装redis-3.0.5-创新互联
网站链接:https://www.cdcxhl.com/article20/csipjo.html

成都网站建设公司_创新互联,为您提供品牌网站建设云服务器App设计网站策划ChatGPT企业建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站网页设计