orange(1)0.8.0版 網關安裝步驟(及開發生產環境創建)

進行以下操作之前先詳細閱讀github上的說明參見Github官方說明,可以避免很多麻煩。

orange網關必要軟件

  • openresty
  • openresty-resty resty命令行工具
  • mysql
  • LuaRocks Lua 模塊的安裝和部署工具,類似nodeJs的npm
  • lor 框架是lua的web開發框架

1. 安裝openresty

1.1 安裝輔助工具

<code>yum install yum-utils/<code>

一直報錯404,找不到資源,更新yum鏡像源

<code># 先清理
yum clean all
# 再更新
yum update/<code>

注意:因為需要在將stub_status_module編譯進openresty,所以不能直接yum install安裝

<code>[root@localhost /]#yum -y install libuuid-devel pcre-devel openssl-devel gcc-c++ wget
...
[root@localhost /]# cd opt/
[root@localhost opt]# mkdir openresty
[root@localhost opt]# cd openresty/
[root@localhost openresty]#/<code>

1.2 安裝openresty

訪問openresty官網找到最新版本的gz包鏈接 openresty官網

<code>[root@localhost openresty]#
[root@localhost openresty]# wget https://openresty.org/download/openresty-1.15.8.2.tar.gz
--2019-10-24 10:31:03-- https://openresty.org/download/openresty-1.15.8.2.tar.gz
Resolving openresty.org (openresty.org)... 182.92.4.22
Connecting to openresty.org (openresty.org)|182.92.4.22|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4906176 (4.7M) [application/x-gzip]
Saving to: ‘openresty-1.15.8.2.tar.gz’
100%[======================================================================================================================================================================================>] 4,906,176 1.82MB/s in 2.6s
2019-10-24 10:31:07 (1.82 MB/s) - ‘openresty-1.15.8.2.tar.gz’ saved [4906176/4906176]
[root@localhost openresty]# ll
total 4792
-rw-rw-r--. 1 root root 4906176 Sep 8 01:46 openresty-1.15.8.2.tar.gz
[root@localhost openresty]#
# 解壓縮
[root@localhost openresty]# tar -zxf openresty-1.15.8.2.tar.gz
[root@localhost openresty]#
# 配置
[root@localhost openresty]# cd openresty-1.15.8.2
[root@localhost openresty-1.15.8.2]#
[root@localhost openresty-1.15.8.2]# ll
total 104
drwxrwxr-x. 46 justin 1003 4096 Aug 29 01:33 bundle
-rwxrwxr-x. 1 justin 1003 52432 Aug 29 01:32 configure
-rw-rw-r--. 1 justin 1003 22924 Aug 29 01:32 COPYRIGHT
drwxrwxr-x. 2 justin 1003 4096 Aug 29 01:32 patches
-rw-rw-r--. 1 justin 1003 4689 Aug 29 01:32 README.markdown
-rw-rw-r--. 1 justin 1003 8972 Aug 29 01:32 README-windows.txt
drwxrwxr-x. 2 justin 1003 50 Aug 29 01:32 util
[root@localhost openresty-1.15.8.2]#
[root@localhost openresty-1.15.8.2]# ./configure --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module
platform: linux (linux)
cp -rp bundle/ build
cd build
cd LuaJIT-2.1-20190507
INFO: found -msse4.2 in cc.
gmake TARGET_STRIP=@: CCDEBUG=-g XCFLAGS='-DLUAJIT_ENABLE_LUA52COMPAT -DLUAJIT_ENABLE_GC64 -msse4.2' CC=cc PREFIX=/usr/local/openresty/luajit
==== Building LuaJIT 2.1.0-beta3 ====
gmake -C src
...
nginx http scgi temporary files: "scgi_temp"

cd ../..
Type the following commands to build and install:
gmake
gmake install
[root@localhost openresty-1.15.8.2]#
# 編譯安裝
[root@localhost openresty-1.15.8.2]# gmake && gmake install

...
# 建立軟連接,開機自啟動
[root@localhost openresty-1.15.8.2]#
[root@localhost openresty-1.15.8.2]# ln -s /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
[root@localhost openresty-1.15.8.2]#
[root@localhost openresty-1.15.8.2]# ln -s /usr/local/openresty/nginx/sbin/nginx /usr/bin/openresty
[root@localhost openresty-1.15.8.2]# nginx -v
nginx version: openresty/1.15.8.2
[root@localhost openresty-1.15.8.2]#/<code>

1.3 啟動openresty

<code>[root@localhost bin]# openresty
[root@localhost bin]# ps -ef|grep openresty
root 5239 1 0 11:36 ? 00:00:00 nginx: master process openresty
root 5242 2443 0 11:36 pts/0 00:00:00 grep --color=auto openresty
[root@localhost bin]#/<code>

2. 安裝resty命令行工具

<code>[root@localhost bin]# yum install openresty-resty/<code>

orange命令行工具, 依賴resty命令

3. 安裝mysql, 初始化orange數據庫

3.1 下載mysql安裝包,創建mysql賬號

<code>[root@localhost /]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
# 解壓
[root@localhost opt]# tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
...
[root@localhost opt]# cp mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql -r
# 添加msyql用戶組
[root@localhost opt]# groupadd mysql
# 添加mysql用戶
[root@localhost opt]# useradd -r -g mysql mysql
# 禁止msyql用戶登錄主機
[root@localhost opt]# usermod -s /bin/false mysql
[root@localhost opt]#/<code>

3.2 安裝mysql服務

<code>[root@localhost opt]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin docs include lib LICENSE LICENSE.router man README README.router run share support-files var
[root@localhost mysql]# chown -R mysql:mysql ./
[root@localhost mysql]#/<code>

3.3 mysql5.7版本之後的方式初始化數據庫

<code>root@localhost mysql]# cd /usr/local/mysql/bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2019-10-24T16:44:24.044262Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2019-10-24T16:44:24.044719Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 6013
2019-10-24T16:44:30.851231Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ********
[root@localhost bin]#/<code>

記住root賬號的密碼:********

3.4 編輯mysql配置文件 /etc/my.cnf

<code>[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[client]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysqld_safe]
log-error=/usr/local/mysql/data/log/mysqld.log
pid-file=/var/run/msyqld/mysqld.pid
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
#
# include all files from the config directory
#
# !includedir /etc/my.cnf.d/<code>

添加mysql賬號訪問權限

<code>chown -R mysql:mysql /usr/local/mysql/<code> 

3.5 設置mysql開機自啟動

<code>[root@localhost support-files]# pwd
/usr/local/mysql/support-files
[root@localhost support-files]# ls
mysqld_multi.server mysql-log-rotate mysql.server
[root@localhost support-files]#
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld
[root@localhost support-files]#/<code>

3.6 啟動mysql

<code>[root@localhost log]# service mysqld start
Starting MySQL.. SUCCESS!
[root@localhost log]#
[root@localhost log]# mysql -u root -p
-bash: /usr/bin/mysql: No such file or directory
[root@localhost log]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
[root@localhost log]#/<code>

3.7 訪問mysql修改密碼

<code>mysql>
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=PASSWORD('123456');
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PASSWORD('123456')' at line 1
# 必須用alter命令來修改密碼
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.09 sec)
# 設定永不過期
mysql> alter user 'root'@'localhost' password expire never;
Query OK, 0 rows affected (0.07 sec)
# 刷新權限
mysql> flush privileges;
Query OK, 0 rows affected (0.07 sec)
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+

4 rows in set (0.01 sec)

mysql>/<code>

mysql 安裝完成.

3.8 初始化orange數據庫

<code>mysql> CREATE DATABASE orange CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.08 sec)

mysql> CREATE USER 'orange'@'%' IDENTIFIED BY 'orange';
Query OK, 0 rows affected (0.08 sec)

mysql> GRANT ALL PRIVILEGES ON orange.* TO 'orange'@'%';
Query OK, 0 rows affected (0.09 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.06 sec)

mysql>/<code>
  • 下載orange數據庫腳本github地址,導入mysql
<code>[root@localhost opt]# mysql -u root -p --database orange <./>/<code>

4. 安裝lor框架

lor框架是lua的web開發框架,類似於node.js的express框架,主要用於web界面dashboard

<code>[root@localhost ~]# yum install -y git
...
[root@localhost ~]# cd /opt/
[root@localhost opt]#
[root@localhost opt]# ls
containerd mysql-8.0.18-linux-glibc2.12-x86_64 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz openresty orange-v0.8.0.sql
[root@localhost opt]# git clone https://github.com/sumory/lor.git
Cloning into 'lor'...
remote: Enumerating objects: 30, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 1759 (delta 5), reused 17 (delta 5), pack-reused 1729
Receiving objects: 100% (1759/1759), 355.55 KiB | 206.00 KiB/s, done.

Resolving deltas: 100% (911/911), done.
[root@localhost opt]#
[root@localhost opt]# ls
containerd lor mysql-8.0.18-linux-glibc2.12-x86_64 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz openresty orange-v0.8.0.sql
[root@localhost opt]# cd lor/
[root@localhost lor]#
[root@localhost lor]# pwd
/opt/lor
[root@localhost lor]# make install
install lor runtime files to /usr/local/lor
lor runtime files installed.
install lord cli to /usr/local/bin/
lord cli installed.
lor framework installed successfully./<code>

5. 安裝LuaRocks

luarocks是一個lua的包管理器(類似於nodejs的npm),基於lua語言開發,提供命令行的方式管理lua包依賴,安裝第三方lua包。 下載luarocks源碼

5.1 下載luarocks

<code># 下載
[root@localhost luarocks-3.1.3]# wget https://luarocks.github.io/luarocks/releases/luarocks-3.1.3.tar.gz
[root@localhost luarocks-3.1.3]# tar zxvf luarocks-3.1.3.tar.gz
[root@localhost luarocks-3.1.3]# cd luarocks-3.1.3
# 查看文件
[root@localhost luarocks-3.1.3]# ll
total 100
drwxr-xr-x. 2 justin users 4096 Jun 7 03:46 binary
drwxrwxr-x. 2 root root 63 Oct 25 23:40 build
-rw-r--r--. 1 justin users 10403 Jun 7 03:46 CHANGELOG.md
-rw-r--r--. 1 justin users 3152 Jun 7 03:46 CODE_OF_CONDUCT.md
-rw-r--r--. 1 justin users 143 Jun 7 03:46 config.ld
-rw-rw-r--. 1 root root 352 Oct 25 23:39 config.unix
-rwxr-xr-x. 1 justin users 14119 Jun 7 03:46 configure
-rw-r--r--. 1 justin users 1060 Jun 7 03:46 COPYING
-rw-r--r--. 1 justin users 6114 Jun 7 03:46 GNUmakefile
-rwxr-xr-x. 1 root root 549 Oct 25 23:40 lua
drwxr-xr-x. 3 root root 16 Oct 25 23:40 lua_modules
-rwxrwxr-x. 1 root root 275 Oct 25 23:40 luarocks
-rw-r--r--. 1 justin users 1120 Jun 7 03:46 luarocks-3.1.3-1.rockspec
-rwxrwxr-x. 1 root root 281 Oct 25 23:40 luarocks-admin
-rw-r--r--. 1 justin users 78 Jun 7 03:46 Makefile
-rwxr-xr-x. 1 justin users 443 Jun 7 03:46 mergerelease
-rwxr-xr-x. 1 justin users 4930 Jun 7 03:46 publishrelease

-rw-r--r--. 1 justin users 1880 Jun 7 03:46 README.md
-rwxr-xr-x. 1 justin users 1000 Jun 7 03:46 smoke_test.sh
drwxr-xr-x. 4 justin users 4096 Jun 7 03:46 spec
drwxr-xr-x. 4 justin users 31 Jun 7 03:46 src
[root@localhost luarocks-3.1.3]#
# 優先查看README.md瞭解安裝流程/<code>

可以看到有 configure,Markfile 文件,通常軟件源碼安裝為三個步驟

配置(configure) 編譯(make) 安裝(make install) 參考:源碼安裝

5.2 源碼安裝luarocks

參考:Lua包管理工具luarocks安裝

<code># 查看配置信息
[root@localhost luarocks-3.1.3]# ./configure --help
# 有兩個重要參數
# 設置luarocks的安裝路徑,默認 /usr/local
# --prefix 設置prefix會自動將Luarocks以及往後使用Luarocks安裝的Lua包,LuaC包都安裝到Luarocks安裝路徑下的相應位置,否則相關的包文件散落在文件系統中,顯得雜亂不便於管理,如果所安裝的Lua模板包含bin文件,則會自動安裝到此目錄下的bin路徑,與Luarocks可執行文件同一路徑,更便於管理、使用。
--prefix=PREFIX Directory where LuaRocks should be installed
[/usr/local]
# 指定luarocks依賴的lua安裝路徑
--with-lua=LUA_DIR Use Lua from given directory. [LUA_BINDIR/..]/<code>

5.2 配置luarocks

<code>[root@localhost luarocks-3.1.3]#
[root@localhost luarocks-3.1.3]# ./configure --prefix=/usr/local/luarocks --with-lua=/usr/local/luajit

Configuring LuaRocks version 3.1.3...


Lua version detected: 5.1
Lua interpreter found: /usr/local/luajit/bin/luajit
lua.h found: /usr/local/luajit/include/luajit-2.0/lua.h
unzip found in PATH: /usr/bin

Done configuring.

LuaRocks will be installed at......: /usr/local/luarocks
LuaRocks will install rocks at.....: /usr/local/luarocks
LuaRocks configuration directory...: /usr/local/luarocks/etc/luarocks
Using Lua from.....................: /usr/local/luajit

* Type make and make install:
to install to /usr/local/luarocks as usual.
* Type make bootstrap:
to install LuaRocks into /usr/local/luarocks as a rock./<code>

5.3 編譯 安裝luarocks

  • make && make install 編譯安裝 順序執行
<code>[root@localhost luarocks-3.1.3]# make && make install
mkdir -p "build"
rm -f src/luarocks/core/hardcoded.lua
echo "#!/bin/sh" > luarocks
echo "unset LUA_PATH LUA_PATH_5_2 LUA_PATH_5_3 LUA_PATH_5_4" >> luarocks
echo 'LUAROCKS_SYSCONFDIR="/usr/local/luarocks/etc/luarocks" LUA_PATH="/opt/luarocks-3.1.3/src/?.lua;;" exec "/usr/local/luajit/bin/luajit" "/opt/luarocks-3.1.3/src/bin/luarocks" --project-tree="/opt/luarocks-3.1.3/lua_modules" "$@"' >> luarocks
chmod +rx ./luarocks
./luarocks init

Initializing project 'luarocks-3.1.3' for Lua 5.1 ...
-----------------------------------------------------

Checking your Lua installation ...
Adding entries to .gitignore ...
Preparing ./.luarocks/ ...
Wrote .luarocks/config-5.1.lua
Preparing ./lua_modules/ ...
./luarocks already exists. Not overwriting it!
Preparing ./lua for version 5.1...
cp ./build/config-5.1.lua .luarocks/config-5.1.lua
rm -f src/luarocks/core/hardcoded.lua
echo "#!/bin/sh" > luarocks-admin
echo "unset LUA_PATH LUA_PATH_5_2 LUA_PATH_5_3 LUA_PATH_5_4" >> luarocks-admin
echo 'LUAROCKS_SYSCONFDIR="/usr/local/luarocks/etc/luarocks" LUA_PATH="/opt/luarocks-3.1.3/src/?.lua;;" exec "/usr/local/luajit/bin/luajit" "/opt/luarocks-3.1.3/src/bin/luarocks-admin" --project-tree="/opt/luarocks-3.1.3/lua_modules" "$@"' >> luarocks-admin
chmod +rx ./luarocks-admin

mkdir -p "build"
(printf '#!/usr/local/luajit/bin/luajit\\n'\\
'package.loaded["luarocks.core.hardcoded"] = { '\\
"$([ -n "" ] && printf 'FORCE_CONFIG = true, ')"\\
'SYSCONFDIR = [[/usr/local/luarocks/etc/luarocks]] }\\n'\\
'package.path=[[/usr/local/luarocks/share/lua/5.1/?.lua;]] .. package.path\\n'; \\
tail -n +2 src/bin/luarocks \\
)> "build/luarocks"
mkdir -p "build"
(printf '#!/usr/local/luajit/bin/luajit\\n'\\
'package.loaded["luarocks.core.hardcoded"] = { '\\
"$([ -n "" ] && printf 'FORCE_CONFIG = true, ')"\\
'SYSCONFDIR = [[/usr/local/luarocks/etc/luarocks]] }\\n'\\
'package.path=[[/usr/local/luarocks/share/lua/5.1/?.lua;]] .. package.path\\n'; \\
tail -n +2 src/bin/luarocks-admin \\
)> "build/luarocks-admin"
mkdir -p "/usr/local/luarocks/bin"
install "build/luarocks" "/usr/local/luarocks/bin/luarocks"
mkdir -p "/usr/local/luarocks/bin"
install "build/luarocks-admin" "/usr/local/luarocks/bin/luarocks-admin"
mkdir -p "/usr/local/luarocks/etc/luarocks"
install -m 644 "build/config-5.1.lua" "/usr/local/luarocks/etc/luarocks/config-5.1.lua"
[root@localhost luarocks-3.1.3]#
[root@localhost luarocks-3.1.3]# luarocks
LuaRocks 3.1.3, the Lua package manager
...
CONFIGURATION
\tLua version: 5.1
\tLuaJIT version: 2.0.5

\tConfiguration files:
\t\tSystem : /usr/local/luarocks/etc/luarocks/config-5.1.lua (ok)
\t\tUser : /root/.luarocks/config-5.1.lua (not found)
\t\tProject : /opt/luarocks-3.1.3/./.luarocks/config-5.1.lua (ok)

\tRocks trees in use:
\t\t/opt/luarocks-3.1.3/./lua_modules ("project")
\t\t/root/.luarocks ("user")
\t\t/usr/local/luarocks ("system")/<code>

luarocks已經成功安裝,指定的lua是 luajit 2.0.5

6. 安裝orange

6.1 clone下載orange源碼

<code>[root@localhost opt]#
[root@localhost opt]# git clone https://github.com/sumory/orange.git
Cloning into 'orange'...

remote: Enumerating objects: 46, done.
remote: Counting objects: 100% (46/46), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 4436 (delta 17), reused 28 (delta 11), pack-reused 4390
Receiving objects: 100% (4436/4436), 2.84 MiB | 562.00 KiB/s, done.
Resolving deltas: 100% (2903/2903), done.
[root@localhost opt]# ll
total 492080
drwx--x--x. 4 root root 26 Sep 11 14:14 containerd
drwxrwxr-x. 8 root root 4096 Oct 25 04:59 lor
drwxrwxr-x. 11 root root 4096 Oct 24 12:38 mysql-8.0.18-linux-glibc2.12-x86_64
-rw-rw-r--. 1 root root 503854832 Sep 22 10:33 mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
drwxrwxr-x. 3 root root 63 Oct 24 10:32 openresty
drwxrwxr-x. 13 root root 4096 Oct 25 05:01 orange
-rw-r--r--. 1 root root 18157 Oct 24 13:21 orange-v0.8.0.sql
[root@localhost opt]#/<code>

6.2 創建orange開發環境配置

cd orangemake dev

<code>[root@localhost orange]# make dev
luarocks install rockspec/orange-master-1.0-0.rockspec --tree=deps --only-deps --local
Missing dependencies for orange-master 1.0-0:
luafilesystem 1.7.0-2 (not installed)
penlight 1.5.4-1 (not installed)
lrandom 20180729-1 (not installed)
luacrypto 0.3.2-2 (not installed)
luasocket 3.0rc1-2 (not installed)
lua-resty-http 0.13-0 (not installed)
lua-resty-kafka 0.06-0 (not installed)
lua-resty-dns-client 1.0.0-1 (not installed)
lua-resty-jwt 0.2.0-0 (not installed)

...
install conf/nginx.conf.example conf/nginx.conf
install conf/orange.conf.example conf/orange.conf
install install/orange-v0.8.0.sql conf/orange-v0.8.0.sql
[root@localhost orange]#/<code>

安裝完orange依賴包,及配置文件自動生成.

6.3 配置文件 conf/orange.conf

<code>[root@localhost conf]#
[root@localhost conf]# pwd
/opt/orange/conf
[root@localhost conf]# ll

total 16
-rw-rw-r--. 1 root root 3957 Oct 25 05:01 mime.types
-rw-rw-r--. 1 root root 6796 Oct 25 05:01 nginx.conf.example
-rw-rw-r--. 1 root root 1218 Oct 25 05:01 orange.conf.example
[root@localhost conf]#/<code>

兩個配置文件nginx.conf 和 orange.conf ,官方提供了example,參照修改即可

<code>[root@localhost conf]# pwd
/opt/orange/conf
[root@localhost conf]# ll
total 16
-rw-rw-r--. 1 root root 3957 Oct 25 05:01 mime.types
-rw-rw-r--. 1 root root 6796 Oct 25 05:01 nginx.conf.example
-rw-rw-r--. 1 root root 1218 Oct 25 05:01 orange.conf.example
[root@localhost conf]# vim orange.conf.example
[root@localhost conf]# vim nginx.conf.example
[root@localhost conf]# cp orange.conf.example orange.conf
[root@localhost conf]# cp nginx.conf.example nginx.conf
[root@localhost conf]# vim orange.conf
[root@localhost conf]#/<code>

修改 orange.conf 中的db配置

<code>...
"store": "mysql",
"store_mysql": {
"timeout": 5000,
"connect_config": {
"host": "127.0.0.1",
"port": 3306,
"database": "orange",
"user": "root",
"password": "123456",
"charset": "utf8",
"max_packet_size": 1048576
},
"pool_config": {
"max_idle_timeout": 10000,
"pool_size": 3
},
"desc": "mysql configuration"
.../<code>

dashboard前端的登錄驗證

<code>... 

"dashboard": {
"auth": true, # true 表示dashboard需要登錄
"session_secret": "y0ji4pdj61aaf3f11c2e65cd2263d3e7e5",
"whitelist": [
"^/auth/login$",
"^/error/$"
]
},
.../<code>

6.4 開發環境啟動orange

注意: 當前路徑為:orange,命令執行時需要按照當前所在路徑查找配置文件,否則會報錯,例如:

  • 錯誤:
<code>[root@localhost bin]# pwd
/opt/orange/bin
[root@localhost bin]# ./orange start
ERROR: ./orange:38: module 'bin.main' not found:
\tno field package.preload['bin.main']
\tno file '/opt/orange/bin/deps/share/lua/5.1/orange/bin/main.lua'
\tno file '/opt/orange/bin/deps/share/lua/5.1/bin/main.lua'
\tno file '/usr/local/openresty/site/lualib/bin/main.ljbc'
\tno file '/usr/local/openresty/site/lualib/bin/main/init.ljbc'
\tno file '/usr/local/openresty/lualib/bin/main.ljbc'
\tno file '/usr/local/openresty/lualib/bin/main/init.ljbc'
\tno file '/usr/local/openresty/site/lualib/bin/main.lua'
\tno file '/usr/local/openresty/site/lualib/bin/main/init.lua'
\tno file '/usr/local/openresty/lualib/bin/main.lua'
\tno file '/usr/local/openresty/lualib/bin/main/init.lua'
\tno file './bin/main.lua'
\tno file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/bin/main.lua'
\tno file '/usr/local/share/lua/5.1/bin/main.lua'
\tno file '/usr/local/share/lua/5.1/bin/main/init.lua'
\tno file '/usr/local/openresty/luajit/share/lua/5.1/bin/main.lua'
\tno file '/usr/local/openresty/luajit/share/lua/5.1/bin/main/init.lua'
\tno file '/usr/local/openresty/site/lualib/bin/main.so'
\tno file '/usr/local/openresty/lualib/bin/main.so'
\tno file './bin/main.so'
\tno file '/usr/local/lib/lua/5.1/bin/main.so'
\tno file '/usr/local/openresty/luajit/lib/lua/5.1/bin/main.so'
\tno file '/usr/local/lib/lua/5.1/loadall.so'

\tno file '/usr/local/openresty/site/lualib/bin.so'
\tno file '/usr/local/openresty/lualib/bin.so'
\tno file './bin.so'
\tno file '/usr/local/lib/lua/5.1/bin.so'
\tno file '/usr/local/openresty/luajit/lib/lua/5.1/bin.so'
\tno file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
\t./orange:38: in function 'file_gen'
\tinit_worker_by_lua:46: in function <44>
\t[C]: in function 'xpcall'
\tinit_worker_by_lua:53: in function <51>
[root@localhost bin]#/<code>
  • 正確:
<code>[root@localhost orange]#
[root@localhost orange]# pwd
/opt/orange
[root@localhost orange]#
[root@localhost orange]# ./bin/orange start --orange_conf=/opt/orange/conf/orange.conf --prefix=/opt/orange --ngx_conf=/opt/orange/conf/nginx.conf
[INFO] Orange: 0.8.0
[INFO] ngx_lua: 10015
[INFO] nginx: 1015008
[INFO] Lua: LuaJIT 2.1.0-beta3
[INFO] args:
[INFO] \tngx_conf:/opt/orange/conf/nginx.conf
[INFO] \torange_conf:/opt/orange/conf/orange.conf
[INFO] \tprefix:/opt/orange
[INFO] args end.
[INFO] Start orange command execute.
[INFO] ORANGE_CONF=/opt/orange/conf/orange.conf openresty -p /opt/orange -c /opt/orange/conf/nginx.conf
[root@localhost orange]#
[root@localhost bin]#/<code>

至此,orange開發環境啟動成功,可以開發自己的插件了。

7 生產環境安裝orange

1. 啟動orange

Orange放到/usr/local下, 可通過make install來安裝。執行此命令:make install安裝

<code>[root@localhost local]# cd /opt/orange
[root@localhost orange]#
[root@localhost orange]# make install
/bin/sh: luarocks: command not found
install -d /usr/local/orange/logs
install -d /usr/local/orange/conf
install -d /usr/local/orange/dashboard/views
install -d /usr/local/orange/dashboard/static
install conf/nginx.conf.example /usr/local/orange/conf/nginx.conf
install conf/orange.conf.example /usr/local/orange/conf/orange.conf
install conf/mime.types /usr/local/orange/conf/mime.types
install install/orange-v0.8.0.sql /usr/local/orange/conf/orange-v0.8.0.sql
install -d /usr/share/lua/5.1/orange/dashboard
install -d /usr/share/lua/5.1/orange/orange
install -d /usr/share/lua/5.1/orange/bin
install -d /usr/share/lua/5.1/orange/api
cp -rf dashboard/* /usr/share/lua/5.1/orange/dashboard
cp -rf dashboard/views/* /usr/local/orange/dashboard/views
cp -rf dashboard/static/* /usr/local/orange/dashboard/static
cp -rf orange/* /usr/share/lua/5.1/orange/orange
cp -rf bin/* /usr/share/lua/5.1/orange/bin
cp -rf api/* /usr/share/lua/5.1/orange/api
install bin/orange /usr/bin/orange
rm -f /usr/local/bin/orange
ln -s /usr/bin/orange /usr/local/bin/orange/<code>

注意: 是原來沒有安裝luarocks包管理工具導致的提示沒找到此命令,如果按照正常步驟就不會有此問題,相關包也會安裝。

  • make install 執行結束之後,就可以啟動 orange了。


orange(1)0.8.0版 網關安裝步驟(及開發生產環境創建)

歡迎 “關注” ,結合實際應用,持續更新orange網關係列。


分享到:


相關文章: