欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Redis密碼設(shè)置與訪(fǎng)問(wèn)限制實(shí)現(xiàn)方法

 更新時(shí)間:2020年11月24日 09:48:43   作者:ノGHJ  
這篇文章主要介紹了Redis密碼設(shè)置與訪(fǎng)問(wèn)限制實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

現(xiàn)在用redis緩存熱數(shù)據(jù)越來(lái)越常見(jiàn)了,甚至一些配置,開(kāi)關(guān)等等的東西也寫(xiě)到redis里。原因就是redis簡(jiǎn)單高效。redis里的數(shù)據(jù)也越來(lái)越重要了,例如一些業(yè)務(wù)的中間數(shù)據(jù)會(huì)暫時(shí)存放在redis里,所以限制redis的訪(fǎng)問(wèn)還是很有必要。

本文通過(guò)幾個(gè)手段說(shuō)一下生產(chǎn)環(huán)境中redis的訪(fǎng)問(wèn)權(quán)限控制。

1、綁定網(wǎng)卡bind

redis的配置文件redis.conf中對(duì)于網(wǎng)絡(luò)安全部分有這樣一段話(huà)

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).

這段話(huà)的意思道出了bind的深意:bind的意思是你的redis實(shí)例綁定在哪個(gè)interface上,可以理解成綁定在哪個(gè)網(wǎng)卡上。那么我們有幾個(gè)網(wǎng)卡呢?可以看一下。

$ ifconfig
eth0 Link encap:Ethernet HWaddr 6C:92:BF:22:D7:FC
inet addr:10.93.84.53 Bcast:10.93.84.127 Mask:255.255.255.128

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0

這里就兩個(gè),一個(gè)是eth0以太網(wǎng)卡(10.93.84.53),一個(gè)是本地回路lo(127.0.0.1)。

那么會(huì)有這兩種情況:

1) bind 10.93.84.53 #同一網(wǎng)段的所有主機(jī)都可以連接redis

2) bind 127.0.0.1 #本地回路,那么只有你redis實(shí)例所在的主機(jī)能訪(fǎng)問(wèn)redis

你可以根據(jù)你的需要進(jìn)行使用:

1) 如果你的機(jī)器直接暴露給互聯(lián)網(wǎng),那么你還是慎重的將bind設(shè)置為127.0.0.1吧,否則你相當(dāng)于暴露了你的redis給外部所有攻擊。

2) 如果你再生產(chǎn)環(huán)境中,那么你一般會(huì)需要綁在網(wǎng)卡上,以便其他主機(jī)也能訪(fǎng)問(wèn)redis,那么我們會(huì)有一些其他的方式保證redis數(shù)據(jù)的安全。

2、設(shè)置密碼requirepass

redis.conf里有這樣的配置,設(shè)置了密碼之后。

#requirepass <yourpassword>
requirepass mypass

重啟redis服務(wù)后,你的客戶(hù)端都需要通過(guò)密碼的方式訪(fǎng)問(wèn)redis

# 密碼正確
$ redis-cli -h 10.93.84.53 -p 6379 -a mypass ping
PONG
# 密碼錯(cuò)誤
$ redis-cli -h 10.93.84.53 -p 6379 -a hehe ping
(error) NOAUTH Authentication required.

3、nologin降低賬號(hào)權(quán)限

以較低權(quán)限賬號(hào)運(yùn)行Redis服務(wù),且禁用該賬號(hào)的登錄權(quán)限。另外可以限制攻擊者往敏感寫(xiě)入文件,但是Redis數(shù)據(jù)還是能被黑客訪(fǎng)問(wèn)到,或者被黑客惡意刪除。

禁止Linux用戶(hù)登錄的方法,一般是修改用戶(hù)的shell類(lèi)型為/sbin/nologin

這種方式會(huì)更加人性化一點(diǎn),因?yàn)椴粌H可以禁止用戶(hù)登錄,還可以在禁用登陸時(shí)給提示告訴它這么做的原因。
修改/etc/nologin.txt,沒(méi)有的話(huà)就手動(dòng)新建一個(gè),在里面添加給被禁止用戶(hù)的提示(這種方式的所有用戶(hù)的鎖定信息都在這個(gè)文件中,在登陸時(shí)給與提示)。

其實(shí)就是把/etc/passwd文件里的/bin/bash對(duì)應(yīng)改成/sbin/nologin

[root@host-192-168-1-117 ~]# useradd wangshibo
[root@host-192-168-1-117 ~]# echo "123456"|passwd --stdin wangshibo
Changing password for user wangshibo.
passwd: all authentication tokens updated successfully.
[root@host-192-168-1-117 ~]# cat /etc/passwd|grep wangshibo
wangshibo:x:500:500::/home/wangshibo:/bin/bash
[root@host-192-168-1-117 ~]# sed -i 's#/home/wangshibo:/bin/bash#/home/wangshibo:/sbin/nologin#g' /etc/passwd
[root@host-192-168-1-117 ~]# cat /etc/passwd|grep wangshibo
wangshibo:x:500:500::/home/wangshibo:/sbin/nologin

[root@host-192-168-1-117 ~]# touch /etc/nologin.txt
[root@host-192-168-1-117 ~]# cat /etc/nologin.txt
In order to protect the system security, this type of user is locked!

4、iptables設(shè)置防火墻

在生產(chǎn)環(huán)境中設(shè)置防火墻還是很有必要的。如果正常業(yè)務(wù)中Redis服務(wù)需要被其他服務(wù)器來(lái)訪(fǎng)問(wèn),可以設(shè)置iptables策略?xún)H允許指定的IP來(lái)訪(fǎng)問(wèn)Redis服務(wù)。

在你redis實(shí)例所在的主機(jī),執(zhí)行如下命令。

# 查看iptables規(guī)則配置的規(guī)則
$ iptables -nL --line-number
# 禁止所有的主機(jī)訪(fǎng)問(wèn)本機(jī)6379端口
$ iptables -I INPUT -p TCP --dport 6379 -j DROP
# 打開(kāi)如下的機(jī)器-s指定,這些機(jī)器可以訪(fǎng)問(wèn)本機(jī)的6379端口
$ iptables -I INPUT -s 10.93.21.21 -p tcp --dport 6379 -j ACCEPT
$ iptables -I INPUT -s 10.93.18.34 -p tcp --dport 6379 -j ACCEPT
$ iptables -I INPUT -s 10.93.18.35 -p tcp --dport 6379 -j ACCEPT
$ iptables -I INPUT -s 10.93.84.53 -p tcp --dport 6379 -j ACCEPT
# 保存iptables配置
$ service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
# 重啟防火墻
$ service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]

設(shè)置成功后,只有配置的那四臺(tái)機(jī)器可以訪(fǎng)問(wèn)redis實(shí)例。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Windows中redis設(shè)置密碼的兩種方法

    Windows中redis設(shè)置密碼的兩種方法

    之前寫(xiě)的一個(gè)項(xiàng)目,有項(xiàng)目代碼,有數(shù)據(jù)庫(kù),但是本地沒(méi)redis,沒(méi)法跑此項(xiàng)目,故思考在本地安裝一個(gè)redis做登錄session存儲(chǔ),所以開(kāi)始動(dòng)手實(shí)踐,下面這篇文章主要給大家介紹了關(guān)于Windows中redis設(shè)置密碼的兩種方法,需要的朋友可以參考下
    2023-04-04
  • 如何高效地向Redis插入大量的數(shù)據(jù)(推薦)

    如何高效地向Redis插入大量的數(shù)據(jù)(推薦)

    本篇文章主要介紹了如何高效地向Redis插入大量的數(shù)據(jù),現(xiàn)在分享給大家,感興趣的小伙伴們可以參考一下。
    2016-11-11
  • 詳解redis big key 排查思路

    詳解redis big key 排查思路

    本文主要介紹了詳解redis big key 排查思路,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-06-06
  • Redis實(shí)戰(zhàn)之商城購(gòu)物車(chē)功能的實(shí)現(xiàn)代碼

    Redis實(shí)戰(zhàn)之商城購(gòu)物車(chē)功能的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Redis實(shí)戰(zhàn)之商城購(gòu)物車(chē)功能的實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-02-02
  • springmvc集成使用redis過(guò)程

    springmvc集成使用redis過(guò)程

    這篇文章主要介紹了springmvc集成使用redis過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • redis中的配置以及密碼設(shè)置方式

    redis中的配置以及密碼設(shè)置方式

    這篇文章主要介紹了redis中的配置以及密碼設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • SpringBoot 集成Redis 過(guò)程

    SpringBoot 集成Redis 過(guò)程

    redis是一個(gè)開(kāi)源的、使用C語(yǔ)言編寫(xiě)的、支持網(wǎng)絡(luò)交互的、可基于內(nèi)存也可持久化的Key-Value數(shù)據(jù)庫(kù)。本文給大家介紹SpringBoot 集成Redis 過(guò)程,感興趣的朋友一起看看吧
    2021-06-06
  • Redis數(shù)據(jù)庫(kù)的數(shù)據(jù)傾斜詳解

    Redis數(shù)據(jù)庫(kù)的數(shù)據(jù)傾斜詳解

    Redis,英文全稱(chēng)是Remote Dictionary Server(遠(yuǎn)程字典服務(wù)),是一個(gè)開(kāi)源的使用ANSI C語(yǔ)言編寫(xiě)、支持網(wǎng)絡(luò)、可基于內(nèi)存亦可持久化的日志型、Key-Value數(shù)據(jù)庫(kù),需要的朋友可以參考下
    2023-07-07
  • Redis保證數(shù)據(jù)不丟失的兩種方法

    Redis保證數(shù)據(jù)不丟失的兩種方法

    Redis 實(shí)現(xiàn)數(shù)據(jù)不丟失的關(guān)鍵在于使用了多種持久化機(jī)制,以確保數(shù)據(jù)在內(nèi)存和磁盤(pán)之間的持久性,本文給大家介紹了Redis保證數(shù)據(jù)不丟失的兩種方法,持久化和集群運(yùn)行,我們分別來(lái)看它們兩的具體實(shí)現(xiàn)細(xì)節(jié),感興趣的同學(xué)跟著小編一起來(lái)看看吧
    2023-11-11
  • redis實(shí)現(xiàn)共同好友的思路詳解

    redis實(shí)現(xiàn)共同好友的思路詳解

    微信朋友圈大家都玩過(guò)吧,那么朋友圈的點(diǎn)贊、評(píng)論只能看到自己好友的信息是怎么操作的呢?下面通過(guò)本文給大家分享下此功能的實(shí)現(xiàn)流程,對(duì)redis實(shí)現(xiàn)共同好友的方法感興趣的朋友一起看看吧
    2021-05-05

最新評(píng)論