docker安装orange

整个文档参照:https://www.cnblogs.com/cbcye/p/6041170.html

进入容器安装 vi 命令:
https://www.cnblogs.com/xiaoyou2018/p/10912117.html
在使用docker容器时,有时候里边没有安装vim,敲vim命令时提示说:vim: command not found,这个时候就需要安装vim,可是当你敲apt-get install vim命令时,提示:
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package vim
这时候需要敲:apt-get update,这个命令的作用是:同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。
等更新完毕以后再敲命令:apt-get install vim -y 命令即可

1、docker run --name platform-db -v /alidata/database:/var/lib/mysql/ -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 daocloud.io/mysql:5.7
2、docker exec -it platform-db /bin/bash
3、进入到容器登录 mysql
mysql -u root -p
4、创建数据库和用户
CREATE DATABASE orange;
CREATE USER ‘orange’@’%’ IDENTIFIED BY ‘orange’;
GRANT ALL PRIVILEGES ON orange.* TO ‘orange’@’%’;

5、执行初始化语句:
在容器中执行进入orange 表空间
use orange
DROP TABLE IF EXISTS dashboard_user;
CREATE TABLE dashboard_user (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
username varchar(60) NOT NULL DEFAULT ‘’ COMMENT ‘用户名’,
password varchar(255) NOT NULL DEFAULT ‘’ COMMENT ‘密码’,
is_admin tinyint(4) NOT NULL DEFAULT ‘0’ COMMENT ‘是否是管理员账户:0否,1是’,
create_time timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ‘创建或者更新时间’,
enable tinyint(4) NOT NULL DEFAULT ‘0’ COMMENT ‘是否启用该用户:0否1是’,
PRIMARY KEY (id),
UNIQUE KEY unique_username (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=‘dashboard users’;

INSERT INTO dashboard_user (id, username, password, is_admin, create_time, enable)
VALUES
(1,‘admin’,‘1fe832a7246fd19b7ea400a10d23d1894edfa3a5e09ee27e0c4a96eb0136763d’,1,‘2016-05-09 17:24:47’,1);

Dump of table divide

------------------------------------------------------------

DROP TABLE IF EXISTS divide;

CREATE TABLE divide (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_divide_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table meta

------------------------------------------------------------

DROP TABLE IF EXISTS meta;

CREATE TABLE meta (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(5000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table monitor

------------------------------------------------------------

DROP TABLE IF EXISTS monitor;

CREATE TABLE monitor (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table redirect

------------------------------------------------------------

DROP TABLE IF EXISTS redirect;

CREATE TABLE redirect (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table rewrite

------------------------------------------------------------

DROP TABLE IF EXISTS rewrite;

CREATE TABLE rewrite (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table waf

------------------------------------------------------------

DROP TABLE IF EXISTS waf;

CREATE TABLE waf (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_waf_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table basic_auth

------------------------------------------------------------

DROP TABLE IF EXISTS basic_auth;

CREATE TABLE basic_auth (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_basic_auth_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table key_auth

------------------------------------------------------------

DROP TABLE IF EXISTS key_auth;

CREATE TABLE key_auth (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_key_auth_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Dump of table rate_limiting

------------------------------------------------------------

DROP TABLE IF EXISTS rate_limiting;

CREATE TABLE rate_limiting (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
key varchar(255) NOT NULL DEFAULT ‘’,
value varchar(2000) NOT NULL DEFAULT ‘’,
op_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY unique_rate_limiting_key (key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

7、下载orange 镜像
sudo docker run -d --name orange
–link platform-db:orange-database
-p 7777:7777
-p 8888:8888
-p 9999:9999
–security-opt seccomp:unconfined
registry.cn-hangzhou.aliyuncs.com/duqian/orange

8、进入platform-db 镜像
sudo docker exec -it platform-db /bin/bash

vi /usr/local/orange/orange.conf #修改数据库连接信息
vi /usr/local/orange/conf/nginx.conf #配置upstream server,真实api server
注释:
查看容器IP地址:
docker inspect --format=’{{.NetworkSettings.IPAddress}}’ 容器ID/NAME
我这里查到的MySQL容器的IP地址为:172.17.0.2

orange.conf 配置:
orange.conf start:
{
“plugins”: [
“stat”,
“headers”,
“monitor”,
“redirect”,
“rewrite”,
“rate_limiting”,
“property_rate_limiting”,
“basic_auth”,
“key_auth”,
“jwt_auth”,
“hmac_auth”,
“signature_auth”,
“waf”,
“divide”
],
“store”: “mysql”,
“store_mysql”: {
“timeout”: 5000,
“connect_config”: {
“host”: “172.17.0.2”,
“port”: 3306,
“database”: “orange”,
“user”: “orange”,
“password”: “orange”,
“max_packet_size”: 1048576
},
“pool_config”: {
“max_idle_timeout”: 10000,
“pool_size”: 3
},
“desc”: “mysql configuration”
},
“dashboard”: {
“auth”: true,
“session_secret”: “y0ji4pdj61aaf3f11c2e65cd2263d3e7e5”,
“whitelist”: [
“^/auth/login " , " / e r r o r / ", "^/error/ ","/error/
]
},
“api”: {
“auth_enable”: false,
“credentials”: [
{
“username”:“api_username”,
“password”:“api_password”
}
]
}
}
orange.conf end
nginx.conf start:
worker_processes auto;
user root;

events {
worker_connections 4096;
}

optional: path of orange.conf

env ORANGE_CONF;

http {
resolver 114.114.114.114; # replace it with your favorite config
charset UTF-8;
include ./mime.types;

log_format  main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$request_time" "$ssl_protocol" "$ssl_cipher" "$http_x_forwarded_for"'
'"$upstream_addr" "$upstream_status" "$upstream_response_length" "$upstream_response_time"';

access_log  ./logs/access.log  main;
error_log ./logs/error.log error;

sendfile        on;
keepalive_timeout  65;

upstream default_upstream {
    server localhost:8001;
}

#
# Config client_body_buffer_size equal client_max_body_size for enforcing in-memory buffering of the whole request body
# ref: https://github.com/openresty/lua-nginx-module/issues/521
#
# official instruct docs http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
#
client_body_buffer_size 1m;
client_max_body_size 1m;

#----------------------------Orange configuration-----------------------------
lua_package_path  "$prefix/deps/share/lua/5.1/?.lua;$prefix/deps/share/lua/5.1/orange/?.lua;$prefix/?.lua;/usr/share/lua/5.1/?.lua;/usr/local/lor/?.lua;;";
lua_package_cpath "$prefix/deps/lib64/lua/5.1/?.so;$prefix/deps/lib/lua/5.1/?.so;/usr/lib64/lua/5.1/?.so;;";
lua_code_cache on;

lua_shared_dict orange_data 20m; # should not removed. used for orange data, e.g. plugins configurations..

lua_shared_dict status 1m; # used for global statistic, see plugin: stat
lua_shared_dict waf_status 1m; # used for waf statistic, see plugin: waf
lua_shared_dict monitor 10m; # used for url monitor statistic, see plugin: monitor
lua_shared_dict rate_limit 10m; # used for rate limiting count, see plugin: rate_limiting
lua_shared_dict property_rate_limiting 10m; # used for rate limiting count, see plugin: rate_limiting



init_by_lua_block {
    local orange = require("orange.orange")
    local env_orange_conf = os.getenv("ORANGE_CONF")
    print(string.char(27) .. "[34m" .. "[INFO]" .. string.char(27).. "[0m", [[the env[ORANGE_CONF] is ]], env_orange_conf)

    -- Here, you can also use the absolute path, eg: local confige_file = "/home/openresty/orange/conf/orange.conf"
    local config_file = env_orange_conf or ngx.config.prefix().. "/conf/orange.conf"
    local config, store = orange.init({
        config = config_file
    })

    -- the orange context
    context = {
        orange = orange,
        store = store,
        config = config
    }
}

init_worker_by_lua_block {
    local orange = context.orange
    orange.init_worker()
}

# main server
server {
    listen       80;
    #server_name  my_domain.com;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location / {
        set $upstream_host $host;
        set $upstream_url 'http://default_upstream';

        rewrite_by_lua_block {
            local orange = context.orange
            orange.redirect()
            orange.rewrite()
        }

        access_by_lua_block {
            local orange = context.orange
            orange.access()
        }

        # proxy
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Scheme $scheme;
        proxy_set_header Host $upstream_host;
        proxy_pass $upstream_url;


        header_filter_by_lua_block {
            local orange = context.orange
            orange.header_filter()
        }

        body_filter_by_lua_block {
            local orange = context.orange
            orange.body_filter()
        }

        log_by_lua_block {
            local orange = context.orange
            orange.log()
        }
    }

    location /robots.txt {
        return 200 'User-agent: *\nDisallow: /';
    }
}

# default upstream server
server {
    listen 8001;
    server_name localhost 127.0.0.1;
    access_log ./logs/default_upstream_access.log main;
    error_log ./logs/default_upstream_error.log;

    location / {
        content_by_lua_block {
            local json = require "cjson"
            ngx.status = 200
            ngx.say("Host: "..ngx.var.host .. "  URI: " .. ngx.var.uri)
            ngx.say('[Query Params]', json.encode(ngx.req.get_uri_args()))
            ngx.req.read_body()
            ngx.say('[Post Params]', json.encode(ngx.req.get_post_args()))
            ngx.say('[Header Params]', json.encode(ngx.req.get_headers()))
        }
    }
}


# orange dashboard server
server {
    listen       9999;
    stub_status on;
    #server_name  localhost;
    access_log ./logs/dashboard_access.log main;
    error_log ./logs/dashboard_error.log info;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location /robots.txt {
        return 200 'User-agent: *\nDisallow: /';
    }

    # dashboard的静态文件
    location ~* /static/(.*) {
        alias ./dashboard/static/$1;
    }

    location / {
        set $template_root '';
        content_by_lua_block {
            context.views_path = ngx.config.prefix() .. "/dashboard/views"
            local main = require("dashboard.main")
            main:run()
        }
    }
}

# api server
server {
    listen       7777;
    #server_name  localhost;
    access_log ./logs/api_access.log main;
    error_log ./logs/api_error.log info;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location /robots.txt {
        return 200 'User-agent: *\nDisallow: /';
    }

    location / {
        content_by_lua_block {
            local main = require("api.main")
            main:run()
        }
    }
}

upstream api_business {
 server 10.160.145.69:8003;
}

}

nginx.conf end

9、重启orange
sudo docker stop orange
sudo docker start orange

10、Orange Gateway控制台
访问http://192.168.56.101:9999 用户名:admin 密码:orange_admin

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值