centos 6.5 安裝、配置redis

來源:互聯網
上載者:User

標籤:release

基於CentOS release 6.5 Final, redis版本3.0.2 [redis版本號碼中間位是偶數的是穩定版,奇數的為非穩定版]

一、安裝redis

1)     下載redis安裝包

可去官網http://redis.io ,也可通過wget命令,

[[email protected] srv]# wget http://download.redis.io/redis-stable.tar.gz 

2)解壓

[[email protected] srv]# tar -zxvf redis-stable.tar.gz 

3)編譯、安裝(編譯安裝安裝Development tools和Desktop Platfrom 開發包組工具)

[[email protected] srv]# cd redis-stable

[[email protected] redis-stable]# ll

total 200

-rw-r--r--.  1 1000 1000 78892 Oct 26 15:17 00-RELEASENOTES

-rw-r--r--.  1 1000 1000    53 Oct 26 15:17 BUGS

-rw-r--r--.  1 1000 1000  1805 Oct 26 15:17 CONTRIBUTING

-rw-r--r--.  1 1000 1000  1487 Oct 26 15:17 COPYING

drwxr-xr-x.  7 1000 1000  4096 Oct 26 15:17 deps

-rw-r--r--.  1 1000 1000    11 Oct 26 15:17 INSTALL

-rw-r--r--.  1 1000 1000   151 Oct 26 15:17 Makefile

-rw-r--r--.  1 1000 1000  4223 Oct 26 15:17 MANIFESTO

-rw-r--r--.  1 1000 1000  6834 Oct 26 15:17 README.md

-rw-r--r--.  1 1000 1000 46695 Oct 26 15:17 redis.conf

-rwxr-xr-x.  1 1000 1000   271 Oct 26 15:17 runtest

-rwxr-xr-x.  1 1000 1000   280 Oct 26 15:17 runtest-cluster

-rwxr-xr-x.  1 1000 1000   281 Oct 26 15:17 runtest-sentinel

-rw-r--r--.  1 1000 1000  7606 Oct 26 15:17 sentinel.conf

drwxr-xr-x.  2 1000 1000  4096 Oct 26 15:17 src

drwxr-xr-x. 10 1000 1000  4096 Oct 26 15:17 tests

drwxr-xr-x.  7 1000 1000  4096 Oct 26 15:17 utils

[[email protected] redis-stable]# make

  CC geo.o

    LINK redis-server

    INSTALL redis-sentinel

    CC redis-cli.o

    LINK redis-cli

    CC redis-benchmark.o

    LINK redis-benchmark

    INSTALL redis-check-rdb

    CC redis-check-aof.o

    LINK redis-check-aof

Hint: It‘s a good idea to run ‘make test‘ ;)

make[1]: Leaving directory `/srv/redis-stable/src‘

[[email protected] redis-stable]# make install

cd src && make install

make[1]: Entering directory `/srv/redis-stable/src‘

Hint: It‘s a good idea to run ‘make test‘ ;)

    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

make[1]: Leaving directory `/srv/redis-stable/src‘

[[email protected] redis-stable]# 

[[email protected] redis-stable]# ls /usr/local/bin

redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

[[email protected] redis-stable]# 

[[email protected] redis-stable]# /usr/local/bin/redis-server -v

Redis server v=3.2.5 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=661b15c1ebfa36b

注意:若此時執行redis-server –v (查看版本命令),若提示redis-server command not found,則需要將/usr/local/bin目錄加到環境變數,如何添加,此處不做詳細介紹,可查看修改/etc/profile,(查看環境變數命令:echo $PATH)

至此,redis安裝完成,接著配置。

二、修改設定檔.conf

1)建立設定檔目錄,dump file目錄,進程目錄,log目錄等

設定檔一般放在/etc/下,建立fedis目錄

[[email protected] redis-stable]# cd /etc/

[[email protected] etc]# mkdir redis

dump file、進程目錄、log目錄等,一般放在/var/目錄下,

[[email protected] etc]# cd redis/

[[email protected] redis]# ls

[[email protected] redis]# cd /var

[[email protected] var]# mkdir redis

[[email protected] var]# cd redis/

[[email protected] redis]# mkdir data log run

[[email protected] redis]# ll

total 12

drwxr-xr-x. 2 root root 4096 Dec  5 15:58 data

drwxr-xr-x. 2 root root 4096 Dec  5 15:58 log

drwxr-xr-x. 2 root root 4096 Dec  5 15:58 run

[[email protected] redis]# 

至此目錄建立完畢。

2)修改設定檔,配置參數

首先拷貝解壓包下的redis.conf檔案至/etc/redis

[[email protected] redis-stable]# cp redis.conf /etc/re

readahead.conf    redhat-lsb/       redhat-release    redis/            resolv.conf       resolv.conf.save

[[email protected] redis-stable]# cp redis.conf /etc/redis/

[[email protected] redis-stable]# vi /etc/redis/redis.conf  最好備份一份redis.conf.bak

# Accept connections on the specified port, default is 6379 (IANA #815344).

# If port 0 is specified Redis will not listen on a TCP socket.

port 6379   

#####修改預設連接埠

# Creating a pid file is best effort: if Redis is not able to create it

# nothing bad happens, the server will start and run normally.

pidfile /var/run/redis_6379.pid

#####修改pid目錄為建立的目錄

# The working directory.

#

# The DB will be written inside this directory, with the filename specified

# above using the ‘dbfilename‘ configuration directive.

#

# The Append Only File will also be created inside this directory.

#

# Note that you must specify a directory here, not a file name.

dir ./

#####修改dump目錄為建立目錄

# Specify the log file name. Also the empty string can be used to force

# Redis to log on the standard output. Note that if you use standard

# output for logging but daemonize, logs will be sent to /dev/null

logfile ""

#####修改log儲存目錄為建立目錄

3)持久化
預設rdb,可選擇是否開啟aof,若開啟,修改設定檔appendonly

4)啟動redis,查看各目錄下檔案

[[email protected] redis-stable]# redis-server /etc/redis/redis.conf 

查看dump,log,pid等

[[email protected] redis]# cd data

[[email protected] data]# ll

total 0

[[email protected] data]# ll../log

-bash: ll../log: No such file or directory

[[email protected] data]# ll ../log

total 4

-rw-r--r--. 1 root root 1861 Dec  5 16:15 redis.log

[[email protected] data]# ll ../run

total 4

-rw-r--r--. 1 root root 6 Dec  5 16:15 redis_6379.pid

[[email protected] data]# 

發現只有日誌,沒有dump和pid資訊,是因為當前redis服務仍然是console模式啟動並執行,且沒有資料存放區操作

停止redis服務,修改設定檔使得redis在background運行

650) this.width=650;" src="http://img.blog.csdn.net/20150804102119940" style="border:none;height:auto;" />

改成yes,儲存,重啟redis服務

5)用戶端串連redis

[[email protected] run]# redis-cli

127.0.0.1:6379>    #####預設連接埠6379

6)至此,redis基礎配置完畢,若有其他相關配置調整,可尋找文檔在修改
三、服務及開機自啟動

 1)建立redis啟動指令碼

拷貝解壓包下utils下redis啟動指令碼至/etc/init.d

[[email protected] redis-stable]# cd /srv/redis-stable/utils/

[[email protected] utils]# cp redis_init_script /etc/init.d/

修改指令碼名稱為redis 並修改指令碼pid及conf路徑為實際路徑

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/8B/21/wKiom1hFKBnDjPSAAACxz8I5Acw322.png-wh_500x0-wm_3-wmp_4-s_2660817963.png" title="Q8.png" alt="wKiom1hFKBnDjPSAAACxz8I5Acw322.png-wh_50" />

至此,在/etc/init.d目錄下,已經可以通過service redis start/stop 啟動/關閉redis服務了。

2、給啟動指令碼添加刪除許可權

#chmod +x /etc/init.d/redis  給啟動指令碼添加許可權

#chmod -x /etc/init.d/redis  刪除許可權

3、設定自啟動

#chkconfig redis on

如果運行報錯,提示

[[email protected] init.d]# chkconfig redis on

service redis does not support chkconfig

是因為沒有在啟動指令碼裡加入redis啟動優先順序資訊,可添加如下

650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/8B/1E/wKioL1hFKgmA0SZ_AACZLQrW7SU504.png-wh_500x0-wm_3-wmp_4-s_2790079623.png" title="442.png" alt="wKioL1hFKgmA0SZ_AACZLQrW7SU504.png-wh_50" />

再次執行chkconfig redis on,成功,至此自啟動配置完畢。

本實驗參考http://blog.csdn.net/ludonqin/article/details/47211109此文檔完成。




centos 6.5 安裝、配置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.