安装openresty和模块,安装openresty模块


感谢大神的帮助。
一、安装依赖的软件包yum install readline-devel pcre-devel openssl-devel gcc
二、安装openresty
1、$ wget https://openresty.org/download/openresty-1.9.7.4.tar.gz如果出现无法下载的情况,可手动下载包,然后上传到服务器
2. 解压tar包$ tar xzvf openresty-1.9.7.4.tar.gz3. 进入到解压的目录里,配置编译选项,可以根据你的实际情况增加、减少相应的模块$ ./configure --prefix=/opt/openresty --with-luajit --without-http_redis2_module --with-http_iconv_module其中/opt/openresty这个目录是配置后的目录4. 编译并安装$ make$ make install 也可以用 make && make install命令结合使用。以下是安装成功后的目录结构


结合之前的sqladvisor,可实现在网页上填入数据库连接和sql语句等,后端通过nginx和lua脚本,转换成命令形式,并解析返回的结果。操作如下:1、在nginx/conf目录下的nginx.conf文件中,增加以下命令# shell location /sqladvisor/exec { content_by_lua_file conf/luascript/sqladvisor.lua; }并去掉注释掉的错误日志脚本 error_log logs/error.log
2、创建luascript文件夹,并写一个lua脚本,脚本内容如下local shell = require("resty.shell")local args = { socket = "unix:/tmp/shell.sock",}ngx.header.content_type = "text/plain"--post请求参数ngx.req.read_body()local post_args = ngx.req.get_post_args()port = tonumber(post_args.port)cmd = "sqladvisor -h "..post_args.host.. " -P "..port .. " -u "..post_args.userName.. " -p "..post_args.passWord.. " -d "..post_args.database.. " -q \""..post_args.sqlText.."\" -v 1"local status,out,err = shell.execute(cmd, args)ngx.say("data:\n",err)
其中使用了require("resty.shell")这个模块,所以在openresty中需要添加这个模板。3、进入lualib这个目录,
找到resty模块,里面有很多命令的lua脚本,因为这次需要shell脚本的,所以需要从网上下载一份lua脚本。git clone https://github.com/juce/lua-resty-shell 然后把lua脚本copy到当前目录 cp /opt/openresty/sockproc/lua-resty-shell/lib/resty/shell.lua ./
4、需要把sqladvisor 这个命令放入全局的环境变量中,此时可以通过软连接的形式操作。找到上次安装的sqladvisor的目录
命令:ln -s /usr/local/SQLAdvisor/sqladvisor/sqladvisor /usr/local/bin/操作到此结束。


填入相关参数
浏览器返回结果



附录:SQLAdvisor的安装拉取最新代码1、git clone https://github.com/Meituan-Dianping/SQLAdvisor.git配置软连接2、cd /usr/lib64/ 3、ln -s libperconaserverclient_r.so.18 libperconaserverclient_r.so安装依赖项4、yum install cmake libaio-devel libffi-devel glib2 glib2-devel有可能需要配置percona56 5、 yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm安装依赖项 其中Percona56的值可以通过yum repolist指定,比如这里可以把Percona56替换成percona-release-x86_64
6、 yum install --enablerepo=Percona56 Percona-Server-shared-56进入SQLAdvisor目录7、cmake -DBUILD_CONFIG=mysql_release -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr/local/sqlparser ./编译和安装8、make && make install9、cd SQLAdvisor/sqladvisor/编译10、cmake -DCMAKE_BUILD_TYPE=debug ./11、make看到这里,说明安装成功

相关内容

    暂无相关文章