升级PHP版本导致WordPress无法显示文章,而是显示“有点尴尬诶!该页无法显示。”的解决方法

我的WordPress版本是5.4.15,当我把服务器系统里的PHP 7.2升级到PHP 8.2后,通过浏览器访问WordPress网站,无法显示文章,而是显示“有点尴尬诶!该页无法显示。”这句话。

经测试,PHP可以正常连接到MySQL数据库。

原因应该是WordPress 5.4.15用到的某些PHP函数在PHP 8.2过时了。

升级WordPress到最新版本解决了这个问题。

PHP Warning: Module ‘curl‘ already loaded in Unknown on line 0警告的解决方法

如果在执行PHP相关命令时,看到一条警告消息:

PHP Warning: Module ‘curl‘ already loaded in Unknown on line 0

那是由于curl模块已经被PHP标准库内建了,如果在/etc/php/8.2/fpm/php.ini和/etc/php/8.2/fpm/conf.d/20-curl.ini两处配置文件里又启用了curl扩展,就会报这个警告。

解决方法是在这两个配置文件中都不启用curl扩展,就是使用;号注释掉extension=curl.so这行。修改了配置文件记得重启php-fpm服务,最后只要在php -m命令的输出中看到curl了,就说明已启用curl扩展。

多个Elasticsearch节点无法组成集群,报错master_not_discovered_exception或NotMasterException的原因和解决方法

多个Elasticsearch节点无法自动组成集群,查看日志发现错误信息:“master_not_discovered_exception”。

原因是运维人员通过克隆虚拟机来获得多台Elasticsearch服务器,这样每个Elasticsearch节点都具有相同的节点ID,因此在组成集群时,无法选举出master节点。

这可以通过以下命令进行验证,列出所有节点ID:

GET /_cat/nodes?v&h=id,ip,name&full_id=true

请注意,由于Elasticsearch集群尚未形成,因此需要单独查询每个节点,即: 

curl 192.168.110.111:9200/_cat/nodes?v&h=id,ip,name&full_id=true
curl 192.168.110.112:9200/_cat/nodes?v&h=id,ip,name&full_id=true
......

Elasticsearch节点ID必须是唯一的。要解决这个问题,我们需要删除每个节点上的索引(RPM方式安装的Elasticsearch的索引数据默认位于/var/lib/elasticsearch)。重启Elasticsearch就会重置节点ID。 

参考

https://www.656463.com/wenda/jdbhjrjqNotMasterExceptionqgddxc_359

Linux系统执行sudo node和sudo npm报错找不到命令的解决方法

从官网下载Node.js二进制包,在Linux操作系统里解压安装后,在用户(非root用户)的家目录下的.bashrc文件里,把可执行文件node所在目录(也是npm所在目录)的路径加入PATH环境变量,例如:

export PATH=$PATH:/opt/nodejs/latest/bin

保存后source一下.bashrc文件,让里面的配置生效:

$ source ~/.bashrc

然后即可直接执行node和npm程序,例如:

$ node -v
v16.20.0
$ npm -v
8.19.4

但是执行sudo node xxx和sudo npm xxx还是报错找不到命令:

$ sudo node -v
sudo: node: command not found

解决办法是为node和npm创建符号链接到/usr/bin/目录:

# 先分别打印输出node和npm的绝对路径看看
$ which node
/opt/nodejs/latest/bin/node
$ which npm
/opt/nodejs/latest/bin/npm
# 创建符号链接
$ sudo ln -s /opt/nodejs/latest/bin/node /usr/bin/node
$ sudo ln -s /opt/nodejs/latest/bin/npm /usr/bin/npm

然后执行sudo node xxx和sudo npm xxx就不会报错找不到命令了:

$ sudo node -v
v16.20.0
$ sudo npm -v
8.19.4

Server sent charset (255) unknown to the client. Please, report to the developers的解决方法

MySQL 8将默认字符集更改为utf8mb4。但是有些客户端不知道这个字符集。因此,当服务器向客户端报告其默认字符集,而客户端不知道其含义时,就会抛出此错误。

该错误针对C++实现的MySQL Connector,因此它影响的不仅仅是PHP。

正确的解决方案是升级你的客户端,但与此同时我通过将服务器的字符集更改为utf8来使其正常工作,以与未升级的客户端兼容。我将以下配置添加到/etc/my.cnf并重新启动mysqld:

[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

参考

https://stackoverflow.com/questions/43437490/pdo-construct-server-sent-charset-255-unknown-to-the-client-please-rep

https://bugs.mysql.com/bug.php?id=71606

SpringBoot运行单元时测试报错:java.lang.IllegalStateException Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or…

错误描述

SpringBoot运行单元测试时报错:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=…) with your test

我的软件环境

JDK 11.0

SpringBoot 2.7

Maven 3.8.7

出错原因

src/test/java目录下的包结构和src/main/java目录下的包结构应该一样,否则就会报上述错误。

我的src/main/java目录下的包是com.comp.example,但是src/test/java目录下的包是com.sample.example,两者不一样,因此报上述错误。

解决方法

把src/test/java目录下的包结构和src/main/java目录下的包结构改成一样即可。

参考

https://stackoverflow.com/questions/47487609/unable-to-find-a-springbootconfiguration-you-need-to-use-contextconfiguration

JDBC连接MySQL数据库警告:Establishing SSL connection without server’s identity verification is not recommend

JDBC连接MySQL出现如下警告:

Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

原因是高版本MySQL需要指明是否进行SSL连接。

解决方法是在JDBC连接MySQL的URL字符串中加入useSSL=true或者useSSL=false即可,例如:

jdbc:mysql://127.0.0.1:3306/framework?serverTimezone=UTC&characterEncoding=utf8&useSSL=false

如果你的连接确实没有暴露给网络(仅限本地主机),或者你在没有真实数据的非生产环境中工作,那么可以肯定的是:通过包含选项useSSL=false来禁用SSL没有坏处。

如果要使用useSSL=true,需要以下一组选项才能使SSL使用证书、主机验证并禁用弱协议选项:

  • useSSL=true
  • sslMode=VERIFY_IDENTITY
  • trustCertificateKeyStoreUrl=file:path_to_keystore
  • trustCertificateKeyStorePassword=password
  • enabledTLSProtocols=TLSv1.2

因此,作为一个示例,让我们假设你希望使用SSL将其中一种Atlassian产品(Jira、Confluence、Bamboo等)连接到MySQL服务器,你需要执行以下主要步骤:

  • 首先,确保你有一个为MySQL服务器主机生成的有效的SSL/TLS证书,并且CA证书安装在客户端主机上(如果你使用自签名,那么你可能需要手动执行此操作,但对于流行的公共CA,它已经在那里了)。
  • 接下来,确保java密钥库包含所有CA证书。在Debian/Ubuntu上,这是通过运行以下命令来实现的:
update-ca-certificates -f
chmod 644 /etc/ssl/certs/java/cacerts
  • 最后,更新Atlassian产品使用的连接字符串以包含所有必需的选项,这在Debian/Ubuntu上类似于:
jdbc:mysql://mysql_server/confluence?useSSL=true&sslMode=VERIFY_IDENTITY&trustCertificateKeyStoreUrl=file%3A%2Fetc%2Fssl%2Fcerts%2Fjava%2Fcacerts&trustCertificateKeyStorePassword=changeit&enabledTLSProtocols=TLSv1.2&useUnicode=true&characterEncoding=utf8

更多相关信息请参见MySQL官方文档https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-using-ssl.html

参考

https://beansandanicechianti.blogspot.com/2019/11/mysql-ssl-configuration.html

CentOS7 yum安装MySql报错The GPG keys listed for the MySQL 8.0 Community Server repository are already installed but they are not correct for this package.的解决方法

在CentOS7中使用yum安装MySql8的时候,遇到这个问题。

原因是,MySQL GPG密钥已过期,无法从官方存储库安装或升级MySQL包。其他详细信息也可以在MySQL网站上找到:https://bugs.mysql.com/bug.php?id=106188

解决方法是,在运行安装程序之前导入密钥:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

对于Ubuntu系统:

wget -q -O - https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 | apt-key add -

参考

https://support.cpanel.net/hc/en-us/articles/4419382481815

https://forums.cpanel.net/threads/mysql-upgrade-process-failed-the-gpg-keys-listed-for-the-mysql-8-0-community-server-repository-are-already-installed-but-they-are-not-correct-for.697213/