halo-dev / halo

强大易用的开源建站工具。
https://www.halo.run
GNU General Public License v3.0
33.32k stars 9.61k forks source link

建议为Mysql数据库启用unix sock连接 #1849

Closed wangxiaoerYah closed 1 year ago

wangxiaoerYah commented 2 years ago

你当前使用的版本

1.5.2

描述一下此特性

数据库直接通过unix sock连接, 减少回环连接, 数据库也可以only listen sock, 增加安全性

附加信息

No response

ruibaby commented 2 years ago

/good-first-issue /kind feature

f2c-ci-robot[bot] commented 2 years ago

@ruibaby: This request has been marked as suitable for new contributors.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-good-first-issue command.

In response to [this](https://github.com/halo-dev/halo/issues/1849): >/good-first-issue >/kind feature Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
JohnNiang commented 2 years ago

非常棒的建议。不过可以提供更多的文档链接,让大家更容易去完成这个改进。

wangxiaoerYah commented 2 years ago

非常棒的建议。不过可以提供更多的文档链接,让大家更容易去完成这个改进。

应该是要实现这个类,SocketFactory

SocketFactory

stackoverflow

wangxiaoerYah commented 2 years ago

非常棒的建议。不过可以提供更多的文档链接,让大家更容易去完成这个改进。

stackoverflow 提到mysql的jdbc驱动好像不支持unix。 但是mariadb的jdbc驱动同时兼容mysql/mariadb 支持unix连接 _

The JDBC Driver from the MariaDB project supports Unix domain sockets while remaining compatible with the MySQL Connector/J JDBC driver. Example jdbc url for the MariaDB driver is: jdbc:mariadb://localhost:3306/revmgt?localSocket=/var/run/mysqld/mysqld.sock

Worth noting that this requires including the JNA library as the MariaDB driver uses domain sockets via JNA internally. I saw speed improvements for CPU bound java processes when using the unix domain sockets. I believe this was largely from the offload of work from the java process to native code freeing up CPU cycles for the already CPU bottle necked java process.

_

Yhcrown commented 2 years ago

使用unix sock需要服务器和数据库在一起,貌似这种情况直接使用H2好一点? 我查了下有个junixsocket包,实现了用以jdbc连接unixsock的socketfactory及其他一些支持。不过目前好像没有springboot默认连接池hikaricp有关支持unixsocket的相关资料。如果简单的配置个使用unixsocket的数据源倒是可以正常使用,但是就失去了使用连接池的优势了。不知道还有没有用以实现这个能够参考的相关资料。