Redis的make,make test,make install、单机多实例配置,以及API程序写数据!

发布时间:2020-06-10 19:51:28 作者:moviebat
来源:网络 阅读:10173

   最近学习王家林老师的大数据蘑菇云行动,要实现将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


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

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. PHP编译,执行make报错
  2. 不要轻易相信make

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

ubuntu 单机 redis

上一篇:KVM虚拟化基本部署

下一篇:GitHub:我们是这样弃用jQuery的

相关阅读

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

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