CentOS7.8安装redis4.0.14
一、安装redis
第一步:下载redis安装包到指定目录
wget -P /usr/local/ http://download.redis.io/releases/redis-4.0.14.tar.gz
[[email protected] ~]# 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]
[[email protected] ~]#
第二步,解压压缩包
[[email protected] ~]# cd /usr/local/
[[email protected] local]# tar -zxvf redis-4.0.14.tar.gz
第三步:yum安装gcc依赖
[[email protected] local]# yum install gcc
第四步:跳转到redis解压目录下
[[email protected] local]# cd redis-4.0.14/
[[email protected] redis-4.0.14]#
第五步:编译安装
1. make MALLOC=libc
[[email protected] redis-4.0.14]# make MALLOC=libc
2. cd src && make install
[[email protected] 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
[[email protected] src]#
二、启动redis的三种方式
1.直接启动redis
./redis-serve
[[email protected] redis-4.0.14]#
[[email protected] redis-4.0.14]# cd src
[[email protected] 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文件到指定地点
[[email protected] local]# cd /usr/local/
[[email protected] local]# ls
bin etc games include lib lib64 libexec redis-4.0.14 redis-4.0.14.tar.gz sbin share src
[[email protected] local]# mkdir redis
[[email protected] local]# cd redis
[[email protected] redis]# mkdir conf
[[email protected] redis]# cp /usr/local/redis-4.0.14/redis.conf /usr/local/redis/conf
第二步:修改redis.conf文件
将
daemonize no
修改为
daemonize yes
[[email protected] conf]# vi redis.conf
esc —>: set number 设置行号
esc —> / daemonize —>enter(回车) 搜索关键字—>n /N—>下一个/上一个
esc—>:wq 保存退出
esc—>:q! 不保存强制退出
第三步指定redis.conf文件启动
[[email protected] conf]# cd /usr/local/redis-4.0.14/src/
[[email protected] 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
[[email protected] src]#
第三步:关闭redis进程
首先使用ps -aux | grep redis查看redis进程
[[email protected] 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
[[email protected] src]#
使用kill命令杀死进程 kill 3364
[[email protected] src]# kill 3364
[[email protected] src]#
3.设置redis开机自启动
1、在/etc目录下新建redis目录
[[email protected] /]# cd /etc
[[email protected] etc]# mkdir redis
[[email protected] etc]#
2、将/usr/local/redis-4.0.14/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf
[[email protected] redis]# cp /usr/local/redis-4.0.14/redis.conf /etc/redis/6379.conf
[[email protected] 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目录下
[[email protected] redis]# cd /etc/init.d/
[[email protected] init.d]# ls
functions netconsole network README
[[email protected] init.d]# cp /usr/local/redis-4.0.14/utils/redis_init_script /etc/init.d/redisd
[[email protected] init.d]#
[[email protected] init.d]# ls
functions netconsole network README redisd
[[email protected] init.d]#
4、设置redis开机自启动
先切换到/etc/init.d目录下
然后执行自启命令
[[email protected] init.d]# chkconfig redisd on
[[email protected] init.d]#
启动:
service redisd start
[[email protected] 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
[[email protected] 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
[[email protected] 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
推荐阅读
-
电脑安装ABBYY FineReader 12提示访问文件被拒绝的解决方法
-
mysql 5.7以上版本安装配置方法图文教程(mysql 5.7.12mysql 5.7.13mysql 5.7.14)
-
Wing FTP Server FTP服务器端中文版安装使用教程
-
Mysql5.7.17 winx64.zip解压缩版安装配置图文教程
-
ie9无法安装怎么解决?ie9无法安装解决图文教程
-
linux下mysql的安装步骤
-
windows系统mysql5.7.18安装图文教程
-
谷歌浏览器(chrome)的免费插件时空隧道安装与使用图文教程
-
详解在React项目中安装并使用Less(用法总结)
-
python3.4+pycharm 环境安装及使用方法