目錄介紹:
0.Windows下下載安裝包:
下載地址: https://redis.io/
1.上傳到linux服務器
將文件上傳到192.168.2.128主機的usr/local目錄下:
C:\Users\li\Desktop>scp ./redis-4.0.2.tar.gz root@192.168.2.128:/usr/local root@192.168.2.128's password: redis-4.0.2.tar.gz 100% 1674KB 3.7MB/s 00:00 C:\Users\li\Desktop>
SSH遠程登錄到linux服務器:
C:\Users\li>SSH root@192.168.2.128 root@192.168.2.128's password: Welcome to Ubuntu 13.10 (GNU/Linux 3.11.0-12-generic i686) * Documentation: https://help.ubuntu.com/ 0 packages can be updated. 0 updates are security updates. Last login: Sat Nov 4 03:14:54 2017 from 192.168.2.1 root@test:~#
進入/usr/local目錄查看文件:
root@test:/usr/local# ll | grep redis-4.0.2.tar.gz -rw-r--r-- 1 root root 1713990 Nov 4 03:13 redis-4.0.2.tar.gz
2.解壓安裝
解壓:
root@test:/usr/local# tar xzf redis-4.0.2.tar.gz
進入目錄編譯(因為是C語言寫的,所以需要對源語言進行編譯)
root@test:/usr/local# ls bin games lib redis-4.0.2 sbin src etc include man redis-4.0.2.tar.gz share root@test:/usr/local# cd redis-4.0.2 root@test:/usr/local/redis-4.0.2# make
編譯成功的標志:
Hint: It's a good idea to run 'make test' ;)
3.安裝到指定目錄,如 /usr/local/redis
make PREFIX=/usr/local/redis install
進入安裝目錄查看文件:
root@test:/usr/local/redis-4.0.2# cd /usr/local/redis root@test:/usr/local/redis# ls bin root@test:/usr/local/redis# cd bin root@test:/usr/local/redis/bin# ls redis-benchmark redis-check-rdb redis-sentinel redis-check-aof redis-cli redis-server
4.進入源碼文件夾將配置文件拷貝到安裝目錄下
root@test:/usr/local# cd redis-4.0.2 root@test:/usr/local/redis-4.0.2# ls 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests BUGS deps MANIFESTO runtest sentinel.conf utils CONTRIBUTING INSTALL README.md runtest-cluster src root@test:/usr/local/redis-4.0.2# cp redis.conf /usr/local/redis root@test:/usr/local/redis-4.0.2# pwd /usr/local/redis-4.0.2 root@test:/usr/local/redis-4.0.2# cd ../redis root@test:/usr/local/redis# ls bin redis.conf
5.啟動redis服務:
root@test:/usr/local/redis# ./bin/redis-server redis.conf
出現以下信息證明啟動成功:
8325:C 04 Nov 03:37:27.757 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 8325:C 04 Nov 03:37:27.762 # Redis version=4.0.2, bits=32, commit=00000000, modified=0, pid=8325, just started 8325:C 04 Nov 03:37:27.763 # Configuration loaded 8325:M 04 Nov 03:37:27.766 * Increased maximum number of open files to 10032 (it was originally set to 1024). 8325:M 04 Nov 03:37:27.874 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now. _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 4.0.2 (00000000/0) 32 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 8325 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 8325:M 04 Nov 03:37:27.882 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 8325:M 04 Nov 03:37:27.882 # Server initialized 8325:M 04 Nov 03:37:27.883 # WARNING overcommit_memory is set 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. 8325:M 04 Nov 03:37:27.970 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 8325:M 04 Nov 03:37:27.971 * Ready to accept connections ^C8325:signal-handler (1509781062) Received SIGINT scheduling shutdown... 8325:M 04 Nov 03:37:42.403 # User requested shutdown... 8325:M 04 Nov 03:37:42.404 * Saving the final RDB snapshot before exiting. 8325:M 04 Nov 03:37:42.410 * DB saved on disk 8325:M 04 Nov 03:37:42.410 * Removing the pid file. 8325:M 04 Nov 03:37:42.410 # Redis is now ready to exit, bye bye...
注意:啟動成功之后新開一SSH連接窗口,上面的窗口不能動。
6.新開SSH連接窗口並測試:
查看進程證明啟動成功:
qiaozhi@test:~$ ps -ef | grep redis root 8505 4668 0 03:55 pts/0 00:00:01 ./bin/redis-server 127.0.0.1:6379 qiaozhi 8523 8397 0 04:13 pts/1 00:00:00 grep --color=auto redis
客戶端進行連接:
qiaozhi@test:~$ cd /usr/local/redis qiaozhi@test:/usr/local/redis$ ./bin/redis-cli 127.0.0.1:6379>
7.存儲數據進行測試:
鍵值對存儲數據:
127.0.0.1:6379> set a hello OK 127.0.0.1:6379> get a "hello"
注意:安裝成功之后需要開放6379端口便於在Java中操作:(遠程連接)
/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT /etc/rc.d/init.d/iptables save
如果上面第二個命令不是一個目錄或文件可以替換為:
iptables-save