linux安装redis

下载Redis

官网:https://redis.io/download

百度云网盘:https://pan.baidu.com/s/1Sd4C4KRqT1rogbo0DFgOfQ

提取码:1jsc

 

2.下载的redis上传至linux

(1)解压redis安装包

1
tar -zxvf redis-5.0.5.tar.gz

 

(2)把redis-5.0.5放到/usr/local/目录下

1
mv -f redis-5.0.5 /usr/local/

  

(3)进入redis-5.0.5目录

1
cd /usr/local/redis-5.0.5/

  

(4)安装gcc  redis是c语言编写的

1
yum install gcc-c++

  

(5)编译

1
make

  

(7)安装

1
make install PREFIX=/usr/local/redis

  

(8)拷贝redis.conf到安装目录

1
cp redis.conf /usr/local/redis

  

(9)进入 /usr/local/redis目录

1
cd /usr/local/redis/

  

(10)创建log数据存放文件

1
mkdir log

  

(11)编辑redis.conf 

1
vim redis.conf

  

1
2
3
4
5
6
7
1.后台启动,daemonize yes
    
2.绑定的主机地址,bind 192.168.146.128 127.0.0.1(注:通过这ip192.168.146.128地址和本地127.0.0.1能够访问到个redis服务)
(bind 0.0.0.0  如果绑定到0.0.0.0那么所有机器上的地址都可以访问redis服务)<br>
3.指定数据文件存放目录,dir /usr/local/redis/log rdb存放的路径<br>
4.指定持久化方式,appendonly yes<br>
5.requirepass 123456 设置密码

  

(12)开放linux 6379 端口

编辑 /etc/sysconfig/iptables 文件

1
vi /etc/sysconfig/iptables

加入内容并保存

1
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 6379 -j ACCEPT

  

(13)后端启动redis:

1
./bin/redis-server ./redis.conf

  

(14)查看是否启动成功:、

1
ps aux | grep redis

  

(15)进入客户端

1
2
./bin/redis-cli -h IP地址 -p 6379 -a 密码
./bin/redis-cli -h 192.168.146.128 -p 6379 -a 123456<br>或者使用<br>./bin/redis-cli

 

进入客户端设置密码 

config set requirepass 123456

 

 

(16)关闭redis进程

当设置密码后,上面的关闭命令无效:带密码输入:    redis-cli -a [password]     回车后输入:shutdown

shutdown还有一个参数,代表关闭redis服务前是否生产持久化文件

shutdown save

 

例如:

1
2
3
4
5
6
7
[root@localhost redis]# ./bin/redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> shutdown save
not connected> exit
[root@localhost redis]# ps aux | grep redis
root      3370  0.0  0.0 103248   828 pts/0    S+   21:15   0:00 grep redis
[root@localhost redis]#

  

(17) 查看进程

1
ps aux | grep redis

  

(18)杀死进程

1
kill -9 pid

例如:

1
2
3
4
5
6
7
[root@localhost redis]# ps aux | grep redis
root      3384  0.0  0.7 152412  7812 ?        Ssl  21:16   0:00 ./bin/redis-server 192.168.146.128:6379
root      3389  0.0  0.0 103248   832 pts/0    S+   21:16   0:00 grep redis
[root@localhost redis]# kill -9 3384
[root@localhost redis]# ps aux | grep redis
root      3401  0.0  0.0 103248   832 pts/0    S+   21:17   0:00 grep redis
[root@localhost redis]#

  

 

posted @   Amy清风  阅读(225)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示