1、容器的基础镜像更换后,当 Rancher 环境变量,CHANNEL_PUB_API_CFG_MIGRATE=true 时,容器启动失败。报错:PHP Core Warning ‘yii/base/ErrorException’ with message ‘Module ‘gd’ already loaded’。如图1
chmod 0755 yii chmod 0755 yii_test ... initialization completed. CHANNEL_PUB_API_CFG_MIGRATE=true Yii Migration Tool (based on Yii v2.0.41.1) No new migrations found. Your system is up-to-date. PHP Core Warning 'yii/base/ErrorException' with message 'Module 'gd' already loaded' in ./Unknown:0 Stack trace: #0 [internal function]: yii/base/ErrorHandler->handleFatalError() #1 {main}
2、当 Rancher 环境变量,CHANNEL_PUB_API_CFG_MIGRATE=false 时,容器启动成功。如图2
chmod 0755 yii chmod 0755 yii_test ... initialization completed. CHANNEL_PUB_API_CFG_MIGRATE=false running without db migrate CHANNEL_PUB_API_CFG_CONSOLE=false copy without console CHANNEL_PUB_API_CFG_CRONTAB_VTT=false crontab.php not running POD_NAMESPACE=ccp test fail get environment fail ENVIRONMENT:default POD_NAMESPACE=ccp POD_HOSTIP=192.168.1.46 POD_IP=10.42.2.200
3、当 Rancher 环境变量,CHANNEL_PUB_API_CFG_MIGRATE=true 时,本质上是在执行一系列命令行。
env | grep CHANNEL_PUB_API_CFG_MIGRATE || export CHANNEL_PUB_API_CFG_MIGRATE="false" if [[ $CHANNEL_PUB_API_CFG_MIGRATE == "true" ]] then php /mcloud/www/ccp_api/yii migrate --migrationPath=@yii/log/migrations/ --interactive=0 php /mcloud/www/ccp_api/yii migrate --interactive=0 php /mcloud/www/ccp_api/yii cache/flush-schema db --interactive=0 php /mcloud/www/ccp_api/yii douyin-web-app/init-sync php /mcloud/www/ccp_api/yii qq-tp-app/init-sync php /mcloud/www/ccp_api/yii qq-cw-app/init-sync php /mcloud/www/ccp_api/yii weibo-weibo-connect-web-app/init-sync php /mcloud/www/ccp_api/yii wx-bizplugin-app/init-sync php /mcloud/www/ccp_api/yii netease-tp-app/init-sync elif [[ $CHANNEL_PUB_API_CFG_MIGRATE == "false" ]] then echo "running without db migrate" else echo "please set environment variable CHANNEL_PUB_API_CFG_MIGRATE true or false" fi
4、决定先在启动成功的容器中手动执行以上命令,以确定究竟是哪个命令导致报错。设置 Rancher 环境变量,CHANNEL_PUB_API_CFG_MIGRATE=false 。依次执行了前 3 条命令,皆报错。如图3
[root@api-console-migrate-5788cbf65c-qkjv2 /]# php /mcloud/www/ccp_api/yii migrate --migrationPath=@yii/log/migrations/ --interactive=0 Yii Migration Tool (based on Yii v2.0.41.1) No new migrations found. Your system is up-to-date. PHP Core Warning 'yii/base/ErrorException' with message 'Module 'gd' already loaded' in ./Unknown:0 Stack trace: #0 [internal function]: yii/base/ErrorHandler->handleFatalError() #1 {main} [root@api-console-migrate-5788cbf65c-qkjv2 /]# php /mcloud/www/ccp_api/yii migrate --interactive=0 Yii Migration Tool (based on Yii v2.0.41.1) No new migrations found. Your system is up-to-date. PHP Core Warning 'yii/base/ErrorException' with message 'Module 'gd' already loaded' in ./Unknown:0 Stack trace: #0 [internal function]: yii/base/ErrorHandler->handleFatalError() #1 {main} [root@api-console-migrate-5788cbf65c-qkjv2 /]# php /mcloud/www/ccp_api/yii cache/flush-schema db --interactive=0 Schema cache for component "db", was flushed. PHP Core Warning 'yii/base/ErrorException' with message 'Module 'gd' already loaded' in ./Unknown:0 Stack trace: #0 [internal function]: yii/base/ErrorHandler->handleFatalError() #1 {main} [root@api-console-migrate-5788cbf65c-qkjv2 /]#
5、在自己的技术博客中搜索:Module ‘gd’ already loaded 。曾经解决过类似的问题。参考网址:https://www.shuijingwanwq.com/2020/06/15/4240/
6、检查 /usr/local/php/etc/php.ini 中是否存在 gd。存在。如图4
;extension = "memcached.so" extension = "redis.so" ;extension = "mongo.so" extension = "sockets.so" extension = "swoole.so" extension = "mongodb.so" extension = "rdkafka.so" extension = "exif.so" extension = "imagick.so" extension = "gd.so" extension=mcrypt.so
7、最终通过在 Dockerfile 中新增:sed -i ‘/gd.so/d’ /usr/local/php/etc/php.ini && / 以解决此问题。
RUN sed -i 's/open_basedir = .//://tmp://data://webtv/;open_basedir = .//://tmp://data://webtv://usr//local//php/g' /usr/local/php/etc/php.ini && / sed -i 's/allow_url_fopen = Off/allow_url_fopen = On/g' /usr/local/php/etc/php.ini && / sed -i 's/disable_functions = exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show/disable_functions = system,shell_exec,escapeshellarg,escapeshellcmd,dl,popen,show/g' /usr/local/php/etc/php.ini && / sed -i 's/;realpath_cache_ttl = 120/realpath_cache_ttl = 1200/g' /usr/local/php/etc/php.ini && / sed -i '/gd.so/d' /usr/local/php/etc/php.ini && / sed -i 's/memory_limit = 2048M/memory_limit = 6144M/g' /usr/local/php/etc/php.ini && / sed -i 's/pm.max_children = 20/pm.max_children = 40/g' /usr/local/php/etc/php-fpm.conf
8、升级后,再次运行相关命令。报错:PHP Core Warning ‘yii/base/ErrorException’ with message ‘Module ‘exif’ already loaded’。如法炮制。在 Dockerfile 中新增:sed -i ‘/exif.so/d’ /usr/local/php/etc/php.ini && / 。
9、依次报错的扩展:sockets。也如此处理。Dockerfile 中最终新增 3 行配置。如图5
10、当 Rancher 环境变量,CHANNEL_PUB_API_CFG_MIGRATE=true 时,容器启动成功。如图6
chmod 0755 yii chmod 0755 yii_test ... initialization completed. CHANNEL_PUB_API_CFG_MIGRATE=true Yii Migration Tool (based on Yii v2.0.41.1) No new migrations found. Your system is up-to-date. Yii Migration Tool (based on Yii v2.0.41.1) Total 1 new migration to be applied: m211104_075052_alter_ccp_tables *** applying m211104_075052_alter_ccp_tables > insert into {{%ccp_platform}} ... done (time: 0.025s) > insert into {{%channel_type}} ... done (time: 0.059s) > alter column publish_task_id in table {{%ccp_task_log}} to integer(11) NOT NULL DEFAULT 0 COMMENT '关联任务id' ... done (time: 0.116s) > alter column account_token in table {{%ccp_platform_account}} to string(500) NOT NULL DEFAULT '' COMMENT '平台账号访问令牌' ... done (time: 0.029s) > alter column refresh_token in table {{%ccp_platform_account}} to string(500) NOT NULL DEFAULT '' COMMENT '刷新令牌' ... done (time: 0.023s) *** applied m211104_075052_alter_ccp_tables (time: 0.264s) 1 migration was applied. Migrated up successfully. Schema cache for component "db", was flushed. 抖音的网站应用模型的初始化(同步)成功 模型(企鹅号的第三方服务平台应用)创建成功 模型(企鹅号的内容网站应用)创建成功 模型(微博的微连接的网页应用)创建成功 微信的第三方平台应用模型的初始化(同步)成功 模型(网易号的第三方内容平台应用)创建成功 CHANNEL_PUB_API_CFG_CONSOLE=false copy without console CHANNEL_PUB_API_CFG_CRONTAB_VTT=false crontab.php not running POD_NAMESPACE=ccp test fail get environment fail ENVIRONMENT:default POD_NAMESPACE=ccp POD_HOSTIP=192.168.1.48 POD_IP=10.42.3.235
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/250641.html