设为首页 收藏本站
查看: 560|回复: 0

[经验分享] 源码安装redis-3.0.5

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-7-1 09:09:21 | 显示全部楼层 |阅读模式
##### 安装redis-server #####
# 创建运行用户
1
useradd redis -s /sbin/nologin -M



# 上传软件到指定位置,我的软件保存位置为
1
mkdir -p /server/tools/



# 解压,配置,编译,安装

1
2
3
4
5
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环境变量
1
2
3
4
5
6
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



# 或者(重启失效)
1
2
export PATH=/usr/local/redis/bin/:$PATH
echo $PATH



# 创建配置文件,数据,日志等相关目录,并拷贝配置文件
# 创建规范的目录结构有助于行成良好习惯,提高效率
1
2
3
4
5
6
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初始配置进行启动
# 启动命令
1
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf &



# 查看启动状态,进程和端口
1
2
ps -ef |grep redis
netstat -anptl |grep redis



# 测试及使用
# 客户端连接命令为:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/usr/local/redis/bin/redis-cli -p 6379

[iyunv@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
1
/usr/local/redis/bin/redis-cli shutdown



# 关闭redis时,数据默认会保存在启动redis时候所在的位置,保存为dump.rdb

-------- 简单优化redis ---------
# 以默认配置启动redis-server会出现以下警告信息:不影响使用,
# 不过以笔者的习惯自然不会容忍此等警告信息的存在:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[iyunv@cache redis]# redis-server /usr/local/redis/conf/redis.conf &
[1] 4570
[iyunv@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



# 根据启动日志提示需要优化一些内核的参数,按提示操作:
1
2
3
4
5
6
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开机自启动

1
2
3
4
5
6
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



# 继续优化配置文件
1
vim /usr/local/redis/conf/redis.conf



# 在配置文件中寻找以下关键字,可以按照以下内容修改:
1
2
3
4
5
6
7
8
9
10
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配置详解”里面的说明
###### END ######


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-237721-1-1.html 上篇帖子: redis启动管理脚本 下篇帖子: PHP操作redis基础程序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表