Total Pageviews

Thursday, 29 August 2024

代理服务器程序XProxy

 XProxy是一个代理服务器,内置有NAT、反向代理、直接代理、间接代理等。

XProxy是一个代理服务器宿主环境,可用于寄宿多种ProxyBase服务,主要是NATProxy反向代理。

2005~2008期间,第一代XProxy同时也是第一代网络库,主要支持NAT、加/解密、反向代理、直接代理、间接代理等,以Http代理缓存以及数据拦截修改为主。
2018年v2.0,采用更成熟稳定且具有千万级吞吐的第三代网络库,主要支持反向代理,转发MySql、Oracle、Redis等。

使用说明

双击启动XProxy.exe,自动生成配置文件Config\XProxy.config,默认如下: Demo

XProxy支持单服务同时寄宿多个代理服务,配置文件的Items下,每一行ProxyItem代表一个代理服务。
以管理员运行XProxy.exe,可以选择把它安装成为Windows服务,并控制它的启动和停止。

新生命开发团队

本应用作为新生命开发团队2018年开源路线图的一部分,依赖库:

新生命开源项目矩阵

各项目默认支持net4.5/net4.0/netstandard2.0

项目 年份 状态 .NET Core 说明
基础组件


支撑其它中间件以及产品项目
NewLife.Core 2002 维护中 算法、日志、网络、RPC、序列化、缓存、多线程
XCode 2005 维护中 数据中间件,MySQL、SQLite、SqlServer、Oracle
NewLife.Net 2005 维护中 网络库,千万级吞吐率,学习gRPC、Thrift
NewLife.Cube 2010 维护中 Web魔方,企业级快速开发框架,集成OAuth
NewLife.Agent 2008 维护中 服务管理框架,Windows服务、Linux的Systemd
中间件


对接各知名中间件平台
NewLife.Redis 2017 维护中 Redis客户端,微秒级延迟,百亿级项目验证
NewLife.RocketMQ 2018 维护中 支持Apache RocketMQ和阿里云消息队列,十亿级项目验证
NewLife.MQTT 2019 维护中 物联网消息协议,客户端支持阿里云物联网
NewLife.LoRa 2016 维护中 超低功耗的物联网远程通信协议LoRaWAN
NewLife.Thrift 2019 维护中 Thrift协议实现
NewLife.Hive 2019 维护中 纯托管读写Hive,Hadoop数据仓库,基于Thrift协议
NoDb 2017 开发中 NoSQL数据库,百万级kv读写性能,持久化
NewLife.Ftp 2008 维护中 Ftp客户端实现
产品平台


产品平台级,编译部署即用,个性化自定义
AntJob 2019 维护中 蚂蚁调度系统,大数据实时计算平台
Stardust 2018 维护中 星尘,微服务平台,分布式平台
XLink 2016 维护中 物联网云平台
XProxy 2005 维护中 产品级反向代理
XScript 2010 维护中 × C#脚本引擎
SmartOS 2014 维护中 C++11 嵌入式操作系统,完全独立自主,ARM Cortex-M芯片架构
GitCandy 2015 维护中 × Git管理系统
其它



XCoder 2006 维护中 码神工具,开发者必备
XTemplate 2008 维护中 模版引擎,T4(Text Template)语法
X组件 .NET2.0 2002 存档中 .NET2.0 日志、网络、RPC、序列化、缓存、Windows服务、多线程

QQ群:1600800
博客:https://nnhy.cnblogs.com

 from https://github.com/NewLifeX/XProxy

----------

XProxy是一个代理服务器宿主环境,可用于寄宿多种ProxyBase服务,主要是NATProxy反向代理。

2018年v2.0,采用更成熟稳定且具有千万级吞吐的第三代网络库,主要支持反向代理,转发MySql、Oracle、Redis等。

下载地址:

https://github.com/NewLifeX/XProxy/releases/download/v2.0/XProxy_v2.0.zip 

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

High-performance MySQL proxy with a GPL license.

www.proxysql.com 

    Introduction

    ProxySQL is a high performance, high availability, protocol aware proxy for MySQL and forks (like Percona Server and MariaDB). All the while getting the unlimited freedom that comes with a GPL license.

    Its development is driven by the lack of open source proxies that provide high performance.

    Useful links

    Getting started

    Installation

    Released packages can be found here: https://github.com/sysown/proxysql/releases

    Just download a package and use your systems package manager to install it:

    wget https://github.com/sysown/proxysql/releases/download/v2.4.2/proxysql_2.4.2-ubuntu20_amd64.deb
    dpkg -i proxysql_2.4.2-ubuntu20_amd64.deb

    Alternatively you can also use the available repositories:

    Ubuntu / Debian:

    Adding repository:

    apt-get update && apt-get install -y --no-install-recommends lsb-release wget apt-transport-https ca-certificates
    wget -nv -O /etc/apt/trusted.gpg.d/proxysql-2.4.x-keyring.gpg 'https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/repo_pub_key.gpg'
    echo "deb https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/$(lsb_release -sc)/ ./" | tee /etc/apt/sources.list.d/proxysql.list

    Installing:

    apt-get update
    apt-get install proxysql OR apt-get install proxysql=version

    Red Hat / CentOS:

    Adding repository:

    cat > /etc/yum.repos.d/proxysql.repo << EOF
    [proxysql]
    name=ProxySQL YUM repository
    baseurl=https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/centos/\$releasever
    gpgcheck=1
    gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/repo_pub_key
    EOF

    Installing:

    yum install proxysql OR yum install proxysql-version

    Amazon Linux:

    Adding repository:

    cat > /etc/yum.repos.d/proxysql.repo << EOF
    [proxysql]
    name=ProxySQL YUM repository
    baseurl=https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/centos/8
    gpgcheck=1
    gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/repo_pub_key
    EOF

    Installing:

    yum install proxysql OR yum install proxysql-version

    Almalinux:

    Adding repository:

    cat > /etc/yum.repos.d/proxysql.repo << EOF
    [proxysql]
    name=ProxySQL YUM repository
    baseurl=https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/almalinux/\$releasever
    gpgcheck=1
    gpgkey=https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/repo_pub_key
    EOF

    Installing:

    yum install proxysql OR yum install proxysql-version

    OpenSUSE:

    Adding repository:

    cat > /etc/zypp/repos.d/proxysql.repo << EOF
    [proxysql]
    name=ProxySQL Zypper repository
    enabled=1
    autorefresh=0
    baseurl=https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/opensuse/\$releasever_major
    gpgcheck=1
    EOF

    or

    zypper addrepo -g -n 'ProxySQL Zypper repository' 'https://repo.proxysql.com/ProxySQL/proxysql-2.4.x/opensuse/$releasever_major' proxysql

    Installing:

    yum install proxysql OR yum install proxysql-version

    FreeBSD:

    Installing (via pkg):

    pkg install proxysql

    Installing (via ports):

    cd /usr/ports/databases/proxysql/ && make install clean

    Service management

    Once the software is installed, you can use the service command to control the process:

    Starting ProxySQL:

    service proxysql start

    Stopping ProxySQL:

    service proxysql stop

    Or alternatively via the Admin interface:

    $ mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
    Warning: Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.5.30 (ProxySQL Admin Module)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    Admin> proxysql stop
    

    Restarting ProxySQL:

    service proxysql restart

    Or alternatively via the Admin interface:

    $ mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
    Warning: Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.5.30 (ProxySQL Admin Module)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    Admin> proxysql restart
    

    Reinitializing ProxySQL from the config file (after first startup the DB file is used instead of the config file):

    # If you are using the init script run:
    /etc/init.d/proxysql initial
    # or
    service proxysql initial
     
    # If you are using the systemd unit file run:
    systemctl start proxysql-initial
    # or
    service proxysql-initial start

    Upgrades

    Just install the new package and restart ProxySQL:

    wget https://github.com/sysown/proxysql/releases/download/v2.1.0/proxysql_2.1.0-ubuntu16_amd64.deb
    dpkg -i proxysql_2.1.0-ubuntu16_amd64.deb
    service proxysql restart

    How to check the ProxySQL version

    $ proxysql --version
    ProxySQL version 2.1.0-544-g17a4b4a7, codename Truls

    A debug version has _DEBUG in its version string. It is slower than non-debug version, but easier to debug in case of failures.

    $ proxysql --version
    Main init phase0 completed in 0.000146 secs.
    ProxySQL version 2.1.0-544-g17a4b4a7_DEBUG, codename Truls

    Configuring ProxySQL via the admin interface

    First of all, bear in mind that the best way to configure ProxySQL is through its admin interface. This lends itself to online configuration (without having to restart the proxy) via SQL queries to its admin database. It's an effective way to configure it both manually and in an automated fashion.

    As a secondary way to configure it, we have the configuration file.

    Configuring ProxySQL through the admin interface

    To log into the admin interface (with the default credentials) use a mysql client and connect using the following admin credentials locally on port (6032):

    $ mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
    Warning: Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.5.30 (ProxySQL Admin Module)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    Admin>

    note: If your MySQL client version is version 8.04 or higher add --default-auth=mysql_native_password to the above command to connect to the admin interface.

    Once connected to the admin interface, you will have a list of databases and tables at your disposal that can be queried using the SQL language:

    Admin> SHOW DATABASES;
    +-----+---------+-------------------------------+
    | seq | name    | file                          |
    +-----+---------+-------------------------------+
    | 0   | main    |                               |
    | 2   | disk    | /var/lib/proxysql/proxysql.db |
    | 3   | stats   |                               |
    | 4   | monitor |                               |
    +-----+---------+-------------------------------+
    4 rows in set (0.00 sec)

    This will allow you to control the list of the backend servers, how traffic is routed to them, and other important settings (such as caching, access control, etc). Once you've made modifications to the in-memory data structure, you must load the new configuration to the runtime, or persist the new settings to disk (so that they are still there after a restart of the proxy). A detailed tutorial on how to configure ProxySQL through the Admin interface is available here.

    Configuring ProxySQL through the config file

    Even though the config file should only be regarded as a secondary way to configure the proxy, we must not discard its value as a valid way to bootstrap a fresh ProxySQL install.

    Let's quickly go over the main sections of the configuration file (this overview serves as a very high level overview of ProxySQL configuration).

    Top-level sections:

    • admin_variables: contains global variables that control the functionality of the admin interface.

    • mysql_variables: contains global variables that control the functionality for handling the incoming MySQL traffic.

    • mysql_servers: contains rows for the mysql_servers table from the admin interface. Basically, these define the backend servers towards which the incoming MySQL traffic is routed. Rows are encoded as per the .cfg file format, here is an example:

       mysql_servers =
       (
       	{
       		address="127.0.0.1"
       		port=3306
       		hostgroup=0
       		max_connections=200
       	}
       )

    mysql_users: contains rows for the mysql_users table from the admin interface. Basically, these define the users which can connect to the proxy, and the users with which the proxy can connect to the backend servers. Rows are encoded as per the .cfg file format, here is an example:

     mysql_users:
     (
     	{
     		username = "root"
     		password = "root"
     		default_hostgroup = 0
     		max_connections=1000
     		default_schema="information_schema"
     		active = 1
     	}
     )

    mysql_query_rules: contains rows for the mysql_query_rules table from the admin interface. Basically, these define the rules used to classify and route the incoming MySQL traffic, according to various criteria (patterns matched, user used to run the query, etc.). Rows are encoded as per the .cfg file format, here is an example (Note: the example is a very generic query routing rule and it is recommended to create specific rules for queries rather than using a generic rule such as this):

     mysql_query_rules:
     (
     	{
     		rule_id=1
     		active=1
     		match_pattern="^SELECT .* FOR UPDATE$"
     		destination_hostgroup=0
     		apply=1
     	},
     	{
     		rule_id=2
     		active=1
     		match_pattern="^SELECT"
     		destination_hostgroup=1
     		apply=1
     	}
     )
  • top-level configuration item: datadir, as a string, to point to the data dir.

    from https://github.com/sysown/proxysql

 
 

No comments:

Post a Comment