Redis的make,make test,make install、單機多執行個體配置,以及API程式寫資料!

來源:互聯網
上載者:User

標籤:redis3.2.1 ubuntu 單機多執行個體

   最近學習王家林老師的大資料蘑菇雲行動,要實現將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!

有多少坑!!!


[email protected]:~/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/redissudo 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


[email protected]:~/Documents/redis-3.2.1$ src/redis-server.sh /etc/redis/6380.conf

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

[email protected]:~/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,並寫入資料


Redis的make,make test,make install、單機多執行個體配置,以及API程式寫資料!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.