Windows 下通过 Vagrant 简单搭建 Magento

准备软件

  1. VirtualBox 5.2.8
  2. Vagrant 2.0.1

官网下载安装,比我的新即可,安装路径自选。

创建 Vagrantfile

新建文件夹并创建 Vagrantfile 放在里面,我配置的环境是 Ubuntu 16.04,内存8G,可以换成自己熟悉的环境。
映射端口80,443(Web),3306(数据库),9200,9300(搜索引擎)。

Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.network "forwarded_port", guest: 443, host: 443
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.network "forwarded_port", guest: 9200, host: 9200
config.vm.network "forwarded_port", guest: 9300, host: 9300
config.vm.provider "virtualbox" do |vb|
vb.memory = "8192"
end
end

启动并连接到虚拟机

Vagrantfile 所在目录执行

cmd
1
2
vagrant up
vagrant ssh

虚拟机中安装 docker

bash
1
2
3
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo apt-get install docker-compose

将当前用户加入 docker 用户组

bash
1
2
3
4
sudo usermod -aG docker $USER
# 需要断开并重新连接以生效
exit
vagrant ssh

设置

修改 VMA(虚拟内存区域)数值以保证 Elastic Search 可以顺利启动

bash
1
sudo sysctl -w vm.max_map_count=262144

使用官方一键部署脚本部署。

bash
1
2
curl -sSL https://raw.githubusercontent.com/bitnami/bitnami-docker-magento/master/docker-compose.yml > docker-compose.yml
docker-compose up -d

查看运行状态

bash
1
2
3
4
5
6
docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
50d5ccd79dbf bitnami/magento:2 "/app-entrypoint.sh …" 6 hours ago Up 6 hours 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp vagrant_magento_1
58577f4b0595 bitnami/mariadb:10.2 "/entrypoint.sh /run…" 7 hours ago Up 6 hours 3306/tcp vagrant_mariadb_1
3c217cc1492e bitnami/elasticsearch:6 "/entrypoint.sh /run…" 7 hours ago Up 7 hours 9200/tcp, 9300/tcp vagrant_elasticsearch_1

在 Windows 中打开 http://127.0.0.1,检查是否能够正常访问。

默认后台:http://127.0.0.1/index.php/admin/
默认用户:user
默认密码:bitnami1

遇到问题

  1. 执行 docker logs [容器ID] 查看 log
  2. 查看官方文档:https://github.com/bitnami/bitnami-docker-magento/blob/master/README.md

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×