redis单机版安装详细

1.执行下面命令需要依赖环境,因为redis是c++写的

[root@localhost ~]# yum install gcc-c++

2.

[root@localhost ~]# tar zxvf redis-4.0.1.tar.gz

3.

[root@localhost ~]# cd redis-4.0.1/

4.编译解压后的源码

[root@localhost redis-4.0.1]# make

5.安装到指定目录中(此目录就是运行redis的目录,如果要卸载重装的话直接把这个文件夹删除即可)

[root@localhost redis-4.0.1]# make PREFIX=/usr/local/redis install

扫描二维码关注公众号,回复: 3682702 查看本文章

6.把解压目录下的redis.conf文件拷贝到redis目录,并进入bin文件夹,修改配置文件

[root@localhost redis-4.0.1]# cp redis.conf /usr/local/redis/bin/

bin下面的命令解释如下:

redis-benchmark  #性能测试的一个工具

redis-check-aof  #文件修复的一个工具

redis-check-dump  #文件检查的一个工具

redis-cli         #命令行的客户端

redis-server #redis服务器启动的命令

[root@localhost redis-4.0.1]# cd /usr/local/bin

vim  redis.conf

修改的内容如下:

daemonize no 改为daemonize yes    意思是改为后端启动

protected-mode yes 中的yes改为no   意思是不要密码,jedis和redis连接工具都可以在外部环境连上,如果不设置,必须密码才能连上

bind 127.0.0.1    找到这一行改为   #bind 127.0.0.1     意思是外部机器可以连接,如果不改只对本机器开放连接

7.后端启动看下成功没

[root@localhost bin]# ./redis-server ./redis.conf 
61596:C 19 Oct 16:10:28.050 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
61596:C 19 Oct 16:10:28.050 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=61596, just started
61596:C 19 Oct 16:10:28.050 # Configuration loaded

[root@localhost bin]# ps -ef |grep redis
root     61597     1  0 16:10 ?        00:00:00 ./redis-server *:6379    表示成功启动
root     61619  5635  0 16:11 pts/0    00:00:00 grep --color=auto redis

[root@localhost bin]# ./redis-cli -p 6379      客户端命令连接
127.0.0.1:6379> ping 
PONG
127.0.0.1:6379> 

此时用redis desktop manager是连接不上的,因为tcp并没有将6379开放,除非你本机防火墙是关闭的

8.开放tcp 6379为开放端口的操作

CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

根据自己的版本查看有没有安装过iptables,我的这里是firewall,直接关闭防火墙即可

命令如下:

systemctl stop firewalld.service         #停止firewall

systemctl disable firewalld.service        #禁止firewall开机启动

redis desktop manager  可以连上了,单机版redis安装到此成功!!!

[root@localhost bin]# rpm -qa|grep iptables
iptables-1.4.21-24.el7.x86_64

firewall有以下的命令:

systemctl start firewalld.service  开启防火墙

firewall-cmd --state 查看防火墙状态

firewall-cmd --reload #重启firewall

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --zone=public --add-port=83/tcp --permanent

firewall-cmd --zone=public --add-port=89/tcp --permanent

firewall-cmd --zone=public --add-port=6379/tcp --permanent

(2)没有的话,可以安装iptables防火墙

yum install  

编辑防火墙配置文件打开指定的端口号使用udp协议打开6379redis端口:

vi /etc/sysconfig/iptables 

修改如下

猜你喜欢

转载自blog.csdn.net/m0_37712901/article/details/83183417