Redis--------基于centos6源碼安裝
【引自asd1123509133的博客】1. 背景
前一章介紹了memecached安裝,此次介紹NoSQL另一款明星產(chǎn)品----->redis.
許多Web 應(yīng)用程序都將數(shù)據(jù)保存到RDBMS中,應(yīng)用服務(wù)器從中讀取數(shù)據(jù)并在瀏覽器中顯示。但隨著數(shù)據(jù)量的增大,訪問的集中,就會出現(xiàn)REBMS的負擔(dān)加重,數(shù)據(jù)庫響應(yīng)惡化,網(wǎng)站顯示延遲等重大影響。Memcached是高性能的分布式內(nèi)存緩存服務(wù)器。一般的使用目的是通過緩存數(shù)據(jù)庫查詢結(jié)果,減少數(shù)據(jù)庫的訪問次數(shù),以提高動態(tài)Web 應(yīng)用的速度、提高擴展性.
* redis比memcached優(yōu)勢
- 豐富的數(shù)據(jù)類型: redis支持二進制的string list hashe set zset五大基礎(chǔ)數(shù)據(jù)類型存儲.
- 原子性:redis的所有操作都是原子性的,同時redis還支持對幾個操作全并后的原子性執(zhí)行.
- 消息訂閱: redis支持publish/subscribe。
- 持久化存儲數(shù)據(jù): redis支持Aof與RDB兩種數(shù)據(jù)持久化支持.
2. 環(huán)境
3 安裝(/usr/local/src)
- 下載: 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/redis-3.2.8 install
- 創(chuàng)建軟鏈接: ln -s /usr/local/redis-3.2.8 /usr/local/redis
4. 配置文件(當(dāng)前還在redis源碼目錄[/usr/local/src/redis-3.2.8]內(nèi))
cp redis.conf /etc/redis.conf
編輯/etc/redis.conf
daemonize no ==> daemonize yes (設(shè)置redis為后臺daemon進程)
5. 創(chuàng)建redis用戶
- [root@redis-server ~]# useradd -r -s /sbin/nologin -M redis
6. 創(chuàng)建啟動腳本/etc/init.d/redis
- #!/bin/sh
- #
- # redis init file for starting up the redis daemon
- #
- # chkconfig: - 20 80
- # description: Starts and stops the redis daemon.
- # Source function library.
- #!/bin/sh
- #
- # redis init file for starting up the redis daemon
- #
- # chkconfig: - 20 80
- # description: Starts and stops the redis daemon.
- # Source function library.
- . /etc/rc.d/init.d/functions
- name="redis-server"
- exec="/usr/local/redis/bin/$name"
- pidfile="/var/run/redis/redis.pid"
- REDIS_CONFIG="/etc/redis.conf"
- [ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
- lockfile=/var/lock/subsys/redis
- start() {
- [ -f $REDIS_CONFIG ] || exit 6
- [ -x $exec ] || exit 5
- echo -n $"Starting $name: "
- daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
- retval=$?
- echo
- [ $retval -eq 0 ] && touch $lockfile
- return $retval
- }
- stop() {
- echo -n $"Stopping $name: "
- killproc -p $pidfile $name
- retval=$?
- echo
- [ $retval -eq 0 ] && rm -f $lockfile
- return $retval
- }
- restart() {
- stop
- start
- }
- reload() {
- false
- }
- rh_status() {
- status -p $pidfile $name
- }
- rh_status_q() {
- rh_status >/dev/null 2>&1
- }
- case "$1" in
- start)
- rh_status_q && exit 0
- $1
- ;;
- stop)
- rh_status_q || exit 0
- $1
- ;;
- restart)
- $1
- ;;
- reload)
- rh_status_q || exit 7
- $1
- ;;
- force-reload)
- force_reload
- ;;
- status)
- rh_status
- ;;
- condrestart|try-restart)
- rh_status_q || exit 0
- restart
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
- exit 2
- esac
- exit $?
7. 修改腳本文件權(quán)限
- [root@redis-server ~]# chmod 755 /etc/init.d/redis
8. 添加進service服務(wù)管理并設(shè)置開機啟動
- [root@redis-server ~]# chkconfig --add redis
- [root@redis-server ~]# chkconfig redis on
9. redis服務(wù)測試
- service redis start
10. 連接測試(通過自帶redis-cli命令連接測試)
- [root@redis-server ~]# /usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379
連接測試成功
11. 總結(jié)
以需求驅(qū)動技術(shù),技術(shù)本身沒有優(yōu)略之分,只有業(yè)務(wù)之分。