centos7安装mysql8_一:安装篇 【Magento2.4实战百万商品】

  • 前言:Magento2.4.0已经发布,为了重新认识这个越来越复杂的系统,决定从安装开始,边摸索边进行。

  • 硬件: 母鸡为Windows的R5-3600,64G, 512*2 NVME,通过hyper-v虚拟出3台内网互通的虚拟机,且全新安装Centos7.8.2003 Minimal

  • 架构: 1台机器配置Web、Mysql、Redis,作为主服务器),第2台机器配置ElasticSearch,第3台机器配置Varnish

            这三台机器的配置、内网IP和hostname分别为

            6核/16G,192.168.1.1,server1

            1核/4G,192.168.1.2,server2

            1核/4G,192.168.1.3,server3

  • 首先安装2号机器的ElasticSearch:

升级系统,安装Java

yum -y updateyum -y install java-1.8.0-openjdk  java-1.8.0-openjdk-devel

配置Java

cat <export JAVA_HOME=/usr/lib/jvm/jre-openjdkexport PATH=\$PATH:\$JAVA_HOME/binexport CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jarEOFsource /etc/profile.d/java8.sh

配置elasticsearch安装源

cat <[elasticsearch-7.x]name=Elasticsearch repository for 7.x packagesbaseurl=https://artifacts.elastic.co/packages/oss-7.x/yumgpgcheck=1gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearchenabled=1autorefresh=1type=rpm-mdEOF

安装elasticsearch

yum -y install elasticsearch-oss

修改配置允许远程访问

修改配置/etc/elasticsearch/elasticsearch.ymlnetwork.host: 0.0.0.0cluster.initial_master_nodes: ["node-1"]

启动elasticsearch并开机自启动

systemctl enable --now elasticsearch

查看是否正常启动

systemctl status elasticsearch

如果看到Active: active (running) 则是正常启动了。

此外需要开放防火墙的9200端口。由于我这边是内网,所以直接把firewalld关闭,禁用自启动了。

systemctl disable --now firewalld

再次测试是否运行,也可以在server1和server3上测试是否允许外部访问

[root@server2 network-scripts]# curl http://127.0.0.1:9200{  "name" : "server2",  "cluster_name" : "elasticsearch",  "cluster_uuid" : "G2Jh9gIeSfK8D_D8hEYfOg",  "version" : {    "number" : "7.9.0",    "build_flavor" : "oss",    "build_type" : "rpm",    "build_hash" : "a479a2a7fce0389512d6a9361301708b92dff667",    "build_date" : "2020-08-11T21:36:48.204330Z",    "build_snapshot" : false,    "lucene_version" : "8.6.0",    "minimum_wire_compatibility_version" : "6.8.0",    "minimum_index_compatibility_version" : "6.0.0-beta1"  },  "tagline" : "You Know, for Search"}
  • 安装3号机器varnish6.4.0:

一开始在jemalloc上折腾了很久,后来发现直接用epel源就顺利解决了

yum install -y autoconf epel-release pygpgme yum-utils

配置安装源

cat <[varnishcache_varnish64]name=varnishcache_varnish64baseurl=https://packagecloud.io/varnishcache/varnish64/el/7/$basearchrepo_gpgcheck=1gpgcheck=0enabled=1gpgkey=https://packagecloud.io/varnishcache/varnish64/gpgkeysslverify=1sslcacert=/etc/pki/tls/certs/ca-bundle.crtmetadata_expire=300[varnishcache_varnish64-source]name=varnishcache_varnish64-sourcebaseurl=https://packagecloud.io/varnishcache/varnish64/el/7/SRPMSrepo_gpgcheck=1gpgcheck=0enabled=1gpgkey=https://packagecloud.io/varnishcache/varnish64/gpgkeysslverify=1sslcacert=/etc/pki/tls/certs/ca-bundle.crtmetadata_expire=300EOF

清除缓存

sudo yum -q makecache -y --disablerepo='*' --enablerepo='varnishcache_varnish64'

安装Varnish6.4.0

yum -y install varnish

启动并开启自启动

systemctl enable --now varnish

检查varnish状态

systemctl status varnish

看到Active: active (running)则说明启动成功

同样的由于内网,3号机器也关闭了防火墙

systemctl disable --now firewalld

后续在Magento2.4安装好之后,后台Store - Configuration - System - Full Page Cache配置Varnish参数,下载vcl配置文件。然后替换/etc/varnish/default.vcl,并重启即可。

varnish可以通过命令varnishstat来查看运行状态

  • 安装1号机器Magento2.4:

为了这篇文章写得方便,这里使用目前比较流行的宝塔面板,如果是我自己使用的话,首选cPanel+Cloudlinux,其次用Vestacp。

安装宝塔

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

安装后选择安装软件

Apache 2.4.46MySQL 8.0.20PHP 7.4.9Redis 6.0.6

重要】安装完成后安装PHP扩展,ionCube、fileinfo、opcache、redis、intl、xsl,并且修改PHP的memory_limit为1536M,另外务必别忘了解除禁用函数putenv,proc_open,openlog,syslog,pcntl_signal。

然后进入宝塔面板,创建网站和数据库,并删除网站目录下的所有文件,避免安装时候文件重复无法覆盖。

提前在https://marketplace.magento.com/customer/accessKeys/创建一个应用,获取Public Key和Private Key,使用composer安装,当然也可以登录这个页面下载源码https://magento.com/tech-resources/download

在composer的时候需要使用到unzip,因此预先安装好,并且通过ssh进入到网站主目录

yum install -y unzipcd /www/wwwroot/demo.com

这里有三个办法安装Magento2.4主程序

  • 【推荐】方法一:单文件安装

在主目录生成composer.json文件

cat <{    "name": "magento/project-community-edition",    "description": "eCommerce Platform for Growth (Community Edition)",    "type": "project",    "license": [        "OSL-3.0",        "AFL-3.0"    ],    "config": {        "preferred-install": "dist",        "sort-packages": true    },    "require": {        "magento/product-community-edition": "2.4.0",        "magento/composer-root-update-plugin": "~1.0"    },    "require-dev": {        "allure-framework/allure-phpunit": "~1.2.0",        "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",        "friendsofphp/php-cs-fixer": "~2.16.0",        "lusitanian/oauth": "~0.8.10",        "magento/magento-coding-standard": "*",        "magento/magento2-functional-testing-framework": "^3.0",        "pdepend/pdepend": "~2.7.1",        "phpcompatibility/php-compatibility": "^9.3",        "phpmd/phpmd": "^2.8.0",        "phpstan/phpstan": ">=0.12.3 <=0.12.23",        "phpunit/phpunit": "^9",        "sebastian/phpcpd": "~5.0.0",        "squizlabs/php_codesniffer": "~3.5.4"    },    "conflict": {        "gene/bluefoot": "*"    },    "autoload": {        "psr-4": {            "Magento\\\\Framework\\\\": "lib/internal/Magento/Framework/",            "Magento\\\\Setup\\\\": "setup/src/Magento/Setup/",            "Magento\\\\": "app/code/Magento/",            "Zend\\\\Mvc\\\\Controller\\\\": "setup/src/Zend/Mvc/Controller/"        },        "psr-0": {            "": [                "app/code/",                "generated/code/"            ]        },        "files": [            "app/etc/NonComposerComponentRegistration.php"        ],        "exclude-from-classmap": [            "**/dev/**",            "**/update/**",            "**/Test/**"        ]    },    "autoload-dev": {        "psr-4": {            "Magento\\\\Sniffs\\\\": "dev/tests/static/framework/Magento/Sniffs/",            "Magento\\\\Tools\\\\": "dev/tools/Magento/Tools/",            "Magento\\\\Tools\\\\Sanity\\\\": "dev/build/publication/sanity/Magento/Tools/Sanity/",            "Magento\\\\TestFramework\\\\Inspection\\\\": "dev/tests/static/framework/Magento/TestFramework/Inspection/",            "Magento\\\\TestFramework\\\\Utility\\\\": "dev/tests/static/framework/Magento/TestFramework/Utility/",            "Magento\\\\PhpStan\\\\": "dev/tests/static/framework/Magento/PhpStan/"        }    },    "version": "2.4.0",    "minimum-stability": "stable",    "repositories": [        {            "type": "composer",            "url": "https://repo.magento.com/"        }    ],    "extra": {        "magento-force": "override"    }}EOF

方法二:composer获取源码

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.4.0

#提示username输入Public Key,password输入Private Key,是否创建auth.json,输入Y回车。

这个时候安装的数据都在/www/wwwroot/demo.com/project-community-edition目录下,我们需要转移文件到网站根目录,用命令行迁移容易丢失.htaccess等文件,建议用文件管理器迁移。

【推荐】方法三:上传源码

在官网https://magento.com/tech-resources/download下载源码,并且解压到主目录。

上述三种办法任选其一,随后在主目录执行

composer install

composer安装完成后执行magento安装,Magento2.4.0已取消网页安装,将下列命令行关于数据库信息和域名信息修改后填入,请注意ElasticSearch服务器是必需的

bin/magento setup:install --base-url=http://www.demo.com/ \--db-host=localhost --db-name=demo_com --db-user=demo_com --db-password=MmZ8asfdjk \--admin-firstname=Magento --admin-lastname=User --admin-email=admin@demo.com \--admin-user=admin --admin-password=demoadmin88 --language=en_US \--currency=USD --timezone=America/Chicago --use-rewrites=1 \--search-engine=elasticsearch7 --elasticsearch-host=server2 \--elasticsearch-port=9200

执行完成后显示对应目录为/admin_31b6ig

[SUCCESS]: Magento installation complete.[SUCCESS]: Magento Admin URI: /admin_31b6igNothing to import.

因为我们一直都是root用户执行命令,因此需要最后重置一下文件权限,此外Magento2.4.0强制开启了二次验证,我们这里关掉,随后刷新静态资源、索引和缓存

chown -R www:www /www/wwwroot/demo.combin/magento module:disable Magento_TwoFactorAuthbin/magento setup:upgradebin/magento setup:di:compilebin/magento setup:static-content:deploy -fbin/magento indexer:reindexbin/magento cache:flush

如果遇到文件读写权限的问题,再执行一遍权限

chown -R www:www /www/wwwroot/demo.com

安装完成后给Magento跑个分,不知道啥时候出的这个功能,需要注意这里要给mysql的root权限,或者直接改app/etc/env.php中的数据库用户为root,跑分文件位于setup/performance-toolkit/profiles/ce/目录下,我们选择一个中等配置进行测试,下面可以看到这个配置中测试生成了24000个简单产品,50000个订单。

[root@server1 demo.com]# bin/magento setup:performance:generate-fixtures /www/wwwroot/demo.com/setup/performance-toolkit/profiles/ce/medium.xmlGenerating profile with following params: |- Admin Users: 50 |- Websites: 3 |- Store Groups Count: 3 |- Store Views Count: 3 |- Categories: 300 |- Attribute Sets (Default): 3 |- Attribute Sets (Extra): 30 |- Simple products: 24000 |- Configurable products: 640 |- Product images: 1000, 3 per product |- Customers: 2000 |- Cart Price Rules: 20 |- Catalog Price Rules: 20 |- Coupon Codes: 20 |- Orders: 50000Config Changes...  done in 00:00:00Generating admin users...  done in 00:00:02Generating websites, stores and store views...  done in 00:00:02Generating categories...  done in 00:00:11Generating attribute sets...  done in 00:00:10Generating simple products...  done in 00:01:55Generating configurable EAV variations...  done in 00:00:00Generating bundle products...  done in 00:00:00Generating configurable products...  done in 00:00:51Generating images...  done in 00:00:44Generating customer groups...  done in 00:00:00Generating customers...  done in 00:00:11Generating cart price rules...  done in 00:00:03Generating catalog price rules...  done in 00:00:03Generating tax rates...  done in 00:04:05Generating tax rules...  done in 00:00:00Generating coupon codes...  done in 00:00:00Generating orders...  done in 00:03:36Indexers Mode Changes...  done in 00:00:03Design Config Grid index has been rebuilt successfully in 00:00:00Customer Grid index has been rebuilt successfully in 00:00:01Category Products index has been rebuilt successfully in 00:00:15Product Categories index has been rebuilt successfully in 00:00:00Catalog Rule Product index has been rebuilt successfully in 00:00:19Product EAV index has been rebuilt successfully in 00:00:20Stock index has been rebuilt successfully in 00:00:16Inventory index has been rebuilt successfully in 00:00:00Catalog Product Rule index has been rebuilt successfully in 00:00:00Product Price index has been rebuilt successfully in 00:00:28Catalog Search index has been rebuilt successfully in 00:03:55Total execution time: 00:17:53

整体数据比较满意,毕竟4万产品和5万订单在这么短的时间内生成处理就已经相当不错了,而且这个服务器还只是入门性能。

跑完分后访问前后台还是有报错,没办法,再来执行一遍

bin/magento setup:upgradebin/magento setup:di:compilebin/magento setup:static-content:deploy -fbin/magento indexer:reindexbin/magento cache:flush

最后配置varnish,在后台依次进入

Store - Configuration - System - Full Page Cache

设置Backend host源IP,注意:我们这里是将Varnish分离出去了,因为实际情况中鉴于各种BUG以及对SSL兼容性的问题,最终我们将不使用varnish,本文仅作安装配置说明,后面在关于性能优化方面会具体为什么不用varnish以及varnish的替代方案。

另外设置varnish为缓存后会存在前台导航菜单丢失的情况,最简单的办法是修改

/vendor/magento/module-theme/view/frontend/layout/default.xml中66行,将ttl="3600"删除即可。

136b43c2c6de071533c823d60deccbd2.png

配置Varnish后前台丢导航

到这里,整个环境安装完成。

ea954549caab614562b854f5c5cf094e.png

Magento2.4.0首次登录后台显示

14f6e8e7d803aab28408a8e550584399.png

后台40000产品,非常流畅。

7a73395d244e41a3824f2e650ae70906.png

得益于ElasticSearch7.6,前台搜索也非常棒!

后续计划

第二篇将通过一系列工具演练产品的采集和上传,

第三篇会通过一些插件进而完善电商的各个运营环节,

第四篇会注重优化前台页面的速度性能,

后续待定...

欢迎关注并分享。有任何疑问随时回复或者留言。

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值