Redis学习笔记二 CentOS下的基本操作

1.下载编辑安装

cd /usr/local/src
wget -c http://redis.googlecode.com/files/redis-3.0.1.tar.gz
或
wget http://download.redis.io/releases/redis-3.0.1.tar.gz
tar zxvf redis-3.0.1.tar.gzcd redis-3.0.1make

2.另一种安装方式(推荐使用,控制命令使用方便一点)

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
sudo rpm -ivh epel-release-7-5.noarch.rpm
sudo yum -y update
sudo yum install redis -y
启动
sudo systemctl start redis.service
sudo systemctl status redis.service
测试 
redis-cli ping
redis-benchmark -q -n 1000 -c 10 -P 5

配置
sudo vi /etc/redis.conf
sudo systemctl restart redis.service
//默认bind 127.0.0.1是无法远程连接的,如果要远程连接,要改为bind 0.0.0.0
//在配置文件可以找到数据库文件位置:
//dbfilename dump.rdb
//dir /var/lib/redis/
//下面安装redis-stat 需要ruby支持,下面是安装ruby的
sudo yum install ruby
sudo yum install gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel
sudo yum install ruby-rdoc ruby-devel

//也行需要运行下面几句,更换源
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l

sudo gem install redis-stat
sudo chmod go-w /usr/local
sudo chmod go-w /usr/sbin
sudo chmod go-w /usr/bin
sudo chmod go-w /usr/java

3.使用

查看版本
redis-server --version

Redis-benchmark
Redis基准信息,redis服务器性能检测

redis-benchmark -h localhost -p 6379 -c 100 -n 100000
100个并发连接,100000个请求,检测host为localhost 端口为6379的redis服务器性能


停止
redis-cli shutdown

监控
redis-cli -h localhost -p 6380 monitor

统计信息
redis-cli -h localhost -p 6380 info

总体信息
redis-stat host localhost port 6380 overview

本机可直接运行redis-stat


请求时长
redis-stat host localhost port 6380 overview


可以在redis-cli下输入下列命令:

  • info
  • monitor

参考:http://redis.io/commands/INFO


4.配置启动脚本

新建文件,放在/etc/init.d下,命名为redis

###########################  
PATH=/usr/local/bin:/sbin:/usr/bin:/bin  
     
REDISPORT=6379  
EXEC=/usr/local/bin/redis-server  
REDIS_CLI=/usr/local/bin/redis-cli  
     
PIDFILE=/var/run/redis.pid  
CONF="/etc/redis.conf"  
     
case "$1" in  
    start)  
        if [ -f $PIDFILE ]  
        then  
                echo "$PIDFILE exists, process is already running or crashed"  
        else  
                echo "Starting Redis server..."  
                $EXEC $CONF  
        fi  
        if [ "$?"="0" ]   
        then  
              echo "Redis is running..."  
        fi  
        ;;  
    stop)  
        if [ ! -f $PIDFILE ]  
        then  
                echo "$PIDFILE does not exist, process is not running"  
        else  
                PID=$(cat $PIDFILE)  
                echo "Stopping ..."  
                $REDIS_CLI -p $REDISPORT SHUTDOWN  
                while [ -x ${PIDFILE} ]  
               do  
                    echo "Waiting for Redis to shutdown ..."  
                    sleep 1  
                done  
                echo "Redis stopped"  
        fi  
        ;;  
   restart|force-reload)  
        ${0} stop  
        ${0} start  
        ;;  
  *)  
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
        exit 1  
esac  
##############################  

赋予可执行权限

chmod +x /etc/init.d/redis

设置开机启动

sudo chkconfig redis on

启动关闭

service redis start   #或者 /etc/init.d/redis start  
service redis stop    #或者 /etc/init.d/redis stop  



参考:

https://www.digitalocean.com/community/tutorials/how-to-configure-a-redis-cluster-on-centos-7


你可能感兴趣的:(redis,centos,服务器)