首页 运维

centos安装OpenResty api 网关 Orange

发布于: 2020-08-20

OpenResty api网关设计,主要涉及api网关介绍、openresty api网关 请求路由(路由判断、路由重写、服务判断、限流)、授权验证(统一认证)、动态Upstream 以及这三部分理论简单实现的Api网关和Api网关admin。

安装依赖

1
yum -y install libuuid-devel pcre-devel openssl-devel gcc-c++ wget perl-Time-HiRes perl-Digest-MD5

openresty安装

编译安装

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

1
2
3
4
5
wget https://openresty.org/download/openresty-1.13.6.1.tar.gz
tar xf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1
./configure --prefix=/usr/local/openresty --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module
gmake && gmake install

apt安装

https://openresty.org/cn/linux-packages.html

1
2
3
4
5
apt install --no-install-recommends wget gnupg ca-certificates
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
sudo add-apt-repository -y "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"
apt update
apt install -y openresty

luarocks安装

https://luarocks.org/

1
2
3
4
5
6
7
8
9
wget https://luarocks.org/releases/luarocks-2.4.1.tar.gz
cd luarocks-2.4.1/
./configure --prefix=/usr/local/openresty/luajit \
--with-lua=/usr/local/openresty/luajit/ \
--lua-suffix=jit \
--with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
make build
# 安装需要root权限
sudo make install

环境变量设置

1
2
3
4
5
cat /etc/profile.d/openresty.sh 
export OPENRESTY_HOME=/usr/local/openresty
export NGINX_HOME=$OPENRESTY_HOME/nginx
export PATH=$OPENRESTY_HOME/bin:$NGINX_HOME/sbin:$PATH
source /etc/profile

mariadb安装

https://downloads.mariadb.org/mariadb/repositories/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
rpm -e mysql-*
rpm -qa | grep mariadb
yum remove mysql mysql-server mysql-libs compat-mysql51
vi /etc/yum.repos.d/MariaDB.repo

# MariaDB 10.4 CentOS repository list - created 2019-09-28 03:16 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum -y install MariaDB-server

mysql_secure_installation
首先是设置密码,会提示先输入密码

Enter current password for root (enter for none):<–初次运行直接回车
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车(后面授权配置)
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车


mysql -uroot -p
CREATE USER 'orange'@'%' IDENTIFIED BY 'orange';

GRANT ALL PRIVILEGES ON orange.* TO 'orange'@'%';
FLUSH PRIVILEGES;

安装lor

1
2
3
4
yum install -y git
git clone https://github.com/sumory/lor.git
cd lor
make install

启动并配置 orange 服务

https://github.com/orlabs/orange/blob/master/README_zh.md

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
service iptables stop
chkconfig iptables off
git clone https://github.com/sumory/orange.git
cd orange
// orange 根目录
luarocks install luafilesystem
luarocks install luasocket
luarocks install lrandom
// 安装 orange 依赖包
opm --install-dir=./ get zhangbao0325/orangelib
//配置文件
cd conf
cp orange.conf.example orange.conf
cp nginx.conf.example nginx.conf
cd install/
mysql -u orange -porange -h 127.0.0.1 orange < orange-v0.6.2.sql