CentOS7.8安装redis4.0.14

一、安装redis

第一步:下载redis安装包到指定目录

wget -P /usr/local/ http://download.redis.io/releases/redis-4.0.14.tar.gz

[root@centos7 ~]# wget -P /usr/local/  http://download.redis.io/releases/redis-4.0.14.tar.gz
--2020-06-02 11:14:22--  http://download.redis.io/releases/redis-4.0.14.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1740967 (1.7M) [application/x-gzip]
Saving to:/usr/local/redis-4.0.14.tar.gz’

100%[====================================================================================================================================================================================================================================>] 1,740,967    840KB/s   in 2.0s   

2020-06-02 11:14:25 (840 KB/s) -/usr/local/redis-4.0.14.tar.gz’ saved [1740967/1740967]

[root@centos7 ~]# 

第二步,解压压缩包
[root@centos7 ~]# cd /usr/local/
[root@centos7 local]# tar -zxvf redis-4.0.14.tar.gz
第三步:yum安装gcc依赖
[root@centos7 local]# yum install gcc
第四步:跳转到redis解压目录下
[root@centos7 local]# cd redis-4.0.14/
[root@centos7 redis-4.0.14]# 

第五步:编译安装
1. make MALLOC=libc
[root@centos7 redis-4.0.14]# make MALLOC=libc
2. cd src && make install
[root@centos7 redis-4.0.14]# cd src && make install
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@centos7 src]# 

二、启动redis的三种方式

1.直接启动redis

./redis-serve

[root@centos7 redis-4.0.14]# 
[root@centos7 redis-4.0.14]# cd src
[root@centos7 src]# ./redis-server 
3303:C 02 Jun 11:31:17.352 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3303:C 02 Jun 11:31:17.353 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=3303, just started
3303:C 02 Jun 11:31:17.353 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
3303:M 02 Jun 11:31:17.353 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.14 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 3303
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

3303:M 02 Jun 11:31:17.356 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
3303:M 02 Jun 11:31:17.356 # Server initialized
3303:M 02 Jun 11:31:17.357 # 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.
3303:M 02 Jun 11:31:17.357 # 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.
3303:M 02 Jun 11:31:17.357 * Ready to accept connections

如上图:redis启动成功,这种启动方式需要一直打开窗口,不能进行其他操作

按 ctrl + c可以关闭窗口。

2.以后台进程方式启动redis

第一步 复制一份redis.conf文件到指定地点

[root@centos7 local]# cd /usr/local/
[root@centos7 local]# ls
bin  etc  games  include  lib  lib64  libexec  redis-4.0.14  redis-4.0.14.tar.gz  sbin  share  src
[root@centos7 local]# mkdir redis
[root@centos7 local]# cd redis
[root@centos7 redis]# mkdir conf
[root@centos7 redis]# cp /usr/local/redis-4.0.14/redis.conf  /usr/local/redis/conf

第二步:修改redis.conf文件

daemonize no
修改为
daemonize yes

[root@centos7 conf]# vi redis.conf

esc —>: set number 设置行号
esc —> / daemonize —>enter(回车) 搜索关键字—>n /N—>下一个/上一个
esc—>:wq 保存退出
esc—>:q! 不保存强制退出

第三步指定redis.conf文件启动

[root@centos7 conf]# cd /usr/local/redis-4.0.14/src/
[root@centos7 src]# ./redis-server /usr/local/redis/conf/redis.conf 
3363:C 02 Jun 11:54:01.758 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3363:C 02 Jun 11:54:01.758 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=3363, just started
3363:C 02 Jun 11:54:01.758 # Configuration loaded
[root@centos7 src]# 

第三步:关闭redis进程
首先使用ps -aux | grep redis查看redis进程

[root@centos7 src]# ps -aux | grep redis
root      3364  0.0  0.1 141940  2016 ?        Ssl  11:54   0:00 ./redis-server 127.0.0.1:6379
root      3369  0.0  0.0 112808   968 pts/0    S+   11:55   0:00 grep --color=auto redis
[root@centos7 src]# 

使用kill命令杀死进程 kill 3364

[root@centos7 src]# kill 3364
[root@centos7 src]# 
3.设置redis开机自启动

1、在/etc目录下新建redis目录

[root@centos7 /]# cd /etc
[root@centos7 etc]# mkdir redis
[root@centos7 etc]# 

2、将/usr/local/redis-4.0.14/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf

[root@centos7 redis]# cp /usr/local/redis-4.0.14/redis.conf /etc/redis/6379.conf
[root@centos7 redis]# 

3、编辑6379.conf

#后台方式启动(守护进程) 设置为yes
daemonize yes
 
#远程登陆
#把bind 127.0.0.1注释掉.(注释后所有机器均可访问)
#bind 127.0.0.1
 
#把protected-mode设置为no.(允许公网访问)
protected-mode no
 
#修改密码
#把requirepass foobared的注释去掉.将foobared 修改成想要的密码
requirepass 123456

3、将redis的启动脚本复制一份放到/etc/init.d目录下

[root@centos7 redis]# cd /etc/init.d/
[root@centos7 init.d]# ls
functions  netconsole  network  README
[root@centos7 init.d]# cp /usr/local/redis-4.0.14/utils/redis_init_script /etc/init.d/redisd
[root@centos7 init.d]# 
[root@centos7 init.d]# ls
functions  netconsole  network  README  redisd
[root@centos7 init.d]# 

4、设置redis开机自启动
先切换到/etc/init.d目录下
然后执行自启命令

[root@centos7 init.d]# chkconfig redisd on
[root@centos7 init.d]# 

启动:
service redisd start

[root@centos7 init.d]# service redisd start
Starting Redis server...
3471:C 02 Jun 12:35:16.598 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3471:C 02 Jun 12:35:16.598 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=3471, just started
3471:C 02 Jun 12:35:16.598 # Configuration loaded
[root@centos7 init.d]# ps aux | grep redis
root      3472  0.0  0.1  38244  1964 ?        Ssl  12:35   0:00 /usr/local/bin/redis-server *:6379
root      3477  0.0  0.0 112808   968 pts/0    S+   12:35   0:00 grep --color=auto redis
[root@centos7 init.d]# 

关闭:

方法1:service redisd stop

安装完成之后可能因为防火墙的原因访问失败
1.sudo systemctl status firewall 查看防火墙状态
2.关闭防火墙(重启之后默认打开防火墙)
sudo systemctl stop firewalld
3.打开防火墙
sudo systemctl start firewalld
4.禁用防火墙
sudo systemctl disable firewalld
5.解除禁用防火墙(恢复开机启动)
systemctl enable firewalld.service
sudo systemctl enable firewalld

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值