關(guān)于redis-dump 安裝遇到的問題以及解決方案
安裝平臺: centos7
[root@VM_16_15_centos ~]# redis-dump
-bash: redis-dump: command not found
沒有安裝這個管理工具【不想看過程的可以看末尾精華版】
因為這個工具是基于Ruby
實現(xiàn)的,首先要安裝Ruby
一:安裝Ruby
參考:Ruby官方
示例:centos (模擬輸入和部分輸出, 可以在 install
前面添加 -y
把后面的手動選擇y
自動化)
[root@VM_16_15_centos ~]# yum install ruby
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
二:嘗試安裝 redis-dump
[root@VM_16_15_centos ~]# gem install redis-dump
Fetching: yajl-ruby-1.4.1.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing redis-dump:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h
這里還是報錯
我就不說什么原因了歇父,直接開始解決宫静。先安裝這個
[root@VM_16_15_centos ~]# yum -y install ruby ruby-devel
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Package ruby-2.0.0.648-35.el7_6.x86_64 already installed and latest version
Package ruby-devel-2.0.0.648-35.el7_6.x86_64 already installed and latest version
然后安裝這個
[root@VM_16_15_centos ~]# yum -y install rubygems
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Package rubygems-2.0.14.1-35.el7_6.noarch already installed and latest version
...暫時先別動份招,替換下國內(nèi)源,加個速度,然后再復(fù)制它的提示指令繼續(xù)操作...
替換的指令為
[root@VM_16_15_centos ~]# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
// 查詢狀態(tài)指令
[root@VM_16_15_centos ~]# gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
然后繼續(xù)嘗試安裝
[root@VM_16_15_centos ~]# gem install redis-dump
Fetching: yajl-ruby-1.4.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed yajl-ruby-1.4.0
Fetching: redis-4.0.1.gem (100%)
ERROR: Error installing redis-dump:
redis requires Ruby version >= 2.2.2.
[root@VM_16_15_centos ~]# yum install curl
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
Package curl-7.29.0-51.el7_6.3.x86_64 already installed and latest version
然后通過上一步安裝好的 curl安裝下面的這個, 部分提示如下
[root@VM_16_15_centos ~]# curl -L get.rvm.io | bash -s stable
····部分提示如下····
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
In case of further problems with validation please refer to https://rvm.io/rvm/security
復(fù)制它的指令先改,再繼續(xù)
[root@VM_16_15_centos ~]# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
[root@VM_16_15_centos ~]# curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
然后重試浩蓉,這一步會等比較久
[root@VM_16_15_centos ~]# curl -L get.rvm.io | bash -s stable
這里之后需要使 rvm指令生效
[root@VM_16_15_centos local]# cd /etc/profile.d
[root@VM_16_15_centos local]# ls
這里會看到有個 `rvm.sh` 的文件,然后
[root@VM_16_15_centos profile.d]# source rvm.sh
然后使用一下rvm -v
檢測 rvm
是否可用
可用的話查看 rvm
里面的支持的東西
[root@VM_16_15_centos ~]# rvm list known
因為安裝 那個需要 Ruby 等級大于2.2.2.
我直接安裝了 2.3
[root@VM_16_15_centos ~]# rvm install 2.3
安裝好了之后就可以安裝 redis-dump了
[root@VM_16_15_centos ~]# gem install redis-dump
然后檢測成功了嗎
[root@VM_16_15_centos ~]# redis-dump
[root@VM_16_15_centos ~]# redis-load
Usage: cat dumpfile_db15.json | redis-load -d 15
看來是成功了,讀取一下我存在內(nèi)存中的 redis內(nèi)容看看情況
[root@VM_16_15_centos ~]# redis-dump -u localhost:6379
{"db":0,"key":"hello","ttl":-1,"type":"string","value":"nihao","size":5}
{"db":0,"key":"funny","ttl":-1,"type":"string","value":"kaixin","size":6}
{"db":0,"key":"school","ttl":-1,"type":"string","value":"xuexiao","size":7}
大功告成
精華版
[root@VM_16_15_centos ~]# yum install ruby
[root@VM_16_15_centos ~]# yum -y install ruby ruby-devel
[root@VM_16_15_centos ~]# yum -y install rubygems
[root@VM_16_15_centos ~]# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
[root@VM_16_15_centos ~]# yum install curl
[root@VM_16_15_centos ~]# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
[root@VM_16_15_centos ~]# curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
[root@VM_16_15_centos ~]# curl -L get.rvm.io | bash -s stable
[root@VM_16_15_centos local]# cd /etc/profile.d
[root@VM_16_15_centos profile.d]# source rvm.sh
[root@VM_16_15_centos ~]# rvm install 2.3
[root@VM_16_15_centos ~]# gem install redis-dump
redis-dump和redis-load簡單的幾個操作派继,具體的去百度就好了
以下小括號內(nèi)的內(nèi)容是有密碼的時候需要做的事情
redis-dump -u (:password@)localhost:6379 # 導(dǎo)出0-15號數(shù)據(jù)庫數(shù)據(jù)
------------------------------------------------------------------------------------
// 全局參數(shù)相關(guān):redis-dump [參數(shù)] COMMAND [參數(shù)及操作]
-u 代表Redis鏈接字符串 (上面那一條就用的這個)
-d 代表數(shù)據(jù)庫代號
-s 代表導(dǎo)出之后的休眠時間
-c 代表分塊大小,默認(rèn)10000
-f 代表導(dǎo)出時的過濾器
-O 代表禁用運(yùn)行時優(yōu)化
-V 顯示版本
-D 表示開啟調(diào)試
--------------------------------------------------------------------------------------
redis-dump -u localhost:6379 > ./redis_data.jl # 導(dǎo)出json
redis-sump -u (:password@)localhost:6379 -d 1 > ./redis_data.jl # 只導(dǎo)出1號數(shù)據(jù)庫內(nèi)容
redis-sump -u (:password@)localhost:6379 -f ads1:* > ./redis_data.jl # 導(dǎo)出以adsl開頭的數(shù)據(jù), 加入-f參數(shù)來過濾
< redis_data.json redis-load -u (:password@)localhost:6379 # 將json文件導(dǎo)入redis數(shù)據(jù)庫
cat redis_data.json | redis-load -u (:password@)localhost:6379 # 同樣效果