linux安装redis

下载Redis

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

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

提取码:1jsc

 

2.下载的redis上传至linux

(1)解压redis安装包

tar -zxvf redis-5.0.5.tar.gz

 

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

mv -f redis-5.0.5 /usr/local/

  

(3)进入redis-5.0.5目录

cd /usr/local/redis-5.0.5/

  

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

 yum install gcc-c++

  

(5)编译

make

  

(7)安装

make install PREFIX=/usr/local/redis

  

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

 cp redis.conf /usr/local/redis

  

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

cd /usr/local/redis/

  

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

mkdir log

  

(11)编辑redis.conf 

vim redis.conf

  

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服务)
3.指定数据文件存放目录,dir /usr/local/redis/log rdb存放的路径
4.指定持久化方式,appendonly yes
5.requirepass 123456 设置密码

  

(12)开放linux 6379 端口

编辑 /etc/sysconfig/iptables 文件

vi /etc/sysconfig/iptables

加入内容并保存

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

  

(13)后端启动redis:

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

  

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

 ps aux | grep redis

  

(15)进入客户端

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

 

进入客户端设置密码 

config set requirepass 123456

 

 

(16)关闭redis进程

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

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

shutdown save

 

例如:

[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) 查看进程

ps aux | grep redis

  

(18)杀死进程

kill -9 pid

例如:

[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 @ 2020-05-15 20:27  Amy清风  阅读(220)  评论(0编辑  收藏  举报