Redis是一個基於內存的,而且可進行持久化的數據庫。redis是以key-value形式進行存儲,且value的數據類型相對比較豐富,支持string,list,set,zset,hash類型,而且支持針對數據的各類操做。redis
從官網下載源代碼進行編譯和安裝數據庫
使用wget命令從官網下載文件ubuntu
wget http://download.redis.io/redis-stable.tar.gz
tar -xzv -f redis-stable.tar.gz //解壓縮剛纔下載下來的源碼包 cd redis-stable //進入到源碼目錄 make //執行make構建程序 sudo make install //安裝並將生成的可執行程序複製到/usr/local/bin中
安裝成功後,會在/usr/local/bin中建立Redis的經常使用的命令文件服務器
附:Reids中經常使用的可執行程序工具
1.3.1 直接啓動性能
redis-server [--port 6379] //直接啓動redis服務進程,--port 可指定監聽端口號
1.3.2 指定配置文件啓動測試
從源碼包中複製redis.conf到/etc/redis目錄下.net
sudo cp redis.conf /etc/redis/6379.conf //文件名爲實際端口號.conf redis-server /etc/redis/6379.conf //啓動Redis
經常使用配置命令行
#是否之後臺模式運行,yes | no daemonize no #可修改默認監聽端口 port 6379 #修改生成默認日誌文件位置 logfile "/home/yalong/logs/redis.log" #配置持久化文件存放位置 dir /home/yalong/data/redisData
1.3.3 使用啓動腳本啓動rest
該方式通常用於生產環境中,使用redis/utils/redis_init_script
腳原本進行啓動.
sudo cp utils/redis_init_script /etc/init.d/redis //複製腳本到啓動腳本目錄
複製後,該腳本還不能直接使用,須要修改其腳本參數,在第一行的!/bin/sh下添加兩行配置信息
#!/bin/sh # chkconfig: 2345 10 90 # description:Start and Stop Redis Service
還須要檢查其餘配置信息,是否正確,若是不是默認的則須要進行手動調整
REDISPORT=6379 //端口號 EXEC=/usr/local/bin/redis-server //服務器路徑 CLIEXEC=/usr/local/bin/redis-cli //客戶端路徑 PIDFILE=/var/run/redis_${REDISPORT}.pid //屬性文件路徑 CONF="/etc/redis/${REDISPORT}.conf" //配置文件路徑
而後就能夠經過如下命令使用service方式啓動了
sudo service redis start/stop/restart sudo chkconfig redis on //設置是否開啓自動啓動
chkconfig是redhat系列的發行版的工具,ubuntu系列沒有.....
問題
若是在啓動時出現如下報錯,則還須要修改systemctl設置
unit redis.service not load sudo systemctl enable redis.service
檢查運行狀況
ps -aux | grep redis yalong[@yalong](https://my.oschina.net/u/1272088):~/redis-stable$ ps -aux | grep redis --輸出-- yalong 11276 0.0 0.7 43484 3904 pts/0 Sl 23:47 0:00 redis-server *:6379 yalong 11298 0.0 0.1 12944 932 pts/0 S+ 23:51 0:00 grep redis
從以上結果能夠看出redis-server已經在運行中,且監聽6379端口。
redis-cli shutdown //使用客戶端發送shutdown命令關閉redis server kill -9 pid //使用進程號來直接關閉redis server