首页 > 数据库 >linux 安装redis

linux 安装redis

时间:2023-04-03 21:00:29浏览次数:54  
标签:5.0 00 -._ redis Redis linux root 安装

 

 

 

一、准备好 gcc 环境

yum install gcc-c++
复制代码

出现以下日志,代表安装成功。Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version

Loaded plugins: fastestmirror
Determining fastest mirrors
base                                                                                                                        | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                            | 3.5 kB  00:00:00     
epel                                                                                                                        | 4.7 kB  00:00:00     
extras                                                                                                                      | 2.9 kB  00:00:00     
nginx                                                                                                                       | 2.9 kB  00:00:00     
updates                                                                                                                     | 2.9 kB  00:00:00     
(1/7): epel/x86_64/group_gz                                                                                                 |  95 kB  00:00:00     
(2/7): epel/x86_64/updateinfo                                                                                               | 1.0 MB  00:00:00     
(3/7): docker-ce-stable/x86_64/primary_db                                                                                   |  45 kB  00:00:00     
(4/7): extras/7/x86_64/primary_db                                                                                           | 205 kB  00:00:00     
(5/7): updates/7/x86_64/primary_db                                                                                          | 3.0 MB  00:00:00     
(6/7): epel/x86_64/primary_db                                                                                               | 6.8 MB  00:00:00     
(7/7): nginx/x86_64/primary_db                                                                                              |  55 kB  00:00:02     
Package gcc-c++-4.8.5-39.el7.x86_64 already installed and latest version
Nothing to do
[root@root ~]# 
复制代码

二、下载并安装Redis

执行命令:wget http://download.redis.io/releases/redis-5.0.7.tar.gz。下载完成之后进行解压。再先后执行 makemake install命令。

或者在官网自由选择离线包安装:download.redis.io/releases/

[root@root /]# cd usr/java
[root@root java]# mkdir redis
[root@root java]# cd redis/
[root@root redis]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
[root@root redis]# tar -zxvf redis-5.0.7.tar.gz
[root@root redis]# cd redis-5.0.7
[root@root redis-5.0.7]# make
[root@root redis-5.0.7]# make install
复制代码

三、启动

输入命令:redis-server redis.conf ,启动Redis。看到以下页面代表启动成功。

[root@root redis-5.0.7]# redis-server redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 12513
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               
复制代码

但是这种启动没有办法在这个tab页下做任何操作了,因为这个时候使用Ctrl+c之后,就变成了这个样子。也就是关闭了Redis,这种方式是前台启动。

^C13082:signal-handler (1594381754) Received SIGINT scheduling shutdown...
13082:M 10 Jul 2020 19:49:14.132 # User requested shutdown...
13082:M 10 Jul 2020 19:49:14.132 * Saving the final RDB snapshot before exiting.
13082:M 10 Jul 2020 19:49:14.135 * DB saved on disk
13082:M 10 Jul 2020 19:49:14.135 * Removing the pid file.
13082:M 10 Jul 2020 19:49:14.135 # Redis is now ready to exit, bye bye...
复制代码

四、后台启动

打开redis.conf 文件。这也是Redis的配置文件。

[root@root redis-5.0.7]# vim redis.conf 
#打开之后,在命令窗口按下/输入daem然后回车
复制代码

image.png 修改为yes


daemonize yes
复制代码

Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,启用守护进程后,Redis会把pid写到一个pidfile中,在/var/run/redis_6379.pid文件中。

再次启动

[root@root redis-5.0.7]# redis-server redis.conf 
13352:C 10 Jul 2020 19:54:34.301 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13352:C 10 Jul 2020 19:54:34.301 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=13352, just started
13352:C 10 Jul 2020 19:54:34.301 # Configuration loaded
复制代码

五、连接Redis

[root@root redis-5.0.7]# redis-cli 
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
#查看密码
1) "requirepass"
2) ""
127.0.0.1:6379> 
复制代码

设置密码

我们发现竟然不需要密码就可以进入Redis。那怎么设置呢?

requirepass foobared:设置 Redis 连接密码,如果配置了连接密码,客户端在连接 Redis 时需要通过 AUTH password命令提供密码,默认是关闭。

1、临时设置

config set requirepass 123456
复制代码

2、永久设置

[root@root redis-5.0.7]# vim redis.conf
#打开之后,在命令窗口按下/输入 requirepass 然后回车
复制代码

找到如图所示的内容,将注释放开设置自己的密码。 image.png image.png

然后重启Redis

[root@root redis-5.0.7]# redis-server redis.conf 
[root@root redis-5.0.7]# redis-cli 
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth xxx
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 
复制代码

可以看到第一次ping的时候提示我需要身份验证。auth xxx这是连接后输入密码。也可以在连接的时候输入:

[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx
复制代码

额外扩展

启动方式

使用以下方式也可以启动 redis。

[root@localhost redis-5.0.7]# cp utils/redis_init_script /etc/init.d/redis
[root@localhost /]# service redis start
Starting Redis server...
87123:C 05 Mar 2022 15:46:12.383 # Fatal error, can't open config file '/etc/redis/6379.conf'
复制代码

还需要再/etc/redis 目录创建一个 6379.conf文件。

[root@localhost redis-5.0.7]# cd /etc/
[root@localhost etc]# mkdir redis
[root@localhost etc]# cp /usr/local/java/redis-5.0.7/redis.conf /etc/redis/6379.conf
[root@localhost /]# service redis start
Starting Redis server...
95224:C 05 Mar 2022 15:51:14.746 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
95224:C 05 Mar 2022 15:51:14.746 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=95224, just started
95224:C 05 Mar 2022 15:51:14.746 # Configuration loaded
[root@localhost /]# ps -ef |grep redis
root      95225      1  0 15:51 ?        00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379
复制代码

开启启动

需要上述方式启动方式!

# 赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/redis
# 添加为启动服务
[root@localhost /]# chkconfig --add redis
# 查看启动服务列表
[root@localhost /]# chkconfig --list
mysql           0:关    1:关    2:开    3:开    4:开    5:开    6:关
netconsole      0:关    1:关    2:关    3:关    4:关    5:关    6:关
network         0:关    1:关    2:开    3:开    4:开    5:开    6:关
redis           0:关    1:关    2:开    3:开    4:开    5:开    6:关
复制代码

远程连接

  • 1、修改 6379.conf。因为上述配置了开机启动,使用的启动配置文件为 /etc/redis/6379.conf。 将
[root@localhost /]# vim /etc/redis/6379.conf 

bind 127.0.0.1
复制代码

改为

# bind 127.0.0.1
复制代码
  • 2、检查防火墙是否关闭 防火墙一般默认都是开启的。如果防火墙是开启的,那就要进行端口检测,如果端口是关闭的,则要放开。 如果不想开放端口,直接将防火墙关闭就行。
    • 关闭防火墙
systemctl stop firewalld
复制代码
    • 开放端口
[root@localhost ~]# firewall-cmd --add-port=6379/tcp --permanent
success
[root@localhost ~]#  systemctl restart firewalld
复制代码

异常

在停止 Redis 服务时,会出现异常,出现原因为设置了Redis访问密码。

[root@localhost init.d]# service redis stop
Stopping ...
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
复制代码

我们找到 在文件中找到 $CLIEXEC -p $REDISPORT shutdown 将其更改为 $CLIEXEC -a "Redis访问密码" -p $REDISPORT shutdo

停止 Redis

[root@localhost init.d]# service redis stop
Stopping ...
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Redis stopped
[root@localhost init.d]# ps -ef | grep redis
root      28074  66532  0 17:00 pts/4    00:00:00 grep --color=auto redis
root      71324   5375  0 16:29 pts/2    00:00:00 redis-cli -a Yj19980402
复制代码

如果 3、4、5 状态为开或者为 on 则表示成功。如果是关或者 off 则执行一下:chkconfig --level 345 mysql on

执行完毕之后,可以重启计算机,命令为:reboot。 重启成功之后,执行 ps -ef | grep redis,可以看到 redis 的进程。

标签:5.0,00,-._,redis,Redis,linux,root,安装
From: https://www.cnblogs.com/message-hrp/p/17284422.html

相关文章

  • 分布式系统——基于Redis的分布式锁的实现
    分布式锁的介绍分布式锁是分布式系统中用于协调多个进程或线程之间并发访问共享资源的一种机制。在分布式系统中,由于各个节点之间的通信存在延迟、故障等问题,可能会导致数据的不一致性。为了保证数据的一致性,需要使用分布式锁来协调各个节点的并发访问。在分布式系统中,多个节点......
  • CentOS 7.x 卸载删除MariaDB,重新安装
    卸载[root@node1~]#rpm-qa|grepmariadbmariadb-5.5.56-2.el7.x86_64mariadb-libs-5.5.56-2.el7.x86_64mariadb-server-5.5.56-2.el7.x86_64[root@node1~]#[root@node1~]#yumremovemariadb...Removed:mariadb.x86_641:5.5.56-2.el7DependencyRemoved:mariadb-server.x......
  • Hi3516A开发--ethtool安装和使用
    一、下载ethtool-4.6.tar.gz下载二、安装解压:tar-xvfethtool-4.6.tar.gz配置:./configure--host=arm-hisiv300-linux //--host指定的是交叉编译工具链的前缀编译:make生成:ethtool查看:fileethtoolethtool:ELF32-bitLSB executable,ARM,EABI5version1(SYSV),dynamic......
  • Redis常见问题答疑
    数据类型一个数据类型都对应了很多种底层数据结构。以List为例,什么情况下是双向链表,反之又在什么情况下是压缩列表呢?还是说是并存状态?1、Hash和ZSet是数据量少采用压缩列表存储,数据量变大转为哈希表或跳表存储2、但List不是这样,是并存的状态,List是双向链表+压缩列表key过期......
  • Grafana 安装启用和钉钉报警
    Grafana钉钉报警的小卡片点击时无法跳转到Grafana的界面在Grafana的配置文件.ini里root_url='xxxx'配置上地址重启即可一、grafana安装与启用我这里使用的docker方式官方文档:https://grafana.com/docs/grafana/latest/installation/docker/1.数据接入、仪表盘配置展示、各指标......
  • Golang环境安装
    Go语言简介什么是Go语言Go语言是谷歌2009发布的第二款开源编程语言。Go语言专门针对多处理器系统应用程序的编程进行了优化,使用Go编译的程序可以媲美C或C++代码的速度,而且更加安全、支持并行进程。Go语言具有很强的表达能力,它简洁、清晰而高效。得益于其并发机制,用......
  • LINUX 放开端口,防火墙操作
    防火墙操作:查看防火墙状态systemctlstatusfirewalld、firewall-cmd--state暂时关闭防火墙systemctlstopfirewalld永久关闭防火墙(慎用)systemctldisablefirewalld开启防火墙systemctlstartfirewalld开放指定端口firewall-cmd--zone=public--add-port=8080/tcp--perman......
  • S5PV210开发 -- Linux dd命令
    昨天群里有人询问,为什么破坏BootLoader破坏不掉。出现错误:dd:writing'/dev/mtdblock0':Operationnotpermitted我说需要插着SD卡才可以。(这个也不对,不插SD卡也可以,那这个错误还是没有搞清楚)然后我们来看一下它操作指令:  busyboxddif=/dev/zeroof=/dev/mmcblk0bs=512......
  • MQTT再学习 -- 安装MQTT客户端及测试
    上一篇文章我们已经讲了MQTT服务器的搭建,参看:MQTT再学习--搭建MQTT服务器及测试接下来我们看一下MQTT客户端。一、客户端下载首先,客户端也有多种,我们需要面临选择了。参看:基于mqtt的消息推送(三)客户端实现现有客户端sdk分析,基本分为两大类:一类移植自C类库,如Mosquitto,一类是用o......
  • 图像和流媒体 -- Sapera 安装遇到的问题
    一、下载安装包参看:GenieNanoM1930-NIR点击软件及例程下载二、安装遇到的问题(1)Installationdirectorymustbeonalocalharddrive解决方法:clsicacls%temp%/reset/T/Q/Cpause以上文件复制到txt中将后缀名修改为bat以管理员执行即可。windows自身权限的的问题。(2)安......