Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Hibernate将webapp连接到docker mysql容器的延迟非常大_Mysql_Tomcat_Docker_Web Applications - Fatal编程技术网

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

通过Hibernate将webapp连接到docker mysql容器的延迟非常大,mysql,tomcat,docker,web-applications,Mysql,Tomcat,Docker,Web Applications,我正在尝试使用Hibernate、针对ApacheTomcat的XAMPP和mysql服务器将我在Windows上创建的web应用程序移植到Linux,使用Docker 完成以下步骤后,我的web.app的第一个功能是登录/注册表单:在Windows上,所有功能都可以正常工作,但使用容器时,延迟大约为几十分钟。。有时也会有500个http错误 docker run-d——名称mysql phpmyadmin-p 127.0.0.1:8686:80-p 127.0.0.1:3306:3306 gr

我正在尝试使用Hibernate、针对ApacheTomcat的XAMPP和mysql服务器将我在Windows上创建的web应用程序移植到Linux,使用Docker

完成以下步骤后,我的web.app的第一个功能是登录/注册表单:在Windows上,所有功能都可以正常工作,但使用容器时,延迟大约为几十分钟。。有时也会有500个http错误

  • docker run-d——名称mysql phpmyadmin-p 127.0.0.1:8686:80-p 127.0.0.1:3306:3306 grzesiekb/mysql phpmyadmin

  • docker run-d-p 8484:8080-p 8007:8009——名称tomcat8链接——链接mysql phpmyadmin:mysqlphp tomcat:8.0-jre8
    然后部署在webapps/文件夹my warfile下

  • 在我的hibernate.cfg.xml中,您可以看到它(我无法以可视方式粘贴它):)

  • 在my mysql容器my.cnf中有:

  • [客户] 端口=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/
    
  • 默认情况下,这个mysql容器只允许从localhost进行连接:为了允许从任何地方进行连接,我做了以下工作:

    授予在上的所有特权。使用GRANT选项发送到由“密码”标识的“根”@“%”; 同花顺特权

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

    描述您收到的结果:

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

    描述您期望的结果:


    立即连接到数据库,就像在使用XAMPP的Windows中一样,您应该尽量使您的设置成为标准设置,以避免由于非标准做法而导致的错误

    • 使用官方或至少流行的图像(数百万次拉取),而不是mysql phpmyadmin的100次拉取:

    • 我不知道为什么要用主机端口和容器端口声明ip,如果没有必要,可能不这样做,只发布主机端口和容器端口,而不是ip

    • 不要使用--link,因为它是,创建一个网桥网络并使用--network my bridge network运行每个容器

    • 使用适用于此LTS版本的最新可用“HWE”内核将Ubuntu升级到最新的LTS版本(16.04.2)(您必须使用单独的命令升级内核,如下所述:
      sudo apt get install--install建议xserver-xorg-HWE-16.04


    谢谢你的回答,Tristan。我尝试了这个新的mysql容器:docker run——命名一些mysql-e mysql\u ROOT\u PASSWORD=pass-p 3307:3306-d mysql然后这个是phpmyadmin:docker run:docker run——命名myadmin-d——链接一些mysql:mysql-p 8686:80 phpmyadmin/phpmyadmin我已经给了值“0.0.0.0”为了在mysql配置文件中绑定_地址,我创建了一个bridge docker网络,连接了tomcat和mysql容器;然后在hibernate.cfg.xml文件中,我指向:3306/at_db,用户为“root”,密码为“pass”。但问题仍然存在!我给了你4个建议,你遵循了前2个,你忽略了后2个。你正在接近,只是不要忽略任何。不要配置mysql配置,这个映像应该是预配置的。如果不清楚:不要忘了更新你的操作系统和内核,不要使用“-link”对于phpmyadmin,如果您在tomcat和mysql之间有一个“延迟”,那么您应该看到phpmyadmin和mysql之间有相同的延迟。