Kubernetes和外部MySQL服务器内部的通讯Wordpress。 -MySQL连接错误:(2002)

问题描述 投票:0回答:1

在Azure云中,我具有以下基础结构:

具有两个子网的Vnet。

  • Vnet:10.0.0.0/8
    • aks子网:10.240.0.0/16
    • 持久性子网:10.241.0.0/27

已安装Azure Kubernetes集群并将其与aks-subnet关联。

persistence-subnet中,已部署了托管的[[Azure MySQL数据库 paas,并将其关联。

persistence-subnet有两个服务端点:Microsoft.SqlMicrosoft.Storage

aks-subnet具有Microsoft.Sql服务端点

Azure Kubernetes群集是使用Azure CNI网络配置文件部署的,因此,每个Pod都将获得一个属于aks-subnet的IP地址。我还决定选择Azure CNI,因为我需要将aks-subnet中的pod与MySQL托管服务进行通信。

在托管的

Azure MySQL数据库

paas服务中,我已将aks-subnet IP地址范围列入白名单,以便允许aks-subnet内部的Pod访问MySQL服务。"StartIpAddress": "10.240.0.0", "EndIpAddress": "10.240.255.255"
在AKS群集中,我正在使用helm3通过此命令来部署Wordpress掌舵图表

helm3 install wordpress-site-1 stable/wordpress --set image.registry=myregistry.azurecr.io,image.repository=wordpress,image.tag=5.2.4,image.pullPolicy=Always,wordpressUsername=site1,wordpressPassword=my-password,[email protected],mariadb.enabled=false,externalDatabase.host=database-db.mysql.database.azure.com,externalDatabase.user=user@wdatabase-db,externalDatabase.password=my-password,externalDatabase.database=wordpress-site-1,externalDatabase.port=3306 NAME: wordpress-site-1 LAST DEPLOYED: Tue Oct 29 13:24:03 2019 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: 1. Get the WordPress URL: NOTE: It may take a few minutes for the LoadBalancer IP to be available. Watch the status with: 'kubectl get svc --namespace default -w wordpress-site-1' export SERVICE_IP=$(kubectl get svc --namespace default wordpress-site-1 --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}") echo "WordPress URL: http://$SERVICE_IP/" echo "WordPress Admin URL: http://$SERVICE_IP/admin" 2. Login with the following credentials to see your blog echo Username: site1 echo Password: $(kubectl get secret --namespace default wordpress-site-1 -o jsonpath="{.data.wordpress-password}" | base64 --decode)

该部署正在运行,但是当我检查wordpress pod日志时,收到此错误消息:

MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known [29-Oct-2019 13:01:13 UTC] PHP Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22 [29-Oct-2019 13:01:13 UTC] PHP Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in Standard input code on line 22 MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known WARNING: unable to establish a database connection to 'mysql' continuing anyways (which might have unexpected results) AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.240.0.36. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.240.0.36. Set the 'ServerName' directive globally to suppress this message [Tue Oct 29 13:01:14.027023 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.11 configured -- resuming normal operations [Tue Oct 29 13:01:14.027099 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 10.240.0.4 - - [29/Oct/2019:13:01:22 +0000] "GET /wp-login.php HTTP/1.1" 500 3003 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:13:01:32 +0000] "GET /wp-login.php HTTP/1.1" 500 3003 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:13:01:42 +0000] "GET /wp-login.php HTTP/1.1" 500 3003 "-" "kube-probe/1.14"

看起来像位于aks-subnet内的wordpress pod无法访问位于persistence-subnet的MySQL服务,尽管我通过helm install command提供了正确的参数。

这很奇怪,豆荚可以访问Internet,而且我一直在仔细检查允许该通信的规则和权限。

我有不知道的东西吗?

如何从部署在Aks群集中的Wordpress服务访问MySQL数据库?


UPDATE:

在使用helm install命令部署Wordpress之前,我已经以手动方式创建了指向Azure容器注册表数据的docker注册表秘密:

kubectl create secret docker-registry regcred --docker-server=my-registry.azurecr.io --docker-username=my-username --docker-password=my-password [email protected]

[我在regcred的本地掌舵图中引用了deployment.yaml,并且我使用helm install命令部署了Wordpress,并且看起来像是可行的,或者至少MySQL不会引起问题。 

只是ServerName Apache指令,因为我尚未将我的deploymnet进程涉及任何主机名。

⟩ kubectl logs pod/wordpress-site-1-7f44b567d6-2949w -f WordPress not found in /var/www/html - copying now... Complete! WordPress has been successfully copied to /var/www/html ### APACHE SERVERNAME WARNING AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.240.0.103. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.240.0.103. Set the 'ServerName' directive globally to suppress this message ##### [Tue Oct 29 16:13:16.327549 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.11 configured -- resuming normal operations [Tue Oct 29 16:13:16.327630 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 10.240.0.4 - - [29/Oct/2019:16:13:18 +0000] "GET / HTTP/1.1" 302 255 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:18 +0000] "GET /wp-admin/setup-config.php HTTP/1.1" 200 4289 "http://10.240.0.103:80/" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:28 +0000] "GET / HTTP/1.1" 302 255 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:28 +0000] "GET /wp-admin/setup-config.php HTTP/1.1" 200 4289 "http://10.240.0.103:80/" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:38 +0000] "GET / HTTP/1.1" 302 255 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:40 +0000] "GET / HTTP/1.1" 302 255 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:40 +0000] "GET /wp-admin/setup-config.php HTTP/1.1" 200 4289 "http://10.240.0.103:80/" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:38 +0000] "GET /wp-admin/setup-config.php HTTP/1.1" 200 4289 "http://10.240.0.103:80/" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:48 +0000] "GET / HTTP/1.1" 302 255 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:50 +0000] "GET / HTTP/1.1" 302 255 "-" "kube-probe/1.14" 10.240.0.4 - - [29/Oct/2019:16:13:50 +0000] "GET /wp-admin/setup-config.php HTTP/1.1" 200 4289 "http://10.240.0.103:80/" "kube-probe/1.14"

我知道,此时数据库不会发生任何事情,因为我们需要通过Web访问Wordpress网站并部署该网站,那么此时创建数据库表的时间正确吗? 

所以我从kubernetes进行了port-forward操作:

⟩ kubectl port-forward pod/wordpress-site-1-7f44b567d6-2949w 8002:80 Forwarding from 127.0.0.1:8002 -> 80 Forwarding from [::1]:8002 -> 80 Handling connection for 8002 Handling connection for 8002 Handling connection for 8002 Handling connection for 8002 Handling connection for 8002

[当我转到http://localhost:8002/时,浏览器将我重定向到http://localhost:8002/wp-admin/setup-config.php,我可以看到wordpress向导。

所以我用先前在数据库服务器中创建的数据库名称填充数据

enter image description here

并且当我在向导UI中提交数据时,我得到了以下内容:

enter image description here

数据连接的消息参考问题

This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at wordpresssentiaassessment-db.mysql.database.azure.com. This could mean your host’s database server is down. Are you sure you have the correct username and password? Are you sure that you have typed the correct hostname? Are you sure that the database server is running?

但是也许由于端口转发操作,我们无法从本地计算机联系数据库? 

我的意思是,该过程无法进行反向端口转发以联系数据库?

我是否需要将Wordpress服务应用程序公开到某个域和IP公共地址才能联系数据库并安装Wordpresss?

因此,我进入吊舱WordPress容器以检查wp-config.php

⟩ kubectl exec -it pod/wordpress-site-1-7f44b567d6-2949w /bin/sh

但是wp-config.php文件不存在,

# ls index.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php license.txt wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php # cat wp-config.php cat: wp-config.php: No such file or directory

我有一个wp-config-sample.php,这是他们的内容,但是我看不到有关FQDN的任何信息。

或者也许我需要在wp-config.php中做一些事情,也许将wp-config-sample.php重命名为wp-config.php并在该文件中添加注入到pod中的变量?

# nano wp-config-sample.php <?php /** * The base configuration for WordPress * * The wp-config.php creation script uses this file during the * installation. You don't have to use the web site, you can * copy this file to "wp-config.php" and fill in the values. * * This file contains the following configurations: * * * MySQL settings * * Secret keys * * Database table prefix * * ABSPATH * * @link https://codex.wordpress.org/Editing_wp-config.php * * @package WordPress */ // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'database_name_here' ); /** MySQL database username */ define( 'DB_USER', 'username_here' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password_here' ); /** MySQL hostname */ define( 'DB_HOST', 'localhost' ); /** Database Charset to use in creating database tables. */ define( 'DB_CHARSET', 'utf8' ); /** The Database Collate type. Don't change this if in doubt. */ define( 'DB_COLLATE', '' ); /**#@+ * Authentication Unique Keys and Salts. * * Change these to different unique phrases! * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. * * @since 2.6.0 */ define( 'AUTH_KEY', 'put your unique phrase here' ); define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); define( 'NONCE_KEY', 'put your unique phrase here' ); define( 'AUTH_SALT', 'put your unique phrase here' ); define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); define( 'NONCE_SALT', 'put your unique phrase here' ); /**#@-*/ /** * WordPress Database Table prefix. * * You can have multiple installations in one database if you give each * a unique prefix. Only numbers, letters, and underscores please! */ $table_prefix = 'wp_'; /** * For developers: WordPress debugging mode. * * Change this to true to enable the display of notices during development. * It is strongly recommended that plugin and theme developers use WP_DEBUG * in their development environments. * * For information on other constants that can be used for debugging, * visit the Codex. * * @link https://codex.wordpress.org/Debugging_in_WordPress */ define( 'WP_DEBUG', false ); /* That's all, stop editing! Happy publishing. */ /** Absolute path to the WordPress directory. */ if ( ! defined( 'ABSPATH' ) ) { define( 'ABSPATH', dirname( __FILE__ ) . '/' ); } /** Sets up WordPress vars and included files. */ require_once( ABSPATH . 'wp-settings.php' );

mysql wordpress azure kubernetes-helm vnet
1个回答
1
投票
似乎该应用程序试图对您指定的IP地址执行反向查找,可能是因为它打算使用SSL来认证远程服务器。用于内部IP地址的标准配置将不提供帮助反向查找的PTR记录。

尝试为您的MySQL实例使用FQDN而不是IP地址。

它应该看起来像这样:

{yourservername}.mysql.database.azure.com

这样,您的应用程序将不需要执行反向查找,Azure将适当地满足路由选择。

编辑:

以下行表示您的应用程序正在尝试连接到主机'mysql':

警告:无法建立与'mysql'的数据库连接

检查FQDN是否已在wp-config.php中正确填充

© www.soinside.com 2019 - 2024. All rights reserved.