RDBMS(关系型)服务软件:
主流的软件: Oracle DB2 (MS SQL Server) Mysql MariaDB
nosql (非关系型)服务软件:
主流软件:redis, MongoDB,Memcached CouchDB Neo4j ,FlockDB
Redis 介绍
1.1 装包
]# yum -y install gcc
]# tar -zxvf redis-4.0.8.tar.gz
]# cd redis-4.0.8
]# make
]# make install
1.2 初始化配置
]# cd utils/
]# ./install_server.sh
[root@host50 redis-4.0.8]# ./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!
1.3 查看服务状态
[root@host50 utils]# netstat -utnlp | grep :6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 8408/redis-server 1
1.4 连接服务
[root@host50 utils]# redis-cli
127.0.0.1:6379> exit
1.5 服务管理
停止服务 ]# /etc/init.d/redis_6379 stop
启动服务 ]# /etc/init.d/redis_6379 start
1.6 存/取数据
]# redis-cli
127.0.0.1:6379> set school tarena
127.0.0.1:6379> keys *
127.0.0.1:6379> get school
1.7 管理数据的基本命令
set get del move ttl exprie type
keys *
keys ??
exists select
flushdb flushall save shutdown
2配置文件解析
[root@host51 ~]# /etc/init.d/redis_6379 stop 停止服务
]# vim /etc/redis/6379.conf # 修改配置文件
port 6350 端口号
bind 192.168.4.50 服务对应的ip
requirepass 123456 修改密码
:wq
[root@host51 ~]# /etc/init.d/redis_6379 start
启动服务
]#netstat -utnlp | grep :6350
[root@host51 ~]# redis-cli -h 192.168.4.51 -p 6351
192.168.4.51:6351> ping
PONG # 说明状态正常
192.168.4.51:6351>
停止服务
]# redis-cli -h 192.168.4.50 -p 6350 -a 123456 shutdown
修改脚本代码 可以使用脚本停止服务
]# vim +43 /etc/init.d/redis_6379
$CLIEXEC -h 192.168.4.50 -p 6350 -a 123456 shutdown
:wq
]# /etc/init.d/redis_6379 start
]# netstat -utnlp | grep :6350
]#/etc/init.d/redis_6379 stop
]# netstat -utnlp | grep :6350
]# netstat -utnlp | grep redis-server
2.1 部署 LNMP 环境 (网站运行平台)
[root@host56 lnmp]# yum -y install pcre-devel zlib-devel gcc # 安装依赖包
[root@host56]cd nginx-1.12.2/
[root@host56] ./configure
[root@host56] make # 编译
[root@host56] make install #安装
[root@host56]ls
[root@host56] cd ..
[root@host56] ls
[root@host56] yum -y install php-fpm-5.4.16-42.el7.x86_64.rpm
[root@host56] systemctl start php-fpm
[root@host56] netstat -anptul | grep :9000
[root@host56 lnmp]# vim +65 /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 /scripts$fastcgi_script_name;
include fastcgi.conf;
}
[root@host56 lnmp]# /usr/local/nginx/sbin/nginx -t 检查配置文件 是否正确
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@host56 lnmp]#
[root@host56 lnmp]# vim /usr/local/nginx/html/test.php #编写php 的测试脚本
echo "hello world!!!";
?>
[root@host56 lnmp]curl http://localhost/test.php # 测试脚本
hello world!!! # 显示hello world!!!
2.2 配置php 支持 Redis
[root@host56 ~]# which php
/usr/bin/which: no php in (/root/perl5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
]# yum -y install php
]# cd lnmp
[root@nginx utils]# php -m | grep -i redis //没有redis模块
]# yum -y install php-devel-5.4.16-42.el7.x86_64.rpm
]# tar -zxvf php-redis-2.2.4.tar.gz
]# cd phpredis-2.2.4/
]# phpize //生成一个php的文件
]# ./configure --with-php-config=/usr/bin/php-config
]# make && make install
]# ls /usr/lib64/php/modules/
]#vim /etc/php.ini
728 extension_dir = "/usr/lib64/php/modules/"
730 extension = "redis.so"
:wq
]# systemctl restart php-fpm
]# php -m | grep -i redis
2.3 测试配置
2.3.1 存储数据php脚本
]# cd lnmp
]# cp linkredis.php /usr/local/nginx/html/set.php
]# vim /usr/local/nginx/html/set.php
$redis = new redis();
$redis->connect("127.0.0.1",6379);
$redis->set("lover","bufulgirl");
echo "ok";
?>
:wq
2.3.2 获取数据php脚本
]#cd lnmp
]# cp linkredis.php /usr/local/nginx/html/get.php
]# vim /usr/local/nginx/html/get.php
$redis = new redis();
$redis->connect("127.0.0.1",6379);
echo $redis->get("lover");
echo "yes";
?>
:wq
访问php脚本存取数据
]# curl http://localhost/set.php //存数据
]# curl http://localhost/get.php //取数据