Linux(Redis)常用操作
阿新 • • 發佈:2021-08-13
- Redis相關
#在bin目錄下開啟redis後臺服務(不在bin目錄下也能啟動redis-server,這樣只是為了在bin目錄下生成dump.rdb檔案) [root@localhost bin]# redis-server /etc/redis.conf #在bin目錄下客戶端連線redis [root@localhost bin]# redis-cli [root@localhost ~]# /usr/local/bin/redis-cli #連線相應埠的Redis服務 [root@localhost myredis]# redis-cli -p 6380 #檢視redis服務程序 [root@localhost bin]# ps -ef | grep redis #關閉redis服務:殺程序或者shutdown: [root@localhost bin]# ps -ef | grep redis 檢視redis [root@localhost bin]# kill -9 程序號 結束redis程序 先shutdown後exit 關閉redis #檢視防火牆狀態 systemctl status firewalld #關掉防火牆 systemctl stop firewalld 或 systemctl stop/disable firewalld.service
- Redis叢集相關
#開啟Redis服務 [root@localhost myredis]# redis-server redis6380.conf #客戶端連線服務 [root@localhost myredis]# redis-cli -p 6380 #開啟哨兵服務 [root@localhost myredis]# redis-sentinel sentinel.conf #快速刪除類似檔案操作 [root@localhost myredis]# rm -rf dump63* 刪除以dump63*開頭的檔案 #統一替換操作 :%s/6379/6380 將6379替換為6380 #將六個節點合成一個叢集(須在src資料夾下操作:cd /opt/redis-6.2.1/src) redis-cli --cluster create --cluster-replicas 1 host1:6379 host2:6380 host3:6381 host4:6389 host5:6390 host6:6391 #叢集搭建成功後顯示的插槽數量 16384 slots covered
- Linux相關
vim /etc/redis.conf 檢視已存在檔案或新建不存在檔案 i 表示修改 esc 退出修改 :wq! 儲存並退出 :q! 退出 / 表示搜尋 ::set nu 開啟(配置檔案)行號 ctrl+c 停止 ll 檢視列表 mkdir /myredis 在根目錄下建立myredis資料夾 rm -rf 檔名 刪除該檔案 mv 原檔名 新檔名 修改檔名稱 關機 shutdown(先sync) 立即關機 halt 重啟 reboot
- Redis整合SpringBoot配置檔案
spring: redis: database: 0 # Redis資料庫索引(預設為0) host: *.*.*.* #Redis伺服器地址 port: 6379 #埠 password: #連結伺服器的密碼預設為空 lettuce: pool: max-active: 200 #連線池最大連線數(使用負值表示沒有限制) max-wait: -1 #連線池最大阻塞時間(使用負值表示沒有限制) max-idle: 10 #連線池中的最大空閒連線 min-idle: 0 #連線池中的最小空閒連線 timeout: 1800000 #連線超時時間(毫秒)