单机redis搭建及启动

1.上传并解压

redis-4.0.2.tar.gz

2.安装C语言编译环境

[建议先拍快照]

yum install -y gcc-c++

如果不能联网,可以使用下面步骤安装:

1.上传gcc-c++.rpm.packages目录到Linux系统
2.拍摄快照
3.进入rpm包所在目录
4.执行安装
rpm -Uvh *.rpm --nodeps --force
5.验证安装效果
gcc -v

3.修改安装位置

vim redis解压目录/src/Makefile

PREFIX?=/usr/local/redis

就Redis自身而言是不需要修改的,这里修改的目的是让Redis的运行程序不要和其他文件混杂在一起。

4.编译安装

编译:进入Redis解压目录执行make命令

[建议先拍快照]

安装:make install

5.启动Redis服务器

①默认启动

[root@rich ~]# /usr/local/redis/bin/redis-server
7239:C 07 Oct 18:59:12.144 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7239:C 07 Oct 18:59:12.144 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=7239, just started
7239:C 07 Oct 18:59:12.144 # Warning: no config file specified, using the default config. In order to specify a config file use /usr/local/redis/bin/redis-server /path/to/redis.conf
7239:M 07 Oct 18:59:12.145 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7239
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

7239:M 07 Oct 18:59:12.148 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7239:M 07 Oct 18:59:12.148 # Server initialized
7239:M 07 Oct 18:59:12.148 # 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.
7239:M 07 Oct 18:59:12.148 # 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.
7239:M 07 Oct 18:59:12.148 * Ready to accept connections

停止Redis服务器可以在另外一个命令行窗口执行下面命令:

/usr/local/redis/bin/redis-cli shutdown
7239:M 07 Oct 19:00:53.208 # User requested shutdown...
7239:M 07 Oct 19:00:53.208 * Saving the final RDB snapshot before exiting.
7239:M 07 Oct 19:00:53.214 * DB saved on disk
7239:M 07 Oct 19:00:53.214 # Redis is now ready to exit, bye bye...

②定制配置项启动

[1]准备配置文件

cp redis解压目录/redis.conf /usr/local/redis/

[2]修改配置项

配置项名称

作用

取值

daemonize

控制是否以守护进程形式运行Redis服务器

yes

logfile

指定日志文件位置

"/var/logs/redis.log"

dir

Redis工作目录

/usr/local/redis

redis.conf文件

daemonize yes
logfile "/var/logs/redis.log"
dir /usr/local/redis

注意:/var/logs目录需要我们提前创建好

[3]让Redis根据指定的配置文件启动

格式

daemonize yes
logfile "/var/logs/redis.log"
dir /usr/local/redis

举例

/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf

6.客户端登录

/usr/local/redis/bin/redis-cli

    127.0.0.1:6379> ping
    PONG
    127.0.0.1:6379> exit

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值