Redis的安裝和配置單一實例篇

來源:互聯網
上載者:User

標籤:redis redis 安裝配置

一、Redis簡介

      Redis 是一個開源(BSD許可)的,記憶體中的資料結構儲存系統,它可以用作資料庫、緩衝和訊息中介軟體。 它支援多種類型的資料結構,如 字串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 與範圍查詢, bitmaps, hyperloglogs 和 地理空間(geospatial) 索引半徑查詢。 Redis 內建了 複製(replication),LUA指令碼(Lua scripting), LRU驅動事件(LRU eviction),事務(transactions) 和不同層級的 磁碟持久化(persistence), 並通過 Redis哨兵(Sentinel)和自動 分區(Cluster)提供高可用性(high availability)。

二、安裝環境介紹

作業系統:CentOS 6.5(核心版本 2.6.32-431.el6.x86_64)

快取資料庫:Redis 3.0.7

三、安裝Redis

1、建立工具目錄(養成好的習慣也是有必要的)

[[email protected] ~]# mkdir -p /home/oldcat/tools

2、建立redis安裝目錄

[[email protected] ~]# mkdir -p /application/redis-3.0.7

3、將下載好的redis安裝包上傳至工具目錄(也可以直接使用wget命令下載到工具目錄)並解壓

[[email protected] tools]# lsredis-3.0.7.tar.gz[[email protected] tools]# tar xf redis-3.0.7.tar.gz [[email protected] tools]# cd redis-3.0.7[[email protected] redis-3.0.7]# ls00-RELEASENOTES  BUGS  CONTRIBUTING  COPYING  deps  INSTALL  Makefile  MANIFESTO  README  redis.conf  runtest  runtest-cluster  runtest-sentinel  sentinel.conf  src  tests  utils

3、安裝redis依賴包

[[email protected] redis-3.0.7]# yum install -y gcc tcl

4、編譯並安裝redis

[[email protected] redis-3.0.7]# make......內容省略[[email protected] redis-3.0.7]# make install PREFIX=/application/redis-3.0.7/......內容省略

5、配置軟連結

[[email protected] ~]# ln -s /application/redis-3.0.7/ /application/redis

四、配置Redis

1、配置環境變數並生效

[[email protected] bin]# echo "PATH=/application/redis/bin:$PATH" >> /etc/profile[[email protected] bin]# . /etc/profile

2、建立redis設定檔目錄,拷貝相關設定檔

[[email protected] bin]# mkdir /application/redis/conf[[email protected] bin]# cp /home/oldcat/tools/redis-3.0.7/redis.conf /application/redis/conf/6379.conf # redis單一實例模式修改檔案名稱不是必須的

3、修改設定檔中相關參數,如下所示:

[[email protected] ~]# vim /application/redis/conf/6379.conf daemonize yes # 此處修改為yes,以守護進程模式運行pidfile /var/run/redis_6379.pid # 修改PID檔案名稱,增加連接埠號碼(同樣單一實例模式非必須)logfile "/application/redis/logs/6379.log" # 增加日誌目錄及檔案名稱

4、建立日誌存放目錄

[[email protected] ~]# mkdir /application/redis/logs/

5、拷貝redis啟動指令碼到/etc/init.d/目錄下,並重新命名為redis

[[email protected] ~]# cp /home/oldcat/tools/redis-3.0.7/utils/redis_init_script /etc/init.d/redis

6、修改redis啟動指令碼,相關參數如下所示:

[[email protected] ~]# vim /etc/init.d/redisREDISHOME=/application/redis # 聲明redis家目錄EXEC=$REDISHOME/bin/redis-serverCLIEXEC=$REDISHOME/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="$REDISHOME/conf/${REDISPORT}.conf" # 指定設定檔所在目錄

7、配置完成,啟動redis並查看進程及連接埠號碼

[[email protected] ~]# /etc/init.d/redis startStarting Redis server...[[email protected] ~]# ps -ef|grep redisroot      5061     1  0 19:18 ?        00:00:00 /application/redis/bin/redis-server *:6379                           root      5065  1474  0 19:19 pts/0    00:00:00 grep redis[[email protected] ~]# ss -lntup|grep 6379tcp    LISTEN     0      128                    *:6379                  *:*      users:(("redis-server",5061,5))tcp    LISTEN     0      128                   :::6379                 :::*      users:(("redis-server",5061,4))

8、執行用戶端命令並測試

[[email protected] ~]# redis-cli127.0.0.1:6379> set num 100OK127.0.0.1:6379> get num"100"127.0.0.1:6379> incr num(integer) 101127.0.0.1:6379> decr num(integer) 100127.0.0.1:6379> del num(integer) 1127.0.0.1:6379> get num(nil)

9、關閉redis服務

[[email protected] ~]# /etc/init.d/redis stopStopping ...Redis stopped[[email protected] ~]# ps -ef|grep redisroot      5104  1474  0 19:26 pts/0    00:00:00 grep redis [[email protected] ~]# ss -lntup|grep 6379[[email protected] ~]#

至此redis安裝配置完成。

Redis的安裝和配置單一實例篇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.