1. 搭建Re
dis服务器
在主机 192.168.4.50 上安装并启用 re
dis 服务
设置变量test,值为123
查看变量test的值
1.1 搭建re
dis服务器
1.1.1 安装re
dis服务器
]# yum -y install gcc gcc-c++ make
]# tar -xvf re
dis-4.0.8.tar.gz
]# cd re
dis-4.0.8/
re
dis-4.0.8]# ls
00-RELEASENOTES
copYING Makefile re
dis.conf runtest-sentinel tests
BUGS deps MANIFESTO runtest sentinel.conf utils
CONTRIBUTING INSTALL README.md runtest-cluster src
re
dis-4.0.8]# make && make install
re
dis-4.0.8]# cd utils/
utils]# ./install_server.sh (一路回车)
查看状态
utils]# /etc/init.d/re
dis_6379 status
查看监听的端口
utils]# netstat -antupl |grep :6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 15203/re
dis-server
utils]# ps -C re
dis-server
PID TTY TIME CMD
15203 ? 00:00:00 re
dis-server
停止服务
utils]# /etc/init.d/re
dis_6379 stop
//再次查看,
显示 没有那个
文件或目录
utils]# /etc/init.d/re
dis_6379 status
cat: /var/run/re
dis_6379.pid: 没有那个
文件或目录
Re
dis is running ()
连接re
dis
utils]# /etc/init.d/re
dis_6379 start
Starting Re
dis server...
]# re
dis-cli
127.0.0.1:6379> ping
PONG //PONG说明服务正常
1.1.2 基本操作
设置变量test,值为123,查看变量test的值
常用指令操作:
set keyname
keyvalue 存储
get keyname
获取
127.0.0.1:6379> set test 123
OK
127.0.0.1:6379> get test
"123"
del keyname
删除变量
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> del k1
(integer) 1
keys * 打印所有变量
127.0.0.1:6379> keys *
1) "test"
EXISTS keyname 测试是否存在
127.0.0.1:6379> exists k1
(integer) 0
type keyname 查看类型
127.0.0.1:6379> set k2 v1
OK
127.0.0.1:6379> type k2
string
move keyname
dbname 移动变量
127.0.0.1:6379> move k2 1 //移动k2到1库
(integer) 1
select
数据库编号0-15 切换库
127.0.0.1:6379> select 1 //切换到1库
OK
127.0.0.1:6379[1]> keys * //查看有k2
1) "k2"
expire keyname 10 设置有效时间
127.0.0.1:6379[1]> EXPIRE k2 10
(integer) 1
ttl keyname 查看生存时间
127.0.0.1:6379[1]> ttl k2
flushall
删除所有变量
127.0.0.1:6379[1]> FLUSHALL
OK
save 保存所有变量
127.0.0.1:6379[1]> save
OK
shutdown
关闭re
dis服务
127.0.0.1:6379[1]> SHUTDOWN
2.
修改Re
dis服务运行参数
具体要求如下:
端口号 6350
IP地址 192.168.4.50
连接
密码 123456
客户端连接Re
dis服务
2.1
修改re
dis运行参数
//可以先备份一份,防止
修改错误没法还原
]# cp /etc/re
dis/6379.conf /root/6379.conf
]# /etc/init.d/re
dis_6379 stop
]# vim /etc/re
dis/6379.conf
...
bind 192.168.4.50 //设置服务使用的ip
port 6350 //更改端口号
requirepass 123456 //
设置密码
]# /etc/init.d/re
dis_6379 start
Starting Re
dis server...
]# ss -antul | grep 6350 //查看有端口6350
tcp LISTEN 0 128 192.168.4.50:6350 *:*
由于
修改了
配置文件所以在连接的时候需要
加上ip和端口
]# re
dis-cli -h 192.168.4.50 -p 6350
192.168.4.50:6350> ping
(error) NOAUTH Authentication
required.
192.168.4.50:6350> auth 123456 //输入
密码才能操作(因为之前设置过
密码)
OK
192.168.4.50:6350> ping
PONG
还可以直接在命令行输入
密码连接
]# re
dis-cli -h 192.168.4.50 -p 6350 -a 123456
192.168.4.50:6350> ping
PONG
停止服务
由于
修改Re
dis服务运行参数,所以在停止服务的时候也不能用
默认的
方法停止
]# /etc/init.d/re
dis_6379 stop //停止失败
]# re
dis-cli -h 192.168.4.50 -p 6350 -a 123456 shutdown
]# ss -antul | grep 6350 //查看没有端口
3.部署LNMP+Re
dis
3.1 部署
Nginx
]# sy
stemctl stop httpd
]# cd
Nginx-1.12.2/
]# yum -y install gcc pcre-devel openssl-devel zlib-devel
]# useradd
Nginx
]# ./con
figure --prefix=/usr/local/
Nginx
]# make && make install
]# ln -s /usr/local/
Nginx/sbin/
Nginx /sbin/
]# ls /usr/local/
Nginx/
conf html logs sbin
修改配置文件并启动服务
]# vim /usr/local/
Nginx/conf/
Nginx.conf
65 location ~ \.
PHP$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.
PHP;
69 #fastcgi_p
aram SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi.conf;
]#
Nginx
]#
Nginx -t
Nginx: the con
figuration file /usr/local/
Nginx/conf/
Nginx.conf
Syntax is ok
Nginx: con
figuration file /usr/local/
Nginx/conf/
Nginx.conf test is successful
]# netstat -utnlp | grep :80 查看端口
3.2 部署
PHP
编写
PHP文件
]#vim /usr/local/
Nginx/html/test.
PHP
<?
PHP
PHPinfo();
?>
安装re
dis服务软件包并运行服务
]# /etc/init.d/re
dis_6379 start
]# netstat -utnlp | grep :6350
配置
PHP支持Re
dis 服务
安装连接re
dis服务 模块软件包
]# yum -y install
PHP
]# yum -y install autoconf aut
omake
]# rpm -ivh
PHP-devel-5.4.16-42.el7.x86_64.rpm
]# rpm -ivh
PHP-fpm-5.4.16-42.el7.x86_64.rpm
]# tar -zxvf
PHP-re
dis-2.2.4.tar.gz
]# cd
PHPre
dis-2.2.4/
]#
PHPize 检测
PHP环境
]# ./con
figure --with-
PHP-con
fig=/usr/bin/
PHP-con
fig
]# make
]# make install
Installing shared extensions: /usr/lib64/
PHP/modules/
提示模块安装目录
]# ls /usr/lib64/
PHP/modules/re
dis.so 查看模块
文件
配置
PHP加载模块
]# vim /etc/
PHP.ini
728 extension_dir = "/usr/lib64/
PHP/modules/"
730 extension = "re
dis.so"
:wq
]# sy
stemctl restart
PHP-fpm
]#
PHP -m | grep -i re
dis 验证模块是否加载成功
re
dis
验证配置
]# cd no
sql(自己打的包)
]# cp linkre
dis.
PHP /usr/local/
Nginx/html/
]# vim /usr/local/
Nginx/html/linkre
dis.
PHP
<?
PHP
$re
dis = new re
dis();
$re
dis->connect('192.168.4.50',6350);
$re
dis->auth("123456");
$re
dis->set('tel,'13152098678);
echo $re
dis->get('school');
?>
:wq
真机检测:
] firefox
http://192.168.4.50/test.php
] firefox
http://192.168.4.50/linkredis.php
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。