Linux安装redis-5.0.5

文章详细介绍了如何下载、编译Redis5.0.5,包括编译后的输出信息、安装步骤,以及如何部署Redis服务器。提到了将Redis配置文件和命令移动到统一目录,设置后台启动,配置远程连接,以及处理启动时的警告。此外,还讨论了通过nohup和systemd管理Redis服务,以及配置防火墙开启对应端口的方法。
摘要由CSDN通过智能技术生成

下载

wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar -zxf redis-5.0.5.tar.gz -C /usr/local
cd /usr/local/redis-5.0.5/
make

编译后如下:

LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof
Hint: It’s a good idea to run ‘make test’ ;
make[1]: Leaving directory `/usr/local/redis-5.0.5/src’

编译完成之后,可以看到解压文件redis-5.0.5 中会有对应的src、conf等文件夹。
编译成功后,进入src文件夹,执行make install进行Redis安装。

[root@localhost 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

部署
1.为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中
1)创建bin和etc文件

mkdir etc
mkdir bin

2)回到刚刚安装目录,找到redis.conf,将其复制移动到 /usr/local/redis/etc 下

mv redis.conf /usr/local/redis-5.0.5/etc/

进入src目录

[root@localhost redis-5.0.5]# cd src
[root@localhost src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis-5.0.5/bin/

2、执行redis-server 启动redis

[root@localhost bin]# ./redis-server
110921:C 19 Apr 2020 07:41:15.797 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
110921:C 19 Apr 2020 07:41:15.797 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=110921, just started
110921:C 19 Apr 2020 07:41:15.797 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
110921:M 19 Apr 2020 07:41:15.797 * Increased maximum number of open files to 10032 (it was originally set to 1024).
.
.-__ ''-._ _.- . . ‘’-._ Redis 5.0.5 (00000000/0) 64 bit
.- .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.-.|'_.-'| Port: 6379 | -. ._ / _.-' | PID: 110921 -._ -._ -./ .-’ .-’
|-._-.
-.__.-' _.-'_.-'| | -.
-._ _.-'_.-' | http://redis.io -._ -._-..-'.-’ .-’
|-._-.
-.__.-' _.-'_.-'| | -.
-._ _.-'_.-' | -._ -._-.
.-‘_.-’ _.-’
-._ -..-’ _.-’
-._ _.-' -.
.-’
110921:M 19 Apr 2020 07:41:15.799 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
110921:M 19 Apr 2020 07:41:15.799 # Server initialized
110921:M 19 Apr 2020 07:41:15.799 # 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.
110921:M 19 Apr 2020 07:41:15.800 # 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.
110921:M 19 Apr 2020 07:41:15.800 * Ready to accept connections

设置后台启动redis

vi /usr/local/redis-5.0.5/etc/redis.conf 将daemonize no 改成daemonize yes

在这里插入图片描述

redis.conf 配置解析
(设置红色的基本就可以自己用了,bind配置0.0.0.0后要在/etc/sysconfig/iptables配置相应的端口):
daemonize:如需要在后台运行,把该项的值改为yes
pdifile:把pid文件放在/var/run/redis.pid,可以配置到其他地址
bind:指定redis只接收来自该IP的请求,如果不设置,那么将处理所有请求,在生产环节中最好设置该项
(设置0.0.0.0 则改为用iptables来控制访问权限) port:监听端口,默认为6379 timeout:设置客户端连接时的超时时间,单位为秒
loglevel:等级分为4级,debug,revbose,notice和warning。生产环境下一般开启notice
logfile:配置log文件地址,默认使用标准输出,即打印在命令行终端的端口上
database:设置数据库的个数,默认使用的数据库是0 save:设置redis进行数据库镜像的频率
rdbcompression:在进行镜像备份时,是否进行压缩 dbfilename:镜像备份文件的文件名
dir:数据库镜像备份的文件放置的路径 slaveof:设置该数据库为其他数据库的从数据库
masterauth:当主数据库连接需要密码验证时,在这里设定 requirepass:设置客户端连接后进行任何其他指定前需要使用的密码
maxclients:限制同时连接的客户端数量 maxmemory:设置redis能够使用的最大内存
appendonly:开启appendonly模式后,redis会把每一次所接收到的写操作都追加到appendonly.aof文件中,当redis重新启动时,会从该文件恢复出之前的状态
appendfsync:设置appendonly.aof文件进行同步的频率 vm_enabled:是否开启虚拟内存支持
vm_swap_file:设置虚拟内存的交换文件的路径
vm_max_momery:设置开启虚拟内存后,redis将使用的最大物理内存的大小,默认为0
vm_page_size:设置虚拟内存页的大小 vm_pages:设置交换文件的总的page数量
vm_max_thrrads:设置vm IO同时使用的线程数量

将redis加入到开机启动
vi /etc/rc.local //在里面添加内容:

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

前台开启redis

[root@localhost etc]# /usr/local/redis-5.0.5/bin/redis-server /usr/local/redis-5.0.5/etc/redis.conf
111234:C 19 Apr 2020 08:09:00.794 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
111234:C 19 Apr 2020 08:09:00.794 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=111234, just started
111234:C 19 Apr 2020 08:09:00.794 # Configuration loaded

后台启动的三种方式

使用&符号
在Redis命令后使用&符号即可将其放入后台执行。例如:
redis-server &
这种方式会将Redis实例启动在后台,并返回进程ID。
注意:这种方式启动的Redis实例,如果当前终端关闭,Redis实例也会随之终止。

使用nohup命令
使用nohup命令可以将Redis实例放入后台执行,并且避免在当前终端关闭时终止Redis实例。
nohup redis-server &

使用systemd管理
使用systemd可以实现自动化管理Redis实例,并在系统启动时自动启动Redis实例。
创建一个名为redis.service的文件
在文件中添加以下内容:

[Unit]
Description=Redis Server
After=network.target

[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

注意:ExecStart中的路径需要根据实际情况进行修改,Restart参数可以根据需求进行设置。

将文件放入systemd的服务配置目录中
执行以下命令启动Redis服务:

systemctl start redis

这种方式启动的Redis实例,在系统启动时也会自动启动。

查看端口

[root@localhost etc]# netstat -tunpl|grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 111235/redis-server

配置远程连接
采用redis desktop manager远程连接的配置
接下里我们在配置文件redis.conf中进行相关的配置

#打开配置文件

vim redis.conf

配置后台启动
在vim编辑模式下,输入行数+gg可以快捷跳行。例如跳到第138行,输入:138gg
将第138行的daemonize no修改为daemonize yes即可(如已经配置了后台启动,这步可省略)

开启远程访问
将第70行的bind注释,第90行将protected-mode改为no

在这里插入图片描述
设置密码
在这里插入图片描述
重启redis

#首先查询到redis的pid后,kill掉,然后重启
[root@localhost bin]# ps -ef|grep redis
root 20940 1 0 12:12 ? 00:00:18 ./redis-server *:6379
[root@localhost bin]# kill 20940
[root@localhost bin]# ./redis-server /usr/local/redis-5.0.5/etc/redis.conf

查看防火墙、开启防火墙:

通过防火墙,开启端口
1.安装防火墙
安装iptables-services :
2.防火墙基本操作
查看版本: firewall-cmd --version
显示状态: firewall-cmd --state
查看所有打开的端口: netstat -anp
开启防火墙 systemctl start firewalld
关闭防火墙 systemctl stop firewalld
开启防火墙 service firewalld start
若遇到无法开启
先用:systemctl unmask firewalld.service
然后:systemctl start firewalld.service
3.端口查询
查询指定端口是否已开 firewall-cmd --query-port=666/tcp
提示yes or no
查询所有开启的端口 netstat -anp
4.开启端口
如果上面端口查询没有开启的话,需要重新开启一下
开启端口命令
添加 firewall-cmd --zone=public --add-port=80/tcp --permanent (–permanent永久生效,没有此参数重启后失效)
重新载入 firewall-cmd --reload
查看 firewall-cmd --query-port=80/tcp
删除 firewall-cmd --zone= public --remove-port=80/tcp --permanent

连接
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值