redis设置防火墙的问题

Linux 下载安装配置Redis完整步骤

 

安装:

1.获取redis资源

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

2.解压

  tar xzvf redis-4.0.8.tar.gz

3.安装

  cd redis-4.0.8

  make

  cd src

  make install PREFIX=/usr/local/redis

4.移动配置文件到安装目录下

  cd ../

  mkdir /usr/local/redis/etc

  mv redis.conf /usr/local/redis/etc

5.配置redis为后台启动

  vi /usr/local/redis/etc/redis.conf //将daemonize no 改成daemonize yes

6.将redis加入到开机启动

  vi /etc/rc.local //在里面添加内容:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (意思就是开机调用这段开启redis的命令)

7.开启redis

  /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf

8.配置 redis-cli 环境

sudo vim /etc/profile

写入: export PATH=</usr/local/redis/bin/redis-cli>:$PATH

  即可在任意路径下使用命令redis-cli 启动redis客户端

常用命令  

  redis-server /usr/local/redis/etc/redis.conf //启动redis

  pkill redis  //停止redis

  卸载redis:

    rm -rf /usr/local/redis //删除安装目录

    rm -rf /usr/bin/redis-* //删除所有redis相关命令脚本

    rm -rf /root/download/redis-4.0.4 //删除redis解压文件夹

来自:https://www.cnblogs.com/lauhp/p/8487029.html

查找防火墙的位置状态

[root@localhost demo]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 三 -- :: PST; 2min 43s ago
Docs: man:firewalld()
Main PID: (firewalld)
CGroup: /system.slice/firewalld.service
└─ /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid 3月 :: localhost.localdomain systemd[]: Starting firewalld - dynamic fir....
3月 :: localhost.localdomain systemd[]: Started firewalld - dynamic fire....
Hint: Some lines were ellipsized, use -l to show in full.

关闭防火墙:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
systemctl start firewalld.service   #开启防火墙

如果你在redis中设置了密码想要修改不要密码可以使用

config set requirepass ""

当你设置了密码输入密码时都需要加上一个

auth admin    #admin是设置的密码

在防火墙中添加端口 6379

[root@localhost /]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
Warning: ALREADY_ENABLED: 6379:tcp
success

然后重启防火墙

[root@localhost /]# firewall-cmd --reload
success

查询所有的开放的端口号

[root@localhost /]# firewall-cmd --list-port
/tcp

③查询linux本地Ip,执行ifconfig

[root@localhost /]# ip addr
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN qlen
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
valid_lft forever preferred_lft forever
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::::fe brd ff:ff:ff:ff:ff:ff
inet 192.168.111.130/ brd 192.168.111.255 scope global dynamic ens33
valid_lft 1417sec preferred_lft 1417sec
inet6 fe80::eb6e:fbad:27d5:9c4a/ scope link
valid_lft forever preferred_lft forever
: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu qdisc noqueue state DOWN qlen
link/ether :::5c:: brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/ brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
: virbr0-nic: <BROADCAST,MULTICAST> mtu qdisc pfifo_fast master virbr0 state DOWN qlen
link/ether :::5c:: brd ff:ff:ff:ff:ff:ff
[root@localhost /]#

但是,xinetd和telnet的服务都启动不了,telnet连服务名都不存在:

#systemctl status telnet.socket
如果显示inactive则表示没有打开请执行
# systemctl enable telnet.socket 加入开机启动
# systemctl start telnet.socket 启动Telnet服务
# systemctl status telnet.socket 再次查看服务状态

systemctl stop firewalld.service,使用这个停用防火墙,应该是这个问题,7使用的是Firewall防火墙

(https://www.cnblogs.com/gyrgyr/p/7954090.html)

[root@localhost ~]# systemctl status telnet.socket
● telnet.socket - Telnet Server Activation Socket
Loaded: loaded (/usr/lib/systemd/system/telnet.socket; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:telnetd()
Listen: [::]: (Stream)
Accepted: ; Connected:
[root@localhost ~]# systemctl start telnet.socket
[root@localhost ~]# systemctl status telnet.cocket
Unit telnet.cocket.service could not be found.
[root@localhost ~]# systemctl status telnet.socket
● telnet.socket - Telnet Server Activation Socket
Loaded: loaded (/usr/lib/systemd/system/telnet.socket; disabled; vendor preset: disabled)
Active: active (listening) since 日 -- :: PDT; 28s ago
Docs: man:telnetd()
Listen: [::]: (Stream)
Accepted: ; Connected: 4月 :: localhost.localdomain systemd[]: Listening on Telnet Server Activ....
4月 :: localhost.localdomain systemd[]: Starting Telnet Server Activatio....
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# ps -ef|grep redis
root : pts/ :: redis-server *:
root : pts/ :: grep --color=auto redis
[root@localhost ~]# telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'. Kernel 3.10.-.el7.x86_64 on an x86_64
[root@andy ~]# telnet 192.168.120.204
Trying 192.168.120.204...
Connected to 192.168.120.204 (192.168.120.204).
Escape character is '^]'. localhost (Linux release 2.6.-274.18..el5 # SMP Thu Feb :: EST ) () login: root
Password:
Login incorrect

一般情况下不允许root从远程登录,可以先用普通账号登录,然后再用su -切到root用户。

下载安装iptables

yum install iptables

启动   /bin/systemctl start iptables.service

关闭   /bin/systemctl start iptables.service

如果遇到问题   (https://blog.csdn.net/c233728461/article/details/52679558)

报错Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.

或  Failed to start iptables.service: Unit not found.

[root@localhost ~]# firewall-cmd --zone=public --add-port=/tcp --permanent
success
[root@localhost ~]# firewall-cmd --zone=public --add-port=-/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --zone=public --query-port=/tcp
yes
[root@localhost ~]# yum install iptables-services

设置开机启动: systemctl enable iptables

保存设置:   service iptables save

开放某个端口 在/etc/sysconfig/iptables里添加

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

 redis 设置密码

查询密码:

redis 127.0.0.1:6379> config get requirepass

因为初始没有密码,所以无需输入,即可连接服务。

redis-cli.exe -h 127.0.0.1 -p 6379

上一篇:js的重载


下一篇:python 调用c语言函数