ql-day11     数据库服务软件类型和配置redis  

l 数据库服务软件类型

² RDBMS

• 关系数据库管理系统

– Relational Database Management System

– 数据按照预先设置的组织结构,存储在物理存储介质上。

– 数据之间可以做关联操作

² RDBMS 服务软件

• 主流的 RDBMS 软件

– Oracle

– DB2

– WS-sqlserver

– MySQL

² NoSQL

• NoSQL(NoSQL = Not Only SQL )

– 意思是 " 不仅仅是 SQL“

– 泛指非关系型数据库

– 不需要预先定义数据存储结构

– 表的每条记录都可以有不同的类型和结构

² NoSQL 服务软件

• 主流软件

– Redis

– MongoDB

– Memcached

– CouchDB

– Neo4j

– FlockDB

² Redis 介绍

• Redis

– Remode DIctionary Server( 远程字典服务器 )

– 使用 C 语言编写的,遵守 BSD 的开源软件

– 是一款高性能的 (Key/Values) 分布式内存数据库

– 并支持数据持久化的 NoSQL 数据库服务软件

– 中文网站 www.redis.cn

Redis 介绍(续 1 )

² Redis 特点:

– 支持数据持久化,可以把内存里数据保存到硬盘中

– 不仅仅支持 key/values 类型的数据,同时还支持 list

hash set zset 类型

– 支持 master-salve 模式数据备份

1)装包

# cd soft/redis

# tar -xzf redis-4.0.8.tar.gz

# yum -y install gcc-c++ gcc

# cd redis-4.0.8

# make         或      // make && make install

# make install

2)初始化

# ./utils/install_server.sh

3)启动redis服务(软件安装完成后服务自动运行)启动服务

• 启动服务

# /etc/init.d/redis_<portnumber> start

• 停止服务

# /etc/init.d/redis_<portnumber> stop

[root@localhost redis-4.0.8]# /etc/init.d/redis_6379 status

[root@localhost redis-4.0.8]# netstat -utnlp  | grep :6379  //redis

[root@localhost redis-4.0.8]# ps -C  redis-server

4)运行

[root@host51 redis-4.0.8]# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

u 连接本机redis服务

[root@localhost redis-4.0.8]# redis-cli

127.0.0.1:6379> ping

PONG

127.0.0.1:6379> set k1 v1    //再次附值,覆盖之前的值

OK

127.0.0.1:6379> get k1

"v1"

127.0.0.1:6379> SHUTDOWN

not connected> exit

u 常用操作指令

– Set keyname keyvalue          // 存储

– get keyname                       // 获取

– Select 数据库编号 0-15      // 切换库

– Keys *                                 // 打印所以变量

– Keys a?                               // 打印指定变量

– Exits keyname                     // 测试是否存在

– ttl keyname                         // 查看生存时间

– type keyname                      // 查看类型

u 连接本机redis服务

[root@localhost redis-4.0.8]# redis-cli

127.0.0.1:6379> ping

PONG

127.0.0.1:6379> set k1 v1     //给k1附值v1

OK

127.0.0.1:6379> get k1          //查看值

"v1"

127.0.0.1:6379> keys *

1) "k1"

127.0.0.1:6379> SHUTDOWN

not connected> exit

u 常用操作指令 ( 续 1)

– move keyname dbname    // 移动变量

– expire keyname 10            // 设置有效时间

– del keyname                     // 删除变量

– flushall                             // 删除所有变量

– save                                 // 保存变量

– shutdown                         // 关闭服务

  

配置文件解析

  • 数据单位

• 数据单位

  • 常用配置选项    vim  /etc/redis/6379.conf

*模板*                                           *修改*

– port 6379 // 端口                        // 93 port 6351

– bind 127.0.0.1 //IP 地址              // 70 bind 127.0.0.1 192.168.4.51

– tcp-backlog 511 //tcp 连接总数

– timeout 0 // 连接超时时间

– tcp-keepalive 300 // 长连接时间

– daemonize yes // 守护进程方式运行

– databases 16 // 数据库个数

– logfile /var/log/redis_6379.log //pid 文件

– maxclients 10000 // 并发连接数量

– dir /var/lib/redis/6379 // 数据库目录

1) 51主机更改配置文件

[root@host52 redis-4.0.8]# vim  /etc/redis/6379.conf

:set nu

70 bind 127.0.0.1 192.168.4.51

93 port 6351

815 cluster-enabled yes                            //去掉注释

823 cluster-config-file nodes-6357.conf    //去掉注释。修改

829 cluster-node-timeout 5000                 //去掉注释。修改

2) 52 主机上连接51

[root@host52 redis-4.0.8]# redis-cli -h 192.168.4.51 -p 6351

  • 内存管理

• 内存清除策略

– volatile-lru 最近最少使用 (针对设置了过期时间的 key )

– keys-lru 删除最少使用的 key

– volatile-random 在设置了过期的 key 里随机移除

– allkeys-random 随机移除 key

– volatile-ttl (minor TTL) 移除最近过期的 key

– noeviction不删除 写满时报错

  • 内存管理 (续 1 )

• 选项默认设置

– maxmemory <bytes> // 最大内存

– maxmemory-policy noeviction // 定义使用的策略

– maxmemory-samples 5 // 选取模板数据的个数

(针对 lru 和 ttl 策略)

  • 设置连接密码

• 设置密码    配置文件:   vim  /etc/redis/6379.conf

– grep -n requirepass /etc/redis/6379.conf

501:requirepass 123456

1)重起服务 (命令停止服务)   //刚开始要down( redis-cli -p 6379 shutdown)

2)[root@host51 redis-4.0.8]# redis-cli -p 6351 shutdown

或 ]# redis-cli -p 6351 -a 123456 shutdown

[root@host51 redis-4.0.8]# /etc/init.d/redis_6379 start

– [root@localhost redis-4.0.8]# redis-cli  -h192.168.4.51  -p 6351 -a 123456

– 127.0.0.1:6379> ping

– (error) NOAUTH Authentication required.

– 127.0.0.1:6379> auth 123456 // 输入密码

– OK

– 127.0.0.1:6379> ping

– PONG

– 127.0.0.1:6379>

3)修改配置文件  (脚本停止服务配置)

[root@host51 redis-4.0.8]# vim  /etc/init.d/redis_6379

43     $CLIEXEC -h 192.168.4.51 -p 6351 -a 123456 shutdown

[root@host51 redis-4.0.8]# /etc/init.d/redis_6379  stop

[root@host51 redis-4.0.8]# /etc/init.d/redis_6379  start

[root@host51 redis-4.0.8]# /etc/init.d/redis_6379  status


部署 LNMP

1)安装软件包

• 安装源码 nginx 和 PHP

[root@host53 ~]# tar -xf lnmp_soft.tar.gz

]# yum -y install gcc gcc-c++ pcre-devel zlib-devel

]# tar -zxf nginx-1.12.2.tar.gz

]# cd nginx-1.12.2

]# ./configure --prefix=/usr/local/nginx

]# make

]# make install

[root@host53 lnmp_soft]# yum -y install php-common

[root@]host53 lnmp_soft# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm

[root@host53 lnmp_soft]# systemctl start php-fpm

[root@host53 lnmp_soft]# netstat -anput | grep :9000

[root@host53 nginx-1.12.2]# /usr/local/nginx/sbin/nginx

[root@host53 nginx-1.12.2]# netstat -anput | grep :80

[root@host53 nginx-1.12.2]# echo "123"  > /usr/local/nginx/html/index.html

[root@host53 nginx-1.12.2]# firefox 192.168.4.53/test.html

2)修改配置文件

• 修改 nginx 服务主配置文件

[root@bogon ~]# vim /usr/local/nginx/conf/nginx.conf

location ~ \.php$ {

root

html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

include

fastcgi_params;

}

:wq

3)测试配置

• 测试文件

[root@bogon lnmp]# vim /usr/local/nginx/html/test.php

<?php

echo "hello world!!!";

?>

:wq

[root@bogon lnmp]#

• 访问 nginx 服务

[root@bogon lnmp]# elinks --dump http://localhost/test.php

hello world!!! 


运行 Redis 服务

• 装包并启动服务

[root@host53 ~]# cd soft/redis

# tar -xzf redis-4.0.8.tar.gz

# cd redis-4.0.8

#make

#make install

#./utils/install_server.sh // 初始化.全部回车

# /etc/init.d/redis_6379 start

u 配置 php 支持 Redis

• 安装 php 扩展

[root@host53 ~]# cd soft/redis

#yum -y install autoconf

#yum -y install automake

#rpm -ivh php-devel-5.4.16-42.el7.x86_64.rpm

# tar -zxf php-redis-2.2.4.tar.gz

# cd phpredis-2.2.4/

[root@bogon phpredis-2.2.4]# /usr/bin/phpize

# ./configure --with-php-config=/usr/bin/php-config

[root@bogon phpredis-2.2.4]# make

[root@bogon phpredis-2.2.4]# make install

[root@bogon ~]# vim /etc/php.ini

728    extension_dir = "/usr/lib64/php/modules/”

730    extension = "redis.so"测试配置

u 测试配置

[root@host53 ~]# firefox 192.168.4.53/test.php

[root@host53 ~]# systemctl start php-fpm.service

• 查看是否支持模块

[root@bogon ~]# php -m | grep -i redis

redis

• 编写测试文件

[root@bogon bin]# cat /usr/local/nginx/html/redis.php

<?php

$redis = new redis();

$redis->connect('127.0.0.1',6379);

$redis->set('redistest','666666');

echo $redis->get('redistest');

?>

• 访问 nginx 服务

[root@bogon bin]# elinks --dump http://localhost/redis.php

666666

u 访问和测试

[root@db54 redis-4.0.8]# redis-cli

127.0.0.1:6379> keys *

1) "redistest"

127.0.0.1:6379> get redistest

"666666"

127.0.0.1:6379>

u 配置页面

[root@db54 lnmp]# vim  /usr/local/nginx/html/test.php

<?php

phpinfo();

?>


快速配置redis服务

u 装包并启动服务

[root@host53 ~]# cd soft/redis

# tar -xzf redis-4.0.8.tar.gz

# cd redis-4.0.8

#make

#make install

#./utils/install_server.sh // 初始化

# /etc/init.d/redis_6379 start

u 修改配置    /etc/redis/6379.conf

[root@host52 redis-4.0.8]# vim  /etc/redis/6379.conf

:set nu

70 bind 127.0.0.1 192.168.4.51

93 port 6351

815 cluster-enabled yes                            //去掉注释

823 cluster-config-file nodes-6357.conf    //去掉注释。修改

829 cluster-node-timeout 5000                 //去掉注释。修改

u 修改配置(2) /etc/init.d/redis_6379

[root@host51 redis-4.0.8]# vim  /etc/init.d/redis_6379

43     $CLIEXEC -h 192.168.4.51 -p 6351 -a 123456 shutdown

u 停止服务

[root@host51 redis-4.0.8]#redis-cli -p 6379 shutdown

u 起服务

[root@host51 redis-4.0.8]# /etc/init.d/redis_6379  stop

[root@host51 redis-4.0.8]# /etc/init.d/redis_6379  start

[root@host51 redis-4.0.8]# /etc/init.d/redis_6379  status

u 查看端口

netstat -anput | grep redis

数据库服务软件类型和配置redis的更多相关文章

  1. 在windows下面配置redis集群遇到的一些坑

    最近工作不忙,就决定学习一下redis.因为一直在windows下工作,不会linux,没办法就选择在windows下配置redis. windows下配置redis集群的文章有很多,比如:http: ...

  2. [Redis]通过代码配置Redis

    查看了文档https://azure.microsoft.com/en-us/documentation/articles/cache-how-to-scale/,发现可以使用代码来配置Redis,所 ...

  3. Ubuntu 安装和配置redis数据库

    Ubuntu 14.04下安装和配置redis数据库 小编现在在写一个分布式爬虫,要用到这个数据库,所以分享一下小编是如何安装和配置的,希望对大家有帮助. 工具/原料   Ubuntu 系统电脑一台 ...

  4. 【Redis】配置redis主从复制

    阅读目录 redis-3.2.1.master tar zxvf redis-3.2.1.tar.gz mv redis-3.2.1 redis-3.2.1.slave-1 tar zxvf redi ...

  5. sqlserver2005重新安装(安装汇编错误,安装程序无法连接到数据库服务进行服务配置)

    2014-01-09 16:41 1687人阅读 评论(1) 收藏 举报 分类: 数据库(1) 版权声明:本文为博主原创文章,未经博主允许不得转载. sqlserver2005重新安装(安装汇编错误, ...

  6. SpringMVC+Mybatis+MySQL配置Redis缓存

    SpringMVC+Mybatis+MySQL配置Redis缓存 1.准备环境: SpringMVC:spring-framework-4.3.5.RELEASE-dist Mybatis:3.4.2 ...

  7. Redis学习笔记之一 : 配置redis

    Redis 简介 Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库. Redis 与其他 key - value 缓存产品有以下三个特点: Redis支持数据的持久 ...

  8. 在服务器上,配置redis可以外网访问

    首先linux开放默认端口6379打开redis配置文件redis-conf注释掉 bind 127.0.0.1(默认只有本地主要才能访问)这个注释掉现在处于受保护的状态,外网连不上,因为没有密码 在 ...

  9. linux下安装与配置Redis

    1.安装 (1)获取源代码 wget http://download.redis.io/releases/redis-4.0.8.tar.gz (2)解压 tar xzvf redis-4.0.8.t ...

随机推荐

  1. Redis篇之操作、lettuce客户端、Spring集成以及Spring Boot配置

    Redis篇之操作.lettuce客户端.Spring集成以及Spring Boot配置 目录 一.Redis简介 1.1 数据结构的操作 1.2 重要概念分析 二.Redis客户端 2.1 简介 2 ...

  2. 19.10.11学习日记随笔 mysql事务隔离性

    一天的感悟 学习事务的处理方式,其中反想自己学过的flask 默认是开启事务的,flask_sqlalchemy每次在提交时都是需要commit,或者失败是需要rollback回滚操作的,其实pyth ...

  3. C#如何实现大小写转换

    2020-03-16  每日一例第8天 1.新建窗体应用程序,拖入label/textbox/radiobutton控件,并改text值:  2.button控件输入代码: if (radioButt ...

  4. 13.浏览器屏幕缩放bug修复

    目录 问题:浏览器缩放时,轮播图显示不全,滚动水平滚动条,发现图片缺失 解决:隐藏水平滚动条,页面都只提供垂直滚动条的需求 问题:浏览器缩放时,轮播图显示不全,滚动水平滚动条,发现图片缺失 解决:隐藏 ...

  5. JDK中线程池参详细解析

    在jdk中为我们提供了三种创建线程池的方式,但是在阿里的编码规范里面都是明确禁止使用这三种api去创建线程池,推荐我们去自定义线程池.为什么? 要回答为什么,我们需要明白创建线程池时,各参数的作用: ...

  6. A Systems-Level Characterization of the Differentiation of Human Embryonic Stem Cells into Mesenchymal Stem Cells (解读人:王欣然)

    文献名:A Systems-Level Characterization of the Differentiation of Human Embryonic Stem Cells into Mesen ...

  7. shiro拦截所有报 Uncaught SyntaxError: Unexpected token '<' 解决方法

    改成 -> filterChainDefinitionMap.put("/css/**", "anon");filterChainDefinitionMa ...

  8. DL 调参经验

    2019-10-20 11:45:54 数据侧 1.在数据集很大的情况下,不要立马跑全量数据.可以现在小数据集上进行测试,估算一下运行时间. 2.数据shuffle和augmentation,训练之前 ...

  9. [模板] LCA-最近公共祖先-倍增法

    2019-11-07 09:25:45 C.树之呼吸-叁之型-树上两点路径长度 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 7 (4 ...

  10. Mysql常用sql语句(二)- 操作数据表

    21篇测试必备的Mysql常用sql语句,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1683347.html ...