溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》
  • 首頁 > 
  • 教程 > 
  • 開發(fā)技術(shù) > 
  • Redis的make,make test,make install、單機(jī)多實(shí)例配置,以及API程序?qū)憯?shù)據(jù)!

Redis的make,make test,make install、單機(jī)多實(shí)例配置,以及API程序?qū)憯?shù)據(jù)!

發(fā)布時(shí)間:2020-06-10 19:51:28 來源:網(wǎng)絡(luò) 閱讀:10173 作者:moviebat 欄目:開發(fā)技術(shù)

   最近學(xué)習(xí)王家林老師的大數(shù)據(jù)蘑菇云行動(dòng),要實(shí)現(xiàn)將Spark Streaming分析的數(shù)據(jù)寫入到Redis。今天正好開始入手。

   一、Ubuntu16安裝Redis3.2.1

   遇到了不少的問題,其中,make倒是沒問題,make test的時(shí)候,出現(xiàn)了:


!!! 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取得同步連接,但是我這不是還沒安裝的嗎?


百度,看到了一片文章,說是用這個(gè)命令:make CFLAGS="-march=i686"

但直接就出錯(cuò)了,沒辦法。

忽略這個(gè)錯(cuò)誤,直接運(yùn)行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


權(quán)限?

sudo make 

sudo make install

提示錯(cuò)誤,要進(jìn)入src

好的,OK!


\o/ All tests passed without errors!

Cleanup: may take some time... OK


繼續(xù)出現(xiàn)錯(cuò)誤:

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

NOREPLICAS Not enough good slaves to write.


繼續(xù)找度娘:

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

  這篇文章有說明:

在make test中可能會(huì)遇到時(shí)間相關(guān)的失敗,比如

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

    這種情況下,可以修改文件tests/integration/replication-2.tcl,將after 1000改為after 10000以延長等待時(shí)間。

修改,繼續(xù)出錯(cuò)!

!!! 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

注意看錯(cuò)誤信息,注意看錯(cuò)誤信息,注意看錯(cuò)誤信息!

是修改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'



虛擬機(jī)中安裝的時(shí)候,機(jī)器性能不夠的話,很容易出現(xiàn)上述錯(cuò)誤!換機(jī)器或者更換參數(shù),以及在機(jī)器不忙的時(shí)候進(jìn)行編譯安裝,會(huì)順利通過!

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,進(jìn)入熟悉的界面,看提示,配置文件是

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

算了吧,還是指定一個(gè)配置文件,在上層目錄下,有一個(gè)redis.conf。


 src/redis-server redis.conf


二、配置Redis3.2.1

1、配置生產(chǎn)環(huán)境,并設(shè)置redis的開機(jī)啟動(dòng)。

    首先,建立存放redis配置文件和持久化RDB數(shù)據(jù)的文件夾:

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

    拷貝redis的啟動(dòng)腳本到/etc/init.d文件夾中:

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

    拷貝redis的配置文件到/etc/redis中,并且以端口號(hào)作為文件名:

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

    在/var/redis中創(chuàng)建文件夾作為redis實(shí)例的數(shù)據(jù)和工作目錄:

sudo mkdir /var/redis/6379


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

  • 設(shè)置 demonize 為 yes(默認(rèn)是no)

  • 設(shè)置 pidfile 為 /var/run/redis_6379.pid

  • 設(shè)置 loglevel 為相應(yīng)級別

  • 設(shè)置 logfile 為 /var/log/redis_6379.log

  • 設(shè)置 dir 為 /var/redis/6379

redis-server /etc/redis/6379.conf

redis-cli客戶端連接服務(wù)器,出現(xiàn)>,輸入set name="dyq"

用get name得到dyq。成功!


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

為了能遠(yuǎn)程連接redis服務(wù)器,需要修改/etc/redis/6379.conf,將ip_bind從127.0.0.1修改為192.168.0.10。


三、安裝單機(jī)多實(shí)例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


創(chuàng)建文件目錄:

sudo mkdir /var/redis/6380/

sudo gedit /var/log/redis_6380.log


3、修改主從設(shè)置

將6380.conf中的

slaveof 192.168.0.10 6379


4、驗(yàn)證主從同步

啟動(dòng)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


可以發(fā)現(xiàn)實(shí)文件沒有寫權(quán)限。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


可以看到主從數(shù)據(jù)實(shí)現(xiàn)同步。成功!


四、從IDES遠(yuǎn)程訪問Redis,并寫入數(shù)據(jù)


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI