OpenResty Redis 安装部署测试SET GET功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenResty Redis 安装部署测试SET GET功能相关的知识,希望对你有一定的参考价值。

OpenResty Redis 安装部署测试SET GET功能


参考文档

http://www.redis.cn/download.html

https://openresty.org/cn/installation.html

https://github.com/openresty/redis2-nginx-module


一,安装OpenResty

1,安装最新稳定版本的OpenResty-1.11.2.5

[[email protected] ~]# yum -y install tclyum -y install perl-devel gcc gmake

[[email protected] ~]# yum -y install tclwget https://openresty.org/download/openresty-1.11.2.5.tar.gz

[[email protected] ~]# yum -y install tcltar zxvf openresty-1.11.2.5.tar.gz 

[[email protected] ~]# yum -y install tclcd openresty-1.11.2.5

[[email protected] ~]# yum -y install tcl./configure

[[email protected] ~]# yum -y install tclgmake

[[email protected] ~]# yum -y install tclgmake install


2,查看Nginx版本

[[email protected] ~]# yum -y install tclnginx -V

nginx version: openresty/1.11.2.5

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 

built with OpenSSL 1.0.1e-fips 11 Feb 2013

TLS SNI support enabled

configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.10 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.18 --add-module=../redis2-nginx-module-0.14 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-http_ssl_module



二,安装Redis

1,安装最新稳定版本的Redis-4.0.1

[[email protected] ~]# yum -y install tcl

[[email protected] ~]# wget http://download.redis.io/releases/redis-4.0.1.tar.gz

[[email protected] ~]# tar zxvf redis-4.0.1.tar.gz 

[[email protected] ~]# cd redis-4.0.1

[[email protected] ~]# make

[[email protected] ~]# make test

[[email protected] ~]# make install

[[email protected] ~]# sh utils/install_server.sh 

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


2,启动

[[email protected] ~]# /etc/init.d/redis_6379 start



三,配置redis_pass

1,主配置文件

[[email protected] ~]# cat /usr/local/openresty/nginx/conf/nginx.conf |grep -Ev "^#|^$"

user  www www;

worker_processes  auto;

worker_cpu_affinity auto;

error_log  logs/error.log  error;

pid        logs/nginx.pid;

worker_rlimit_nofile 409600;

events

{

  use epoll;

  worker_connections 409600;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

                      ‘$status $body_bytes_sent "$http_referer" ‘

                      ‘"$http_user_agent" "$http_x_forwarded_for"‘;

    access_log  logs/access.log  main;

    sendfile        on;

    tcp_nopush     on;

    keepalive_timeout  65;

    upstream redis{

        server 127.0.0.1:6379;

        keepalive 10;

    }

    server {

        listen       80;

        server_name  localhost;

        location / {

            root   html;

            index  index.html index.htm;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        } 

        # GET /get?key=some_key

        location = /get {

            set_unescape_uri $key $arg_key;  # this requires ngx_set_misc

            redis2_query get $key;

            redis2_pass 127.0.0.1:6380;

         }

        # GET /set?key=one&val=first%20value

        location = /set {

            set_unescape_uri $key $arg_key;  # this requires ngx_set_misc

            set_unescape_uri $val $arg_val;  # this requires ngx_set_misc

            redis2_query set $key $val;

            redis2_pass 127.0.0.1:6380;

        }

    }

}


2,检测语法

[[email protected] ~]# /usr/local/openresty/nginx/sbin/nginx -t


3,启动

[[email protected] ~]# /usr/local/openresty/nginx/sbin/nginx



四,测试功能

1,SET Key

[[email protected] ~]# curl "http://172.17.6.60/set?key=name&val=minyt"

+OK


2,GET Key

[[email protected] ~]#  curl http://172.17.6.60/get?key=name

$5

minyt



五,备注

经了解,目前OpenResty第三方Redis模块都不支持集群协议

[[email protected] ~]# ./configure --help|grep redis

  --without-http_redis2_module       disable ngx_http_redis2_module

  --without-http_redis_module        disable ngx_http_redis_module

  --without-lua_redis_parser         disable the lua-redis-parser library

  --without-lua_resty_redis          disable the lua-resty-redis library



以上是关于OpenResty Redis 安装部署测试SET GET功能的主要内容,如果未能解决你的问题,请参考以下文章

Nginx-OpenResty安装配置

Redis数据库安装部署及基本操作!

Redis数据库安装部署及基本操作!

openresty 安装部署脚本

非openresty方式安装Nginx + Lua + Redis 环境

使用Lua+Redis+OpenResty实现电商首页并发优化