Centos7下的Redis安装

一、下载Redis

手动下载地址:http://download.redis.io/releases/

wget http://download.redis.io/releases/redis-5.0.3.tar.gz

二、解压Redis

tar -zxvf redis-5.0.3.tar.gz 

三、编译安装

#下面操作如果报gcc错误,需要先安装gcc,yum install -y gcc
cd redis-5.0.3/
make MALLOC=libc
cd src && make install

成功安装的提示:

    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

四、启动

直接启动
#如果当前模式安装,会自动添加全局快捷方式
#直接执行下面命令可以启动redis
redis-server
后台方式启动

方式一:

  • 修改redis.conf文件
    daemonize no
    修改为
    daemonize yes
  • 指定redis配置文件启动
redis-server /usr/local/redis-4.0.6/redis.conf 

方式二:

 nohup redis-server &
后台方式启动的关闭
ps -ef|grep redis
#root      7767  5357  0 10:31 pts/1    00:00:00 redis-server *:6379
kill -9 7767

五、设置远程连接

编辑 redis.conf文件
bind 127.0.0.1这一行注释掉,或者bind 0.0.0.0
protected-mode 要设置成no
重启redis

六、防火墙配置

参考https://blog.csdn.net/irokay/article/details/72717132
切记:ssh远程访问时,不要把22端口删掉,22是ssh连接的端口。
各种数据库需要的默认端口:https://www.jianshu.com/p/50f15b3d0de6

#清除所有规则,开放所有端口
iptables -F

下面是我的一个iptables的配置

# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
#-A INPUT -p tcp -m state --state NEW -m multiport tcp --dport 1433,1521,3306,5000,5432,6379,9092,11211,27017 -j ACCEPT
-A INPUT -m state --state NEW -p tcp -m multiport --dport 1433,1521,3306,5000,5432,6379,9092,11211,27017 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8000:8888 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

你可能感兴趣的:(Centos7下的Redis安装)