[TOC]linux
本篇文章將介紹在三大主流操做系統(Linux,mac,windows)上安裝redis。git
Linux上的安裝介紹自沒必要說,不多有人用除了Linux以外的其餘操做系統在生成環境下部署redis吧……github
可是在開發的時候,頗有可能不是在Linux環境下開發的,有必要在本身的操做系統上裝一個來開發測試用。因此此處也介紹在mac和windows下的安裝。redis
wget http://download.redis.io/releases/redis-3.2.8.tar.gz tar -zxvf redis-3.2.8.tar.gz
cd redis-3.2.8 make PREFIX=/usr/local/bin install # 目錄能夠本身指定
至此,安裝完成,能夠看看生成了哪些東西shell
# 在/usr/local/bin下,已經在環境變量裏了 [root@h4 redis-3.2.8]$ ls -l /usr/local/bin/ total 26348 -rwxr-xr-x. 1 root root 5580319 Apr 4 15:27 redis-benchmark -rwxr-xr-x. 1 root root 22185 Apr 4 15:27 redis-check-aof -rwxr-xr-x. 1 root root 7829986 Apr 4 15:27 redis-check-rdb -rwxr-xr-x. 1 root root 5709187 Apr 4 15:27 redis-cli lrwxrwxrwx. 1 root root 12 Apr 4 15:27 redis-sentinel -> redis-server -rwxr-xr-x. 1 root root 7829986 Apr 4 15:27 redis-server
複製redis.confvim
# 從redis解壓目錄將redis.conf配置文件複製到/data/redis # 此處的/data/redis目錄是本人的習慣,按你本身的須要來就行 cp redis.conf /data/redis/
修改配置文件windows
# 編輯配置文件/data/redis/redis.conf # 修改如下幾項 vim /data/redis/redis.conf # 後臺模式運行 daemonize yes # 修改日誌文件路徑 logfile "/data/redis/log.log" # 關閉保護模式,雖然這樣不安全,可是從其餘主機鏈接redis時是要關閉保護模式的 protected-mode no
[root@h4 redis-3.2.8]$ utils/install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] /data/redis/redis.conf Please select the redis log file name [/var/log/redis_6379.log] /data/redis/log.log Please select the data directory for this instance [/var/lib/redis/6379] /data/redis Please select the redis executable path [/usr/local/bin/redis-server] Selected config: Port : 6379 Config file : /data/redis/redis.conf Log file : /data/redis/log.log Data dir : /data/redis Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! /var/run/redis_6379.pid exists, process is already running or crashed Installation successful!
若是你執行了步驟1.4,即你把redis作成了系統服務,能夠像下面這樣操做:安全
# 啓動Redis [root@h4 redis-3.2.8]$ service redis_6379 start Starting Redis server... # 查看redis進程 [root@h4 redis-3.2.8]$ ps -ef | grep redis root 17160 1 0 15:43 ? 00:00:00 /usr/local/bin/redis-server 127.0.0.1:6379 root 17164 3968 0 15:43 pts/1 00:00:00 grep --color redis # 查看redis使用的端口 [root@h4 redis-3.2.8]$ netstat -tnpl | grep 6379 tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 17160/redis-server # 鏈接客戶端測試 [root@h4 redis-3.2.8]$ redis-cli -p 6379 127.0.0.1:6379> ping PONG 127.0.0.1:6379> exit # 中止Redis [root@h4 redis-3.2.8]$ service redis_6379 stop Stopping ... Redis stopped
若是沒有作成系統服務,能夠像下面這樣操做:bash
# 啓動Redis [root@h4 redis-3.2.8]# redis-server /data/redis/redis.conf # 查看redis進程 [root@h4 redis-3.2.8]# ps -ef | grep redis root 17238 1 0 15:48 ? 00:00:00 redis-server 127.0.0.1:6379 root 17243 3968 0 15:48 pts/1 00:00:00 grep --color redis # 查看redis使用的端口 [root@h4 redis-3.2.8]# netstat -tlnp | grep 6379 tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 17238/redis-server # 鏈接客戶端測試 [root@h4 redis-3.2.8]# redis-cli -p 6379 127.0.0.1:6379> ping PONG 127.0.0.1:6379> exit # 中止Redis [root@h4 redis-3.2.8]# redis-cli shutdown
其實在mac下安裝和在Linux(CentOS-6.8-x64)下是很是相似的。網絡
在mac下安裝redis最簡單的方式就是使用brew install redis
來一鍵搞定了。
若是你不喜歡瞎折騰,就是要最快的傻瓜式安裝,那你就用上面的brew install redis
吧。
不然,能夠參考咱們這裏介紹的手動編譯安裝的方式:
$ wget http://download.redis.io/releases/redis-3.2.8.tar.gz $ tar -zxvf redis-3.2.8.tar.gz
$ cd redis-3.2.8/ $ make PREFIX=/usr/local/bin/redis install
因爲此處我將redis安裝到了/usr/local/bin/redis,不是默認的/usr/local/bin,因此得改下環境變量
$ vim ~/.bash_profile # 加入以下配置 export redis_home=/usr/local/bin/redis export PATH=$PATH:$redis_home/bin # 刷新環境變量 $ source ~/.bash_profile # 看看配好沒? $ which redis-server /usr/local/bin/redis/bin/redis-server
複製redis.conf
$ mkdir /usr/local/etc/redis $ cp redis.conf /usr/local/etc/redis
編輯配置文件
$ cd /usr/local/etc/redis/ $ vim redis.conf # 按需修改以下幾項 # 綁定全部網絡地址 bind 0.0.0.0 # 數據目錄(需事先手動創建目錄) dir /Users/hylexus/data/redis/6379/ # 日誌文件(需事先手動創建目錄) logfile "/Users/hylexus/data/redis/log.log" # 後臺運行 daemonize yes # 關閉保護模式 protected-mode no
# 啓動Redis $ redis-server /usr/local/etc/redis/redis.conf # 查看redis進程 $ ps -ef | grep redis 501 5456 1 0 4:47下午 ?? 0:00.01 redis-server 0.0.0.0:6379 # 鏈接客戶端 $ redis-cli -p 6379 # 測試 127.0.0.1:6379> ping PONG 127.0.0.1:6379> ping redis "redis" 127.0.0.1:6379> exit # 中止Redis $ redis-cli shutdown
如下是redis官網下載頁面的部分截圖:
也就是說redis是不支持windows的。
可是Microsoft Open Tech group
維護了一個windows版本的redis。
地址在這裏:https://github.com/MSOpenTech...。
去這裏下載個msi安裝包安裝就好了:https://github.com/MSOpenTech...。
一路狂點鼠標[Next],安裝完成便可。
有點須要注意的 最好在安裝的時候勾選將redis可執行文件加入環境變量
具體的步驟請看這裏:https://raw.githubusercontent...
C:\Program Files\Redis>redis-server --service-install redis.windows-service.conf --loglevel verbose
能夠去服務窗口看看:
配置文件都在安裝目錄下:C:/Program Files/Redis
按需修改便可.
直接去windows提供的服務管理控制檯(3.2中的截圖)最方便
命令方式以下:
# 啓動Redis # 注意:若是已經啓動了,會提示錯誤。可是錯誤並不會告訴你已經啓動了……………… C:\Users\hylexus> redis-server --service-start [13032] 04 Apr 17:58:42.168 # HandleServiceCommands: system error caught. error code=1056, message = StartService failed: unknown error # 先中止,再試試啓動會不會正常 C:\Users\hylexus> redis-server --service-stop [5308] 04 Apr 17:58:47.284 # Redis service successfully stopped. # 再次嘗試啓動[成功] C:\Users\hylexus> redis-server --service-start [15200] 04 Apr 17:58:52.940 # Redis service successfully started. # 鏈接客戶端測試 C:\Program Files\Redis>redis-cli -p 6379 127.0.0.1:6379> ping PONG 127.0.0.1:6379> ping haha "haha" 127.0.0.1:6379> exit # 中止服務 C:\Program Files\Redis>redis-server --service-stop [18564] 04 Apr 17:59:22.700 # Redis service successfully stopped. C:\Program Files\Redis>