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
二 部署 lnmp + redis
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 的測試腳本
<?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
<?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
<?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 //取數據