后台经常性报500错误

bug问题 · cebook · 于 17天前 发布 · 135 次阅读

部署好了fecshop以后,进入后台,经常性的报500错误。 读取数据的时候,多点击几次就好了,写入数据的时候必然报这个错误,看了下数据库的配置也是对的,求解决。

具体错误如下: Http status: 500 Internal Server Error ajaxOptions: error thrownError: Internal Server Error Exception (Database Exception) 'yii\db\Exception' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'yii2_fecshop_docker_php_1.yii2fecshopdocker_code-network' (using password: YES)'

in /www/web/fecshop/vendor/yiisoft/yii2/db/Connection.php:624

Stack trace: #0 /www/web/fecshop/vendor/yiisoft/yii2/db/Connection.php(996): yii\db\Connection->open() #1 /www/web/fecshop/vendor/yiisoft/yii2/db/Connection.php(983): yii\db\Connection->getMasterPdo() #2 /www/web/fecshop/vendor/yiisoft/yii2/db/Command.php(253): yii\db\Connection->getSlavePdo() #3 /www/web/fecshop/vendor/yiisoft/yii2/db/Command.php(1153): yii\db\Command->prepare(true) #4 /www/web/fecshop/vendor/yiisoft/yii2/db/Command.php(399): yii\db\Command->queryInternal('fetchAll', NULL) #5 /www/web/fecshop/vendor/yiisoft/yii2/db/mysql/Schema.php(319): yii\db\Command->queryAll() #6 /www/web/fecshop/vendor/yiisoft/yii2/db/mysql/Schema.php(125): yii\db\mysql\Schema->findColumns(Object(yii\db\TableSchema)) #7 /www/web/fecshop/vendor/yiisoft/yii2/db/Schema.php(744): yii\db\mysql\Schema->loadTableSchema('admin_user') #8 /www/web/fecshop/vendor/yiisoft/yii2/db/Schema.php(194): yii\db\Schema->getTableMetadata('{{%admin_user}}', 'schema', false) #9 /www/web/fecshop/vendor/yiisoft/yii2/db/ActiveRecord.php(435): yii\db\Schema->getTableSchema('{{%admin_user}}') #10 /www/web/fecshop/vendor/yiisoft/yii2/db/ActiveRecord.php(262): yii\db\ActiveRecord::getTableSchema() #11 /www/web/fecshop/vendor/yiisoft/yii2/db/ActiveRecord.php(234): yii\db\ActiveRecord::filterValidColumnNames(Object(yii\db\Connection), Array) #12 /www/web/fecshop/vendor/yiisoft/yii2/db/ActiveRecord.php(191): yii\db\ActiveRecord::filterCondition(Array, Array) #13 /www/web/fecshop/vendor/yiisoft/yii2/db/BaseActiveRecord.php(112): yii\db\ActiveRecord::findByCondition(Array) #14 /www/web/fecshop/vendor/fancyecommerce/fecshop/models/mysqldb/AdminUser.php(85): yii\db\BaseActiveRecord::findOne(Array) #15 /www/web/fecshop/vendor/yiisoft/yii2/web/User.php(690): fecshop\models\mysqldb\AdminUser::findIdentity(2) #16 /www/web/fecshop/vendor/yiisoft/yii2/web/User.php(192): yii\web\User->renewAuthStatus() #17 /www/web/fecshop/vendor/yiisoft/yii2/web/User.php(360): yii\web\User->getIdentity() #18 /www/web/fecshop/vendor/yiisoft/yii2/base/Component.php(139): yii\web\User->getIsGuest() #19 /www/web/fecshop/vendor/yiisoft/yii2-debug/src/panels/UserPanel.php(79): yii\base\Component->get('isGuest') #20 /www/web/fecshop/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\debug\panels\UserPanel->init() #21 [internal function]: yii\base\BaseObject->construct(Array) #22 /www/web/fecshop/vendor/yiisoft/yii2/di/Container.php(384): ReflectionClass->newInstanceArgs(Array) #23 /www/web/fecshop/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('yii\debug\panel...', Array, Array) #24 /www/web/fecshop/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->get('yii\debug\panel...', Array, Array) #25 /www/web/fecshop/vendor/yiisoft/yii2-debug/src/Module.php(182): yii\BaseYii::createObject(Array) #26 /www/web/fecshop/vendor/yiisoft/yii2-debug/src/Module.php(154): yii\debug\Module->initPanels() #27 /www/web/fecshop/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\debug\Module->init() #28 /www/web/fecshop/vendor/yiisoft/yii2/base/Module.php(158): yii\base\BaseObject->construct(Array) #29 [internal function]: yii\base\Module->construct('debug', Object(yii\web\Application), Array) #30 /www/web/fecshop/vendor/yiisoft/yii2/di/Container.php(376): ReflectionClass->newInstanceArgs(Array) #31 /www/web/fecshop/vendor/yiisoft/yii2/di/Container.php(156): yii\di\Container->build('yii\debug\Modul...', Array, Array) #32 /www/web/fecshop/vendor/yiisoft/yii2/BaseYii.php(345): yii\di\Container->get('yii\debug\Modul...', Array) #33 /www/web/fecshop/vendor/yiisoft/yii2/base/Module.php(427): yii\BaseYii::createObject('yii\debug\Modul...', Array) #34 /www/web/fecshop/vendor/yiisoft/yii2/base/Application.php(315): yii\base\Module->getModule('debug') #35 /www/web/fecshop/vendor/yiisoft/yii2/web/Application.php(69): yii\base\Application->bootstrap() #36 /www/web/fecshop/vendor/yiisoft/yii2/base/Application.php(273): yii\web\Application->bootstrap() #37 /www/web/fecshop/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\base\Application->init() #38 /www/web/fecshop/vendor/yiisoft/yii2/base/Application.php(206): yii\base\BaseObject->construct(Array) #39 /www/web/fecshop/appadmin/web/index.php(76): yii\base\Application->construct(Array) #40 {main}

共收到 7 条回复
Fecshop#117天前 0 个赞

google搜索了一下 mysql Access denied for user 'root'

造成这个好像是ip的问题

你是按照docker文档安装的吗?

发一下你的docker根目录下的 docker-compose.yml文件以及 app/fecshop/common/config/main-local.php看一下

cebook#217天前 0 个赞

docker-compose.yml文件内容 version: "2"
services:
web:

image: registry.cn-hangzhou.aliyuncs.com/fecshopsoft/nginx  
ports:  
  - "80:80" 
restart: always
volumes:  
  - ./app:/www/web
  - ./services/web/nginx/conf:/etc/nginx
  - ./services/web/nginx/logs:/www/web_logs
networks:
    - code-network
depends_on:
  - php

mysql:

image: registry.cn-hangzhou.aliyuncs.com/fecshopsoft/mysql 
restart: always
volumes:  
  - ./db/mysql/data:/var/lib/mysql 
  - ./db/mysql/example_db:/var/example_db 
  - ./db/mysql/conf.d:/etc/mysql/conf.d      
restart: always
environment:
  - MYSQL_ROOT_PASSWORD=*****
  - MYSQL_DATABASE=fecshop
networks:
  - code-network 

php:

image: registry.cn-hangzhou.aliyuncs.com/fecshopsoft/php-7.1.13-fpm_2
restart: always
volumes:  
  - ./app:/www/web
  - ./services/php/etc/php7.1.13.ini:/usr/local/etc/php/conf.d/php7.1.13.ini
depends_on:
  - mongodb
  - mysql
networks:
    - code-network  

mongodb:

image: registry.cn-hangzhou.aliyuncs.com/fecshopsoft/mongo
restart: always
environment:
  - MONGO_DATA_DIR=/data/db
  - MONGO_LOG_DIR=/data/logs
volumes:
  - ./db/mongodb/data:/data/db
  - ./db/mongodb/example_db:/data/example_db
  - ./db/mongodb/logs:/data/logs
networks:
  - code-network 

xunsearch:

image: registry.cn-hangzhou.aliyuncs.com/fecshopsoft/xunsearch
restart: always
volumes:
  - ./db/xunsearch/data:/usr/local/xunsearch/data  
networks:
  - code-network 

redis:

image: registry.cn-hangzhou.aliyuncs.com/fecshopsoft/redis
restart: always
environment:
    REDIS_PASS_FILE: /run/secrets/redis-password
command: [
  "bash", "-c",
  '
   docker-entrypoint.sh
   --requirepass "$$(cat $$REDIS_PASS_FILE)"
  '
]
volumes:
  - ./db/redis/etc/redis.conf:/usr/local/etc/redis/redis.conf 
  - ./db/redis/data:/data 
  - ./db/redis/etc/redis-password:/run/secrets/redis-password 
networks:
  - code-network 

networks: code-network:

driver: bridge
    
    
    
    
    
cebook#317天前 0 个赞

app/fecshop/common/config/main-local.php内容:

<?php
return [
    'components' => [
        // Mysql部分的配置
        'db' => [ 
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=mysql;dbname=fecshop',
            'username' => 'root',
            'password' => '*****',
            'charset' => 'utf8',
        ],
        // Mongodb部分的配置
		'mongodb' => [
            'class' => 'yii\mongodb\Connection',
			# 有账户的配置
            //'dsn' => 'mongodb://fecshop:fecshop123@mongodb:27017/fecshop',
			# 无账户的配置
			'dsn' => 'mongodb://mongodb:27017/fecshop',
			# 复制集
			//'dsn' => 'mongodb://10.10.10.252:10001/erp,mongodb://10.10.10.252:10002/erp,mongodb://10.10.10.252:10004/erp?replicaSet=terry&readPreference=primaryPreferred',
        ],
		// Redis的配置
		'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'redis',    // redis的host
            'port' => 6379,               // redis的端口     
			'password'  => '*****', // redis的密码
            'database' => 0,    // redis的库,此处不要改动
        ],
        // Cache 组件的配置,您需要配置下面的redis
        'cache' => [
            'class'     => 'yii\redis\Cache',
            // 缓存配置独立的redis,您可以和上面的redis配置一致
            'redis' => [
                'hostname' => 'redis',   // redis的host
                'port' => 6379,              // redis的端口   
                'password'  => ''*****',', // redis的密码
            ],
        ],
        // Session 组件的配置,您需要配置下面的redis
        'session' => [
            'class'   => 'yii\redis\Session',
            // session过期时间,1天过期
            'timeout' => 86400 * 1, 
            // 缓存配置独立的redis,您可以和上面的redis配置一致
            'redis' => [
                'hostname' => 'redis', // redis的host
                'port' => 6379,            // redis的端口   
                'password'  => ''*****',', // redis的密码
            ],
        ],

    ],
];

cebook#417天前 0 个赞

我用的是Fecshop Docker 傻瓜版安装 https://github.com/fecshop/yii2_fecshop_docker_fool 按照这个地址下面的安装方法安装的。

Fecshop#517天前 0 个赞

通过远程,已解决,原因是docker的容器混乱,多个php容器,导致php连接mysql,在ip方面出现问题。

大致的解决步骤:

1.删除掉所有的容器,参看文章:http://www.fecshop.com/topic/1828

2.重新构建:https://github.com/fecshop/yii2_fecshop_docker_fool

cebook#617天前 0 个赞

多谢Terry老大,亲自帮我搞定了头疼的问题,为您的精神打Call。

successago#77天前 0 个赞

666,非常好

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics