歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> redis配置

redis配置

日期:2017/3/3 12:55:45   编辑:Linux技術
本文記錄了安裝Redis和從JAVA端訪問Redis的步驟
從http://download.csdn.net/detail/kkdelta/4034137 下載本文所需文件.
1,在Linux上安裝Redis服務.
下面的操作的base dir為 /root/4setup
tar xzf redis-2.4.6.tar
cd redis-2.4.6
make
安裝完後啟動
nohup src/redis-server &
下面是從http://tech.it168.com/a2011/0830/1239/000001239923.shtml 拷貝過來的詳細步驟
步驟一: 下載Redishttp://download.csdn.net/detail/kkdelta/4034137

步驟二: 編譯源程序
[plain] view
plain copy
[root@localhost 4setup]# ll
總計 29168
-rw-r--r--1 root root455240 2011-07-22 redis-2.2.12.tar.gz
[root@localhost 4setup]# tar xzf redis-2.2.12.tar.gz
[root@localhost 4setup]# cd redis-2.2.12
[root@localhost redis-2.2.12]# make
cd src && make all
make[1]: Entering directory `/root/4setup/redis-2.2.12/src'
步驟三: 啟動Redis服務
[plain] view
plain copy
src/redis-server
[root@localhost redis-2.2.12]# src/redis-server
[6246] 05 Aug 19:17:22 # Warning: no config file specified, using the default config. In order to specify a config file use'redis-server /path/to/redis.conf'
[6246] 05 Aug 19:17:22* Server started, Redis version2.2.12
[6246] 05 Aug 19:17:22 # WARNING overcommit_memory isset to 0! Background save may fail under low memory condition.To fix this issue add'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[6246] 05 Aug 19:17:22* The serveris now readyto accept connectionson port 6379
[6246] 05 Aug 19:17:22- 0 clients connected (0 slaves),539544 bytes in use
Redis 服務端的默認連接端口是 6379。
步驟四: 將Redis作為 Linux 服務隨機啟動
vi /etc/rc.local, 使用vi編輯器打開隨機啟動配置文件,並在其中加入下面一行代碼。
[java] view
plain copy
/root/4setup/redis-2.2.12/src/redis-server
步驟五: 客戶端連接驗證
新打開一個Session輸入:src/redis-cli,如果出現下面提示,那麼您就可以開始Redis之旅了。
[java] view
plain copy
[root@localhost redis-2.2.12]# src/redis-cli
redis 127.0.0.1:6379>
步驟六: 查看Redis日志
查看服務器端session,即可對Redis的運行狀況進行查看或分析了。
[java] view
plain copy
[6246]05 Aug 19:24:33- 0 clients connected (0 slaves),539544 bytes in use
[6246] 05 Aug 19:24:37- Accepted 127.0.0.1:51381
[6246] 05 Aug 19:24:38- 1 clients connected (0 slaves),547372 bytes in use
以上的幾個步驟就OK了!!這樣一個簡單的Redis數據庫就可以暢通無阻地運行起來了。
步驟七: 停止Redis實例
最簡單的方法是在啟動實例的session中,直接使用Control-C來將實例停止。
我們還可以用客戶端來停止服務,如可以用shutdown來停止Redis實例, 具體如下:
[root@localhost redis-2.2.12]#
src/redis-cli
shutdown2,
2,開發客戶端JAVA程序:
在Eclipse裡新建一個JAVAproject,把上面的jar包導入.
下面是一個簡單的示例代碼:
[java] view
plain copy
public static void main(String[] args) {
Jedis jedis = new Jedis("147.151.240.234",6379);
jedis.set("foo", "bar");
String value = jedis.get("foo");
System.out.println(value);
}
Copyright © Linux教程網 All Rights Reserved