Redis服务-linux下的配置

关系数据库管理系统
-RDMS
-数据按照预先设置的组织结构,存储在


NoSQL(NoSQL=Not Only SQL)
-非关系型数据库
-不需要预先定义数据存储结构
-表的每条记录都可以有不同的类型和结构


主流软件
-Redis
-MongoDB
-Memcached
-CouchDB
-Neo4j
-FlockDB


部署Redis服务
--Remote Dictionary Server(远程字典服务器)
--是一款高性能的(Key/Values)分布式内存数据库
--支持数据持久化,可以把内存数据保存到硬盘中
也支持list、hash、set、zset数据类型
-支持master-salve模式数据备份
-中文网站www.redis.cn
--支持主从模式,实现数据的自动备份






装包
初始化配置
启动服务
查看服务运行信息
连接服务存储数据
[root@51 ~]# tar -xzf redis-4.0.8.tar.gz 


[root@51 ~]# cd redis-4.0.8/
[root@51 redis-4.0.8]# 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@51 ~]# rpm -q gcc gcc-c++
gcc-4.8.5-16.el7.x86_64
gcc-c++-4.8.5-16.el7.x86_64


[root@51 redis-4.0.8]# make
[root@51 redis-4.0.8]# make install
[root@51 redis-4.0.8]# cd utils/
[root@51 utils]# ls
build-static-symbols.tcl  hashtable          redis_init_script.tpl
cluster_fail_time.tcl     hyperloglog        redis-sha1.rb
corrupt_rdb.c             install_server.sh  releasetools
create-cluster            lru                speed-regression.tcl
generate-command-help.rb  redis-copy.rb      whatisdoing.sh
graphs                    redis_init_script
[root@51 utils]# vim install_server.sh 
[root@51 utils]# ./install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server


Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] 
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@51 utils]# netstat -utnlp | grep :6379
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      5118/redis-server 1 
[root@51 utils]# /etc/init.d/redis_6379 status
Redis is running (5118)
[root@51 utils]# /etc/init.d/redis_6379 stop
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
[root@51 utils]# /etc/init.d/redis_6379 status
cat: /var/run/redis_6379.pid: 没有那个文件或目录
Redis is running ()
[root@51 utils]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@51 utils]# /etc/init.d/redis_6379 status
Red is running (5151)
[root@51 utils]# ps -C redis-server
  PID TTY          TIME CMD
 5151 ?        00:00:00 redis-server
is is running (5151)


4.访问数据行命令格式


[root@51 utils]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> quit
[root@51 utils]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name bob
OK
127.0.0.1:6379> get name
"bob"
127.0.0.1:6379> quit
[root@51 utils]# ls /var/lib/redis/6379/
dump.rdb










[root@51 ~]# /etc/init.d/redis_6379  start
Starting Redis server...
[root@51 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> cd
    -> ^DBye


[root@51 ~]# redis-cli
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> select 16
(error) ERR DB index is out of range
127.0.0.1:6379> select 2
OK
127.0.0.1:6379[2]> select 0
OK
127.0.0.1:6379> 
127.0.0.1:6379> Keys *
1) "name"
127.0.0.1:6379> get  name
"bob"
127.0.0.1:6379> set name lucy
OK
127.0.0.1:6379> get name
"lucy"
127.0.0.1:6379> set aa 1
OK
127.0.0.1:6379> set aaa 21
OK
127.0.0.1:6379> Keys *
1) "aaa"
2) "name"
3) "aa"
127.0.0.1:6379> del aa
(integer) 1
127.0.0.1:6379> Keys *
1) "aaa"
2) "name"
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> Keys *
(empty list or set)
127.0.0.1:6379> save
OK
127.0.0.1:6379> shutdown
not connected> ping
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
[root@51 ~]# netstat -utnlp | grep 6379






[root@51 ~]# redis-cli
127.0.0.1:6379> Exits age
(error) ERR unknown command 'Exits'
127.0.0.1:6379> Exsits age
\(error) ERR unknown command 'Exsits'
127.0.0.1:6379> EXISTS age
(integer) 0
127.0.0.1:6379> set age
(error) ERR wrong number of arguments for 'set' command
127.0.0.1:6379> set age 12
OK
127.0.0.1:6379> EXISTS age
(integer) 1
127.0.0.1:6379> type age
string
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> key *
(error) ERR unknown command 'key'
127.0.0.1:6379[1]> keys *
(empty list or set)
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> move age 1
(integer) 1
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> Keys *
1) "age"
127.0.0.1:6379[1]> select 0
OK
127.0.0.1:6379> Keys *
(empty list or set)
127.0.0.1:6379> 
















更改IP和端口号
[root@51 ~]# vim /etc/redis/6379.conf


  70 bind 192.168.4.52
  93 port 6379
[root@51 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@51 ~]# /etc/init.d/redis_6379 status




让其手动关闭变成自动关闭


[root@51 ~]# vim /etc/init.d/redis_6379 
 8 REDISPORT="6350"
 43  $CLIEXEC  -h 192.168.4.50 -p $REDISPORT shutdown -a 123456


[root@51 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@51 ~]# /etc/init.d/redis_6379 status


设置密码
[root@51 ~]# vim /etc/init.d/redis_6379 
501 requirepass 123456


[root@51 ~]# redis-cli -h 192.168.4.51 -p6350 -a 123456


[root@51 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@51 ~]# /etc/init.d/redis_6379 status




默认存储数据的文件
[root@51 ~]# ls /var/lib/redis/6379/
dump.rdb














搭建Redis服务器
服务的常用配置 IP地址 端口 数据库位置 数据库个数 内存清除 设置连接密码


管理数据的常用命令:set get del move flusha;; type ttl select


网站网络的环境 LNMP+Redis






访问热度高的在redis上,因为redis数据存储在内存中















































你可能感兴趣的:(Redis服务-linux下的配置)