温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

redis的搭建过程

发布时间:2021-08-30 18:39:11 来源:亿速云 阅读:112 作者:chen 栏目:关系型数据库

本篇内容介绍了“redis的搭建过程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

redis官网:http://download.redis.io/releases

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

redis的搭建过程

[root@localhost init.d]# redis-cli -a 123 --bigkeys -i 0.01

扫描大key

redis的搭建过程

主从同步:

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。

“redis的搭建过程”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI