redis介紹不再累贅
1、安裝gcc,因為Redis是用C語言寫的,所以需要gcc進(jìn)行編譯
yum install gcc -y
2、下載redis-2.8.9.tar.gz
http://download.redis.io/releases/redis-2.8.9.tar.gz
3、安裝Redis
tar xf redis-2.8.9.tar.gz
cd redis-2.8.9
make MALLOC=libc
make PREFIX=/usr/local/redis install
4、安裝完成以后查看目錄以及文件
[root@salt-server bin]# pwd
/usr/local/redis/bin
[root@salt-server bin]# ls
redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
5、命令解釋
redis-server:redis服務(wù)器的daemon啟動程序
redis-cli:redis命令行操作工具
redis-benchmark:redis性能測試工具
redis-check-aof:對更新日志appendonly.aof檢查
redis-check-dump:用于本地數(shù)據(jù)庫rdb文件的檢查
6、配置啟動服務(wù)
設(shè)置環(huán)境變量:
vim /etc/profile
PATH=$PATH:/usr/local/redis/bin
source /etc/profile
拷貝配置文件:
mkdir /usr/local/redis/conf
cp redis-2.8.9/redis.conf /usr/local/redis/conf
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf && sysctl -p
啟動服務(wù):redis-server /usr/local/redis/conf/redis.conf &
7、啟動成功正常反饋如下
[root@salt-server ~]# redis-server /usr/local/redis/conf/redis.conf &
[1] 11736
[root@salt-server ~]# [11736] 27 Jan 09:16:07.772 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 11736
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[11736] 27 Jan 09:16:07.773 # Server started, Redis version 2.8.9
[11736] 27 Jan 09:16:07.773 * The server is now ready to accept connections on port 6379
8、基本操作
關(guān)閉redis:redis-cli shutdown
可直接輸入redis-cli進(jìn)去交互式
[root@salt-client1 ~]# redis-cli
127.0.0.1:6379>
輸入值并取值測試
[root@salt-client1 ~]# redis-cli
127.0.0.1:6379> set Test 001 //設(shè)置一個Test值為001
OK
127.0.0.1:6379> get Test //獲取Test的值
"001"
127.0.0.1:6379> del Test //刪除一個值
(integer) 1
127.0.0.1:6379>keys * //取所有值
9、客戶端連接使用
[root@salt-client1 ~]# redis-cli -h 172.16.10.133 -p 6379
172.16.10.133:6379>
也可以不登錄直接賦值
[root@salt-client1 ~]# redis-cli -h 172.16.10.133 -p 6379 set Test 789
OK
[root@salt-client1 ~]# redis-cli -h 172.16.10.133 -p 6379 get Test
"789"
10、redis安全
為redis客戶端設(shè)置外部連接密碼
vim /usr/local/redis/conf/redis.conf
修改requirepass如下:
requirepass a)s$M7F57TN58$8
重啟redis
redis-cli shutdown
redis-server /usr/local/redis/conf/redis.conf &
直接登錄測試會提示認(rèn)證失敗需要指定密碼
[root@salt-server ~]# redis-cli
127.0.0.1:6379> set d 1
(error) NOAUTH Authentication required.
127.0.0.1:6379>
指定密碼登錄
[root@salt-server ~]# redis-cli
127.0.0.1:6379> auth a)s$M7F57TN58$8
OK
Over
網(wǎng)站題目:Redis(一) CentOS十分鐘搭建Redis2.8.9
網(wǎng)頁鏈接:
http://weahome.cn/article/gpssde.html