mysql - 通过 Hibernate 将 webapp 连接到 docker mysql 容器的巨大延迟

标签 mysql tomcat docker web-applications

我正在尝试将我在 Windows 上创建的 Web 应用程序(使用 Hibernate、XAMPP for Apache tomcat 和 mysql 服务器)移植到 Linux(使用 Docker)。

在我完成以下步骤后,我的 web.app 的第一个功能是登录/注册表单:在 Windows 上一切正常,但容器有大约几十分钟的延迟..有时还有 500 http 错误!!

  1. docker run -d --name mysql-phpmyadmin -p 127.0.0.1:8686:80 -p 127.0.0.1:3306:3306 grzesiekb/mysql-phpmyadmin

  2. docker run -d -p 8484:8080 -p 8007:8009 --name tomcat8-linked --link mysql-phpmyadmin:mysqlphp tomcat:8.0-jre8 然后部署下webapps/文件夹我的warfile

  3. 在我的hibernate.cfg.xml中,你可以看到它here (我无法以可见的方式粘贴它):)

  4. 在我的mysql容器my.cnf中有:

[client] port = 3306 socket = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
#
# * Fine Tuning
#
key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
general_log_file        = /var/log/mysql/mysql.log
general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#slow_query_log_file = /var/log/mysql/mysql-slow.log
#slow_query_log      = 1
#long_query_time = 2
#log_queries_not_using_indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name

# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem


[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer              = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
  1. 默认情况下,这个 mysql 容器只允许来自本地主机的连接:为了允许来自任何地方的连接,我已经做到了:

    授予 上的所有特权。 给“root”@“%”,通过“密码”标识并授予选项; 刷新权限;

然后我通过 phpmyadmin 导入了我的 dql 转储

描述您收到的结果:

巨大的延迟,与我不知道哪个问题有关,并且以随机方式无法连接到mysql。没有日志。老师说可能是Docker网络的DNS问题。

描述您预期的结果:

立即连接到数据库,就像在 Windows 中使用 XAMPP 一样

最佳答案

您应该尝试使您的设置尽可能标准,以避免由于非标准做法而导致的错误。

关于mysql - 通过 Hibernate 将 webapp 连接到 docker mysql 容器的巨大延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42413404/

相关文章:

mysql - (MySQL) 使用在更新查询中计算的值更新多行

docker - 与Windows容器一样通过IP连接到Linux容器

docker - 如何暴露mysql端口?

mysql - 根据 2 个条件从多个 MySQL 表中获取最新记录

php - 如何乘以所有行 MySQL 和 PHP

apache - 在 Windows 框中使用 tomcat 托管 Solr 5.3

Spring 数据 mongodb :Error creating bean

java - 以前工作的 Java servlet 现在在 'Clean' 之后不再工作 - Tomcat v7.0 和 Eclipse

docker - Dockerfile 中的 VOLUME 是否在 kubernetes 中持久存在

php - 需要帮助来构造一个具有特定结果+随机结果的查询