Redis在Linux的安装(CentOS)
方案一:自行编译安装
官网上给出的安装流程如下:
1 2 3 4 |
$ wget http://download.redis.io/releases/redis-3.2.3.tar.gz $ tar xzf redis-3.2.3.tar.gz $ cd redis-3.2.3 $ make |
编译完成后二进制文件放在src文件夹下
执行 src/redis-server 即可启动服务。
上述的流程非常的简单,而实际安装过程中并没有这么简单。
1、安装开发包组
1 |
yum groupinstall "Development Tools" -y |
2、获取安装文件
1 |
wget http://download.redis.io/releases/redis-3.2.3.tar.gz |
3、解压文件,并移动到需要安装的目录
1 2 |
tar -xzvf redis-3.2.3.tar.gz mv redis-3.2.3 /usr/local/redis |
4、进入目录编译安装
1 2 3 4 |
cd /usr/local/redis make make install make test |
5、设置配置文件路径
1 2 |
mkdir -p /etc/redis cp redis.conf /etc/redis |
6、修改配置文件,设置以后台程序方式运行
1 2 |
vi /etc/redis/redis.conf 仅修改: daemonize yes (no-->yes) |
7、启动
1 |
/usr/local/bin/redis-server /etc/redis/redis.conf |
8、查看启动
1 |
ps -ef | grep redis |
10、使用客户端
如果redis-cli没有反应,重启下服务器就可以了(具体原因未知)
1 2 3 |
[root@localhost ~]# redis-cli 127.0.0.1:6379> ping PONG |
11、关闭客户端
1 |
redis-cli shutdown |
12、开机启动配置
CentOS 6 开机启动:
开机启动要配置在 rc.local 中,而 /etc/profile 文件,要有用户登录了,才会被执行。
1 |
echo "/usr/local/bin/redis-server /etc/redis/redis.conf &" >> /etc/rc.local |
CentOS 7 开机启动:
创建文件:/usr/lib/systemd/system/redis.service,文件内容为:
1 2 3 4 5 6 7 8 9 10 |
[Unit] Description=Redis persistent key-value database After=network.target [Service] ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --daemonize no ExecStop=/usr/bin/redis-shutdown [Install] WantedBy=multi-user.target |
然后建立软链接:
1 |
ln -s /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service |
13、开放防火墙端口:
CentOS 6.7:
1 2 3 |
iptables -I INPUT -p tcp -m tcp --dport 6379 -j ACCEPT /etc/rc.d/init.d/iptables save service iptables restart |
CentOS 7:
centos7以后,内置的防火墙从iptables变成了firewalld。
1 2 |
firewall-cmd --permanent --zone=public --add-service=redis-server firewall-cmd --reload |
方案二:使用Yum安装(CentOS 7)
1、安装epel
1 |
yum -y install epel-release |
2、执行执行redis的安装
1 |
yum -y install redis |
3、修改相关的配置,配置文件所在位置:
1 2 |
/etc/redis.conf /etc/redis-sentinel.conf |
4、启动、停止、重启redis服务器和查看Redis服务器状态
1 2 3 4 |
systemctl start redis.service systemctl stop redis.service systemctl restart redis.service systemctl status redis.service |
5、打开或关闭开机启动
1 2 |
systemctl enable redis.service systemctl disable redis.service |
Redis在Windows上的安装
下载地址:https://github.com/MSOpenTech/redis/releases
在解压的目录下运行: redis-server redis.windows.conf 即可启动Redis。
可以通过双击目录下的redis-cli.exe 打开客户端工具。
其实Redis是可以安装成windows服务的,开机自启动,命令如下:
1 |
redis-server --service-install redis.windows-service.conf --loglevel verbose |
安装完之后,就可看到Redis已经作为windows服务。但是安装好之后,Redis并没有启动,启动、关闭命令如下:
1 2 |
redis-server --service-start redis-server --service-stop |
另外还可以安装多个实例
1 2 3 4 5 6 |
redis-server --service-install –service-name redisService1 –port 10001 redis-server --service-start –service-name redisService1 redis-server --service-install –service-name redisService2 –port 10002 redis-server --service-start –service-name redisService2 redis-server --service-install –service-name redisService3 –port 10003 redis-server --service-start –service-name redisService3 |
卸载服务命令:
1 |
redis-server --service-uninstall |
Windows下Redis GUI管理工具推荐:http://redisdesktop.com/
参考地址:
打赏作者
