redis搭建

redis 安装包    redis-3.2.13.tar.gz
解压:tar -xvf redis-3.2.13.tar.gz
把解压的redis放在你准备的目录下面,我放在根/ 下面。
cd redis-3.2.13 make
编译好了,进入src文件下面;
[root@localhost src]# make install Hint: It's a good idea to run 'make test' ;)    INSTALL install    INSTALL install    INSTALL install    INSTALL install    INSTALL install [root@localhost src]#
返回上一层,
[root@localhost redis-3.2.13]# pwd
/redis-3.2.13
[root@localhost redis-3.2.13]# vim redis.conf
bind 0.0.0.0   如果别人要访问修改成0.0.0.0,默认是本机连接
daemonize yes   默认不是后台启动,我们修改成yes
requirepass 123  去掉#号,修改密码,重启生效,
timeout 10
现在启动redis,我们设置了后台启动的,所以不会显示什么:
[root@localhost redis-3.2.13]# ./src/redis-server /redis-3.2.13/redis.conf
查看进程:
[root@localhost redis-3.2.13]# ps -ef|grep redis root      4434     1  0 10:54 ?        00:00:00 ./src/redis-server 127.0.0.1:6379 root      4506   818  0 10:55 pts/2    00:00:00 grep --color=auto redis
进入redis:
[root@localhost redis-3.2.13]# redis-cli -a 123 127.0.0.1:6379> 127.0.0.1:6379> config get dir 1) "dir" 2) "/redis-3.2.13" 127.0.0.1:6379>
下面可做可不做,方便后面维护而已:
进入redis安装目录:
[root@localhost ~]# cd /redis-3.2.13/utils/ [root@localhost utils]# ll total 52 -rw-rw-r--. 1 root root  593 Mar 19 00:25 build-static-symbols.tcl -rw-rw-r--. 1 root root 1303 Mar 19 00:25 cluster_fail_time.tcl -rw-rw-r--. 1 root root 1070 Mar 19 00:25 corrupt_rdb.c drwxrwxr-x. 2 root root   60 Mar 19 00:25 create-cluster -rwxrwxr-x. 1 root root 2137 Mar 19 00:25 generate-command-help.rb drwxrwxr-x. 2 root root   39 Mar 19 00:25 hashtable drwxrwxr-x. 2 root root   70 Mar 19 00:25 hyperloglog -rwxrwxr-x. 1 root root 8529 Mar 19 00:25 install_server.sh drwxrwxr-x. 2 root root   39 Mar 19 00:25 lru -rw-rw-r--. 1 root root 1277 Mar 19 00:25 redis-copy.rb -rwxrwxr-x. 1 root root 1098 Mar 19 00:25 redis_init_script -rwxrwxr-x. 1 root root 1047 Mar 19 00:25 redis_init_script.tpl -rw-rw-r--. 1 root root 1762 Mar 19 00:25 redis-sha1.rb drwxrwxr-x. 2 root root  114 Mar 19 00:25 releasetools -rwxrwxr-x. 1 root root 3787 Mar 19 00:25 speed-regression.tcl -rwxrwxr-x. 1 root root  693 Mar 19 00:25 whatisdoing.sh [root@localhost utils]# vim redis_init_script REDISPORT=6379 EXEC=/usr/local/bin/redis-server    --找到redis-server,我的在/redis-3.2.13/src CLIEXEC=/usr/local/bin/redis-cli    --找到redis-server,我的在/redis-3.2.13/src PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/etc/redis/${REDISPORT}.conf"     ---配置文件在安装目录下面/redis-3.2.13,注意redis.confg名字 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        ;;    stop)        if [ ! -f $PIDFILE ]        then                echo "$PIDFILE does not exist, process is not running"        else                PID=$(cat $PIDFILE)                echo "Stopping ..."                $CLIEXEC -p $REDISPORT shutdown    ----注意密码问题 -a password                while [ -x /proc/${PID} ]                do                    echo "Waiting for Redis to shutdown ..."                    sleep 1                done                echo "Redis stopped"        fi        ;;    *)        echo "Please use start or stop as first argument"        ;; esac
修改好了,就把这个文件/etc/init.d下面,改名redis
[root@localhost utils]# mv redis_init_script /etc/init.d/redis [root@localhost utils]# chmod +x /etc/init.d/redis
修改好了,停一下报错,发现还没有配置好:
[root@localhost utils]# service redis stop Stopping ... (error) NOAUTH Authentication required. Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ... Waiting for Redis to shutdown ...
找到问题了,原来是/etc/init.d/redis下面的脚本缺少-a 密码认证
[root@localhost init.d]# service redis stop Stopping ... Redis stopped
配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上/etc/sysctl.conf加上 
#vim /etc/sysctl.conf
vm.overcommit_memory = 1 
#sysctl -p 
vi /etc/profile
export PATH="$PATH:/redis-3.2.13/src"    这个位置就是redis-server和redis-cli的位置
redis状态监测:
[root@localhost init.d]# redis-cli -a 123 --stat
[root@localhost init.d]# redis-cli -a 123 --bigkeys -i 0.01
扫描大key
主从同步:
1,先修改从库的配置文件
slaveof 主库ip 端口
2,重启从库
3,登录从库,slaveof 主库ip 端口   ----开启主从同步
遇到的问题。
1,从库配置文件添加了slaveof,但是从主不同步,查看info,
repl_backlog_active:0   显示的为0
解决办法:重启从库,执行slaveof no one,再执行slaveof 主ip+端口,
redis使用命令:
127.0.0.1:6379> config get dir 1) "dir" 2) "/apps/redis/data/master" 127.0.0.1:6379>
info 查看redis的基本信息
1、protected-mode
#protected-mode yes #是否开启保护模式,默认开启。要是配置里没有指定bind和密码。开启该参数后,redis只会 本地进行访问,拒绝外部访问。要是开启了密码 和bind,可以开启。否 则最好关闭,设置为no。


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31434355/viewspace-2652501/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31434355/viewspace-2652501/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值