天天看點

Redis安裝

可以從官網擷取tcl的最新版本,官網也有詳細的安裝步驟

# wget http://downloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz 

# tar xf tcl8.6.0-src.tar.gz  

# cd tcl8.6.0/unix/ 

# ./configure --prefix=/usr \ 

            --mandir=/usr/share/man \ 

            $([ $(uname -m) = x86_64 ] && echo --enable-64bit) && 

make && 

sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \ 

    -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \ 

    -i tclConfig.sh 

# make test 

# make install && make install-private-headers && ln -v -sf tclsh8.6 /usr/bin/tclsh && chmod -v 755 /usr/lib/libtcl8.6.so 

# tclsh8.6  //有這個指令表示安裝成功 

redis官網:http://redis.io/

# tar xf redis-2.6.2.tar.gz  

# cd redis-2.6.2 

# make 

# make install 

# cp redis.conf /etc/ 

# vi /etc/sysctl.conf //如果已經配置過這裡了,可以忽略,如果沒有,一定要配置 vm.overcommit_memory = 1

# redis-server /etc/redis.conf 

# netstat -nutlp | grep 6379 | grep -v grep //看到以下表示redis啟動成功 

6379          0.0.0.0:*               LISTEN      14845/xinetd    

# vi /etc/init.d/redis

#!/bin/bash  

# Init file for redis  

# chkconfig: - 80 12  

# description: redis daemon  

# processname: redis  

# TITLE END 

# Source function library. 

. /etc/rc.d/init.d/functions 

BIN="/usr/local/bin"  

CONFIG="/etc/redis.conf"  

PIDFILE="/var/run/redis.pid"  

prog="redis-server"  

desc="Redis Server"  

start() {  

        if [ -e $PIDFILE ];then  

             echo "$desc already running...."  

             exit 1  

        fi  

        echo -n $"Starting $desc: "  

        daemon $BIN/$prog $CONFIG  

        RETVAL=$?  

        echo  

        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog  

        return $RETVAL  

}  

stop() {  

        echo -n $"Stop $desc: "  

        killproc $prog  

        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE  

restart() {  

        stop  

        start  

case "$1" in  

  start)  

        ;;  

  stop)  

  restart)  

        restart  

  status)  

        status $prog  

   *)  

        echo $"Usage: $0 {start|stop|restart|condrestart|status}"  

        RETVAL=1  

esac  

exit $RETVAL 

# chmod 755 /etc/init.d/redis 

# chkconfig --add redis 

# chkconfig --level 345 redis on 

# chkconfig --list redis 

redis預設會把日志列印到螢幕上,并且不是以daemon的模式運作,可以改下配置檔案

# vi /etc/redis.conf 

#daemonize no   //預設為no,注釋掉,新增一行改為yes 

daemonize yes 

# Set server verbosity to 'debug' 

# it can be one of: 

# debug (a lot of information, useful for development/testing) 

# verbose (many rarely useful info, but not a mess like the debug level) 

# notice (moderately verbose, what you want in production probably) 

# warning (only very important / critical messages are logged) 

loglevel notice   //這裡定義日志的級别,預設為notice 

#logfile stdout    //這裡指定Redis的日志檔案位置 

logfile /var/log/redis.log 

配置完成後,重新開機下Redis,看一下Redis的日志吧

[root@node3 ~]# cat /var/log/redis.log  

[3779] 07 Apr 12:23:42.340 * Max number of open files set to 10032 

                _._                                                   

           _.-``__ ''-._                                              

      _.-``    `.  `_.  ''-._           Redis 2.6.2 (00000000/0) 64 bit 

  .-`` .-```.  ```\/    _.,_ ''-._                                    

 (    '      ,       .-`  | `,    )     Running in stand alone mode 

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379 

 |    `-._   `._    /     _.-'    |     PID: 3779 

  `-._    `-._  `-./  _.-'    _.-'                                    

 |`-._`-._    `-.__.-'    _.-'_.-'|                                   

 |    `-._`-._        _.-'_.-'    |           http://redis.io         

  `-._    `-._`-.__.-'_.-'    _.-'                                    

 |    `-._`-._        _.-'_.-'    |                                   

      `-._    `-.__.-'    _.-'                                        

          `-._        _.-'                                            

              `-.__.-'                                                

[3779] 07 Apr 12:23:42.344 # Server started, Redis version 2.6.2 

[3779] 07 Apr 12:23:42.344 * The server is now ready to accept connections on port 6379 

OK,到此基本配置已經配置完成

Redis有一個指令,可以檢視目前redis的狀态資訊,非常的全面

運作redis-cli info

[root@node3 ~]# redis-cli info 

# Server 

redis_version:2.6.2 

redis_git_sha1:00000000 

redis_git_dirty:0 

redis_mode:standalone 

os:Linux 2.6.32-358.el6.x86_64 x86_64 

arch_bits:64 

multiplexing_api:epoll 

gcc_version:4.4.7 

process_id:4034 

run_id:f9500377d415b0a5912c45e12100c074768d5c41 

tcp_port:6379 

uptime_in_seconds:5 

uptime_in_days:0 

lru_clock:216250 

# Clients 

connected_clients:1 

client_longest_output_list:0 

client_biggest_input_buf:0 

blocked_clients:0 

# Memory 

used_memory:846336 

used_memory_human:826.50K 

used_memory_rss:2015232 

used_memory_peak:787864 

used_memory_peak_human:769.40K 

used_memory_lua:31744 

mem_fragmentation_ratio:2.38 

mem_allocator:jemalloc-3.0.0 

# Persistence 

loading:0 

rdb_changes_since_last_save:0 

rdb_bgsave_in_progress:0 

rdb_last_save_time:1365311304 

rdb_last_bgsave_status:ok 

rdb_last_bgsave_time_sec:-1 

rdb_current_bgsave_time_sec:-1 

aof_enabled:0 

aof_rewrite_in_progress:0 

aof_rewrite_scheduled:0 

aof_last_rewrite_time_sec:-1 

aof_current_rewrite_time_sec:-1 

aof_last_bgrewrite_status:ok 

# Stats 

total_connections_received:1 

total_commands_processed:0 

instantaneous_ops_per_sec:0 

rejected_connections:0 

expired_keys:0 

evicted_keys:0 

keyspace_hits:0 

keyspace_misses:0 

pubsub_channels:0 

pubsub_patterns:0 

latest_fork_usec:0 

# Replication 

role:master 

connected_slaves:0 

# CPU 

used_cpu_sys:0.01 

used_cpu_user:0.01 

used_cpu_sys_children:0.00 

used_cpu_user_children:0.00 

# Keyspace 

詳細的先不解釋了, 等有空再解釋吧。

# yum install git 

# git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git 

# cd phpRedisAdmin 

# git submodule init 

# git submodule update 

 然後通路

http://youip/phpRedisAdmin

<a href="http://blog.51cto.com/attachment/201304/175031629.jpg" target="_blank"></a>

本文轉自 gm100861 51CTO部落格,原文連結:http://blog.51cto.com/gm100861/1175569