Redis的make,make test,make install、单机多实例配置,以及API程序写数据!
admin
2023-08-03 14:00:07
0次

   最近学习王家林老师的大数据蘑菇云行动,要实现将Spark Streaming分析的数据写入到Redis。今天正好开始入手。

   一、Ubuntu16安装Redis3.2.1

   遇到了不少的问题,其中,make倒是没问题,make test的时候,出现了:


!!! WARNING The following tests failed:


*** [err]: Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl

Replication not started.

Cleanup: may take some time... OK

Makefile:215: recipe for target 'test' failed

make[1]: *** [test] Error 1

make[1]: Leaving directory '/home/dyq/Documents/redis-3.2.1/src'

Makefile:6: recipe for target 'test' failed

make: *** [test] Error 2


貌似是没有和master取得同步连接,但是我这不是还没安装的吗?


百度,看到了一片文章,说是用这个命令:make CFLAGS="-march=i686"

但直接就出错了,没办法。

忽略这个错误,直接运行make install吧:

cd src && make install

make[1]: Entering directory '/home/dyq/Documents/redis-3.2.1/src'


Hint: It's a good idea to run 'make test' ;)


    INSTALL install

install: cannot create regular file '/usr/local/bin/redis-server': Permission denied

Makefile:256: recipe for target 'install' failed

make[1]: *** [install] Error 1

make[1]: Leaving directory '/home/dyq/Documents/redis-3.2.1/src'

Makefile:9: recipe for target 'install' failed

make: *** [install] Error 2


权限?

sudo make 

sudo make install

提示错误,要进入src

好的,OK!


\o/ All tests passed without errors!

Cleanup: may take some time... OK


继续出现错误:

[exception]: Executing test client: NOREPLICAS Not enough good slaves to write..

NOREPLICAS Not enough good slaves to write.


继续找度娘:

https://my.oschina.net/u/1049845/blog/203370

  这篇文章有说明:

在make test中可能会遇到时间相关的失败,比如

Executing test client: NOREPLICAS Not enough good slaves to write..

    这种情况下,可以修改文件tests/integration/replication-2.tcl,将after 1000改为after 10000以延长等待时间。

修改,继续出错!

!!! WARNING The following tests failed:


*** [err]: PEXPIRE/PSETEX/PEXPIREAT can set sub-second expires in tests/unit/expire.tcl

Expected 'somevalue {}' to equal or match '{} {}'

*** [err]: Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl

Replication not started.

Cleanup: may take some time... OK

Makefile:215: recipe for target 'test' failed

make: *** [test] Error 1

注意看错误信息,注意看错误信息,注意看错误信息!

是修改tests/unit/expire.tcl:

  tags {"slow"} {

        test {EXPIRE - After 2.1 seconds the key should no longer be here} {

            after 21000

            list [r get x] [r exists x]

        } {{} 0}

    }


    test {EXPIRE - write on expire should work} {

        r del x

        r lpush x foo

        r expire x 10000

        r lpush x bar

        r lrange x 0 -1

    } {bar foo}


终于看到了绿色:

\o/ All tests passed without errors!

有多少坑!!!


dyq@ubuntu:~/Documents/redis-3.2.1$ sudo make install

cd src && make install

make[1]: Entering directory '/home/dyq/Documents/redis-3.2.1/src'


Hint: It's a good idea to run 'make test' ;)


    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

    INSTALL install

make[1]: Leaving directory '/home/dyq/Documents/redis-3.2.1/src'



虚拟机中安装的时候,机器性能不够的话,很容易出现上述错误!换机器或者更换参数,以及在机器不忙的时候进行编译安装,会顺利通过!

GIT上的说明:


For timing issues, one test isn't very representative. Did you try running them 5-10 times? Is there anything unusual about your machine (very small memory, very slow, shared, overloaded, etc)? Some of the tests are based on timing, so if the machine can't deliver results in time then tests can't complete properly. (you can manually edit some of the tests to increase the timeout waiting)

在src目录下,输入redis-server,进入熟悉的界面,看提示,配置文件是

29181:C 06 Oct 13:48:16.321 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server 

/path/to/redis.conf

算了吧,还是指定一个配置文件,在上层目录下,有一个redis.conf。


 src/redis-server redis.conf


二、配置Redis3.2.1

1、配置生产环境,并设置redis的开机启动。

    首先,建立存放redis配置文件和持久化RDB数据的文件夹:

sudo mkdir /etc/redis
sudo mkdir /var/redis

    拷贝redis的启动脚本到/etc/init.d文件夹中:

sudo cp utils/redis_init_script /etc/init.d/redis_6379

    拷贝redis的配置文件到/etc/redis中,并且以端口号作为文件名:

sudo cp redis.conf /etc/redis/6379.conf

    在/var/redis中创建文件夹作为redis实例的数据和工作目录:

sudo mkdir /var/redis/6379


    按下面要求修改配置文件:

  • 设置 demonize 为 yes(默认是no)

  • 设置 pidfile 为 /var/run/redis_6379.pid

  • 设置 loglevel 为相应级别

  • 设置 logfile 为 /var/log/redis_6379.log

  • 设置 dir 为 /var/redis/6379

redis-server /etc/redis/6379.conf

redis-cli客户端连接服务器,出现>,输入set name="dyq"

用get name得到dyq。成功!


redis的官方配置文档地址为:http://redis.io/topics/quickstart

为了能远程连接redis服务器,需要修改/etc/redis/6379.conf,将ip_bind从127.0.0.1修改为192.168.0.10。


三、安装单机多实例Redis


1、拷贝配置文件

cp /etc/6379.conf /etc/6380.conf

 cp /etc/6379.conf /etc/6381.conf


2、修改配置文件

sudo gedit /etc/6380.conf

修改

 bind 192.168.0.10

port 6380     

daemonize yes     

logfile /var/log/redis_6380.log       

dir /var/redis/6380/

pidfile /var/run/redis_6380.pid


创建文件目录:

sudo mkdir /var/redis/6380/

sudo gedit /var/log/redis_6380.log


3、修改主从设置

将6380.conf中的

slaveof 192.168.0.10 6379


4、验证主从同步

启动6380和6381


dyq@ubuntu:~/Documents/redis-3.2.1$ src/redis-server.sh /etc/redis/6380.conf

-bash: src/redis-server.sh: No such file or directory

dyq@ubuntu:~/Documents/redis-3.2.1$ src/redis-server /etc/redis/6380.conf


*** FATAL CONFIG FILE ERROR ***

Reading the configuration file, at line 163

>>> 'logfile /var/log/redis6380.log'

Can't open the log file: Permission denied


可以发现实文件没有写权限。sudo chown dyq /var/log/redis6380.log


src/redis-cli -h 192.168.0.10 -p 6379

>set name='testredis'

>get name


从库登录:

src/redis-cli -h 192.168.0.10 -p 6380

>get name


src/redis-cli -h 192.168.0.10 -p 6381

>get name


可以看到主从数据实现同步。成功!


四、从IDES远程访问Redis,并写入数据


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...