标签 magento 下的文章

安装 magento 2.4.6-p1

当前,magento 官方商城使用的程序版本是 magento 2.4.6-p1 。尝试安装一下,记录遇到的问题。

问题一:debian 12系统里,默认安装的mariadb版本是10.11.3,但 magento 要求是10.6。数据库的版本过高,magento安装程序不认。

出错信息:Current version of RDBMS is not supported. Used Version: 10.11.3-MariaDB-1. Supported versions: MySQL-8, MySQL-5.7, MariaDB-(10.2-10.6)

或:

Warning: preg_match(): Compilation failed: range out of order in character class at offset 25 in magento/vendor/magento/framework/DB/Adapter/SqlVersionProvider.php on line 101

尝试:

对于第一个报错,按照网上的例子,修改 magento/app/etc/di.xml 文件内容,如:
<item name="MariaDB-(10.2-10.11)" xsi:type="string">^10\.[2-11]\.</item> 直接修改版本号。

第二个报错,修改 magento/vendor/magento/framework/DB/Adapter/SqlVersionProvider.php 文件内容,如:

        $pattern = sprintf('/(%s)/', implode('|', $this->supportedVersionPatterns));
        $pattern = '/10.11/';
        $sqlVersionOutput = '10.11.3-MariaDB-1';
        preg_match($pattern, $sqlVersionOutput, $match);

问题二:magento 安装程序,连接不上刚刚安装的 opensearch ,提示:Could not validate a connection to the opensearch, no alive nodes found in your cluster

尝试:在 /etc/opensearch/opensearch.yml 文件中,添加一行 plugins.security.disabled: true ,即将opensearch的https和用户访问的安全设置禁用。

问题三:使用 nginx 的反向代理 apache 上的 magento 站点后,https 访问异常,如不断地循环跳转。

magento 的站点网址设置等,和平时的差不多,如下例:

catalog/search/engine - opensearch
catalog/search/opensearch_server_hostname - localhost
catalog/search/opensearch_server_port - 9200
catalog/search/opensearch_index_prefix - magento2
catalog/search/opensearch_server_timeout - 15
catalog/category/root_id - 2
web/seo/use_rewrites - 1
web/unsecure/base_url - http://magento.anqun.org/
web/unsecure/base_static_url -
web/unsecure/base_media_url -
web/secure/base_url - https://magento.anqun.org/
web/secure/base_static_url -
web/secure/base_media_url -
web/secure/enable_hsts - 0
web/secure/enable_upgrade_insecure - 0
web/secure/use_in_frontend - 1
web/secure/use_in_adminhtml - 1
web/secure/offloader_header -
web/default_layouts/default_product_layout - product-full-width
web/default_layouts/default_category_layout - category-full-width
web/default_layouts/default_cms_layout - cms-full-width
web/cookie/cookie_path -
web/cookie/cookie_domain -
web/cookie/cookie_httponly - 1
general/locale/code - zh_Hans_CN
general/locale/timezone - Asia/Shanghai
general/region/display_all - 1
general/region/state_required - AL,AR,AU,BG,BO,BR,BY,CA,CH,CL,CN,CO,CZ,DK,EC,EE,ES,GR,GY,HR,IN,IS,IT,LT,LV,MX,PE,PL,PT,PY,RO,SE,SR,US,UY,VE
currency/options/base - CNY
currency/options/default - CNY
currency/options/allow - CNY
analytics/subscription/enabled - 1
crontab/default/jobs/analytics_subscribe/schedule/cron_expr - 0 * * * *
crontab/default/jobs/analytics_collect_data/schedule/cron_expr - 00 02 * * *

关键应该是设置 https 的环境参数,如通过 .htaccess 添加以下内容:

setenv HTTPS on
SetEnv HTTP_X_FORWARDED_PROTO "https"

如果nginx反代配置中使用了 X-Real-IP 头,那么 apache 中的访问日志,可以使用 LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Real-IP}i\"" proxycombined 来记录访客IP。

nginx站点例子:

server {
        listen       443 ssl;  
        server_name  magento.anqun.org; 

        ssl_certificate          fullchain.cer;
        ssl_certificate_key      magento.anqun.org.key;

        proxy_buffer_size   128k;
        proxy_buffers   4 256k;
        proxy_busy_buffers_size   256k;

        location / {
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_pass         http://192.168.1.9:8001;
        }
}

参考:

magento - 负载高 - 后台任务 - cron_schedule

现象:magento2站点,查看系统负载,在4.5左右。
尝试:在top命令详情中,mysqld和php进程占用CPU、内存高。先删除magento的定时任务,再手动退出当前的php任务进程,系统负载明显回落。但将定时任务加回后,负载又升高。最后,将数据库中的cron_schedule清空,即执行 TRUNCATE cron_schedule; 后,基本恢复正常。

参考:https://magento.stackexchange.com/questions/203107/magento-2-cron-schedule-table-increasing-and-cpu-100

更新 magento2 产品索引时,elastic search 报错 - status 429

问题:magento2.4的站点,执行 bin/magento indexer:reindex 后,elastic search 报错。内容如下:

Catalog Search index process error during indexation process:
{"error":{"root_cause":[{"type":"cluster_block_exception","reason":"index [magento2_mazia_243_product_1_v45] blocked by: [TOO_MANY_REQUESTS/12/disk usage exceeded flood-stage watermark, index has read-only-allow-delete block];"}],"type":"cluster_block_exception","reason":"index [magento2_mazia_243_product_1_v45] blocked by: [TOO_MANY_REQUESTS/12/disk usage exceeded flood-stage watermark, index has read-only-allow-delete block];"},"status":429}

尝试:按网上说的,调整elastic search设置后就可以了:

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'

参考:https://stackoverflow.com/questions/63689953/magento-2-4-reindex-issue-with-elasticsearch

为 magento2 的 static 和 media 设置 aws cloudfront 访问

需求:想将magento2的static和media配置cdn,如aws的cloudfront访问。

尝试:

  1. 分别以/static和/media为源,在cloudfront创建两个分配
  2. 如/static的分配,在“行为”中的“源请求策略名称”选择为“Managed-CORS-CustomOrigin”、“响应标头策略名称”选择为“Managed-CORS-With-Preflight”
  3. 在magento2后台中,设置static和media的网址为cloudfront的
  4. 如需调整static和media文件目录中的.htaccess内容,可适当调整

参考:

magento1.x 无法导出商品的部分属性,如价格

现象:通过magento 1.x 自带的导出商品数据功能,再在迁移后的站点里导入,商品丢失价格等部分属性。如果直接通过mysqldump导出及mysql导入整个magento站点数据表,则站点后台无法列出显示商品,“商品管理”为零。

尝试:在phpmyadmin中看到,通过mysql导入数据库内容后的部分数据表,如 catalog_product_entity_int 无数据。尝试通过phpmyadmin导入该表时,提示错误 #1062 - Duplicate entry '204-102-0' for key 'UNQ_CATALOG_PRODUCT_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID' 。很可能是因为原数据库的部分数据表有错误,无法成功导出完整的数据。

参考:https://community.magento.com/t5/Magento-2-x-Technical-Issues/How-to-add-new-products-through-magento-database/m-p/447973/highlight/true