Appearance
使用源码安装ProxySQL
操作系统:UnionTech OS Server release 20 (kongzi) 【阿里云ARM架构统信操作系统】
ProxySQL版本:2.6.3
ProxySLQ源码下载地址:https://github.com/sysown/proxysql/releases
ProxySQL编译安装
解压源码包
bash
$ tar -zxvf proxysql-2.6.3.tar.gz
$ cd proxysql-2.6.3查看安装说明文档
bash
$ less INSTALL.md根据INSTALL.md安装依赖
以下配置不是原始的哈
bash
$ yum install -y automake bzip2 cmake make gcc-c++ gcc gnutls-devel libconfig-devel libcurl-devel libdaemon-devel libev-devel libtool libuuid-devel lz4-devel openssl openssl-devel pcre-devel perl sqlite-devel zlib-devel patch
备注:需要保证gcc-c++版本足够新,不然编译有错。
$ yum install perl-DBD-MySQL -y ==>使用yum安装时用到了整个依赖包,这里也一起装了。
# 注意:【坑坑坑】
## openssl需要3.x过低的版本会安装失败openssl安装参考:[OpenSSL 3.x 安装](#OpenSSL 3.x 安装)
注意调整:
bash
# 修改以下位置的Makefile文件调整其GIT_VERSION := $(shell git describe --long --abbrev=7)配置为硬编码版本号,如:GIT_VERSION=2.4.8
lib/Makefile
src/Makefile
Makefile编译安装
bash
$ make
$ make install给相关目录和文件授权
bash
$ chmod 777 /etc/proxysql.cnf
$ chmod 777 /var/lib/proxysql错误:
bash[ERROR] Unable to open config file /etc/proxysql.cnf specified in the command line. Aborting! # 解决 chmod 777 /etc/proxysql.cnfbash[INFO] No SSL keys/certificates found in datadir (/var/lib/proxysql). Generating new keys/certificates. proxy_tls.cpp:150:write_rsa_key(): [ERROR] Error on BIO_new_file Can't open PID file /var/lib/proxysql/proxysql.pid (yet?) after start: No such file or directory # 解决 chmod 777 /var/lib/proxysql
启动ProxySQL
bash
$ systemctl start proxysql状态查看
bash[root@iZ2vchdoid8iirggyd1m54Z ~]# systemctl status proxysql ● proxysql.service - High Performance Advanced Proxy for MySQL Loaded: loaded (/usr/lib/systemd/system/proxysql.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2024-07-15 17:04:56 CST; 17min ago Process: 298209 ExecStart=/usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf $PROXYSQL_OPTS (code=exited, status=0/SUCCESS) Main PID: 298215 (proxysql) Tasks: 25 (limit: 38978) Memory: 34.8M CGroup: /system.slice/proxysql.service ├─298215 /usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf └─298216 /usr/bin/proxysql --idle-threads -c /etc/proxysql.cnf 7月 15 17:04:56 iZ2vchdoid8iirggyd1m54Z systemd[1]: Starting High Performance Advanced Proxy for MySQL... 7月 15 17:04:56 iZ2vchdoid8iirggyd1m54Z proxysql[298209]: 2024-07-15 17:04:56 [INFO] Using jemalloc with MALLOC_CONF: config.xmalloc:1, lg_tcache_max:16, opt.prof_accum:1, opt.prof_leak:1, opt.lg_prof_sample:20, opt.lg_prof_interval:30, rc:0 7月 15 17:04:56 iZ2vchdoid8iirggyd1m54Z proxysql[298209]: 2024-07-15 17:04:56 [INFO] Using config file /etc/proxysql.cnf 7月 15 17:04:56 iZ2vchdoid8iirggyd1m54Z proxysql[298209]: 2024-07-15 17:04:56 [INFO] Current RLIMIT_NOFILE: 102400 7月 15 17:04:56 iZ2vchdoid8iirggyd1m54Z proxysql[298209]: 2024-07-15 17:04:56 [INFO] Using OpenSSL version: OpenSSL 3.2.1 30 Jan 2024 7月 15 17:04:56 iZ2vchdoid8iirggyd1m54Z proxysql[298209]: 2024-07-15 17:04:56 [INFO] No SSL keys/certificates found in datadir (/var/lib/proxysql). Generating new keys/certificates. 7月 15 17:04:56 iZ2vchdoid8iirggyd1m54Z systemd[1]: Started High Performance Advanced Proxy for MySQL.
OpenSSL 3.x 安装
https://www.openssl.org/source/
系统自带的 OpenSSL 版本时间比较早,即使更新软件也还是老版本,如果老版本不能使用、并且无法通过yum更新的话,那就只能编译安装了。
在安装新版本之前,需要卸载旧版本
bash
$ yum remove openssl下载最新版
bash
$ wget https://www.openssl.org/source/openssl-3.3.1.tar.gz依赖安装
bash
$ yum install -y gcc gcc-c++ zlib-devel libtool autoconf automake perl perl-IPC-Cmd perl-Data-Dumper perl-CPAN解压下载的源码包
bash
$ tar -zxvf openssl-3.3.1.tar.gz进入解压后的目录
bash
$ cd openssl-3.3.1配置安装选项
运行config脚本来配置安装选项,设置安装目录为/usr/local/openssl-3.3.1
bash
$ ./config --prefix=/usr/local/openssl-3.3.1 shared zlib-dynamic enable-ec_nistp_64_gcc_128
# 根据需要取
$ ./config shared zlib --prefix=/usr/local/openssl运行make命令来编译安装OpenSSL
bash
$ make && make install_sw
# 根据需要取
$ make && make install安装完成之后,生成了新的执行文件,需要创建一个新的软链接指向新安装的 OpenSSL
bash
# 备份原来的openssl目录
$ mv /usr/bin/openssl /usr/bin/openssl-old
# 创建软连接
$ ln -s /usr/local/openssl-3.3.1/lib/libcrypto.so.3 /usr/lib64/libcrypto.so.3
$ ln -s /usr/local/openssl-3.3.1/lib/libssl.so.3 /usr/lib64/libssl.so.3
$ ln -s /usr/local/openssl-3.3.1/bin/openssl /usr/bin/openssl
$ ln -s /usr/local/openssl-3.3.1/include/openssl /usr/include/openssl配置环境变量
为了使系统能够在全局范围内访问openssl命令,需要更新PATH环境变量。编辑 ~/.bashrc 或 ~/.bash_profile 文件,在文件末尾添加环境变量。
bash
$ vi ~/.bash_profile
export PATH=$PATH:/usr/local/openssl-3.3.1/bin保存文件后,刷新环境变量使其立即生效:
bash
$ source ~/.bash_profile验证
运行命令验证新安装的OpenSSL版本
bash
$ openssl version