使用vagrant快速搭建boxjp开发环境
前提
- 已经安装好virtualbox
- 已经安装好vagrant
部署开发环境
- 下载boxjp.box 文件,放到任意目录;
假设下载的文件放到了~/Desktop下
- 创建一个目录用于存放代码和开发环境配置文件
mkdir ~/Workspace/test/vagrant
- 初始化
cd ~/Workspace/test/vagrant
vagrant box add boxjp ~/Desktop/boxjp.box
vagrant init boxjp
- 修改配置Vagrantfile
增加如下内容:
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.network "private_network", ip: "10.10.1.5"
完整Vagrantfile文件内容:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "boxjp"
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.network "private_network", ip: "10.10.1.5"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
end
- 部署代码
mkdir ~/Workspace/test/vagrant/boxjp
cd ~/Workspace/test/vagrant/boxjp
git git@code.aliyun.com:zy/btc_boxjp_www.git
- 修改项目配置文件
- cp btc_boxjp_www/conf/application.ini.dev btc_boxjp_www/conf/application_local.ini
application_local.ini 内容如下:(application_local.ini下载)
[common]
application.directory = APPLICATION_PATH "/application"
application.modules = "Index,Admin,Ajax,Cms,Api,Product,Wap,Account"
;application.dispatcher.throwException = 1
;application.dispatcher.catchException = 1
application.use_namespace = 1
application.layout.directory = APPLICATION_PATH "/application/views/layouts"
application.protect_from_csrf = 1
db.default.dsn = "mysql:dbname=btcbox_jp;host=box-db00;port=3306"
db.default.username = root
db.default.password = 123456
db.slave01.dsn = "mysql:dbname=btcbox_jp;host=box-db00;port=3306"
db.slave01.username = root
db.slave01.password = 123456
redis.default.host = 127.0.0.1
redis.default.port = 6379
redis.default.db = 4
redis.cache.host = 127.0.0.1
redis.cache.port = 6379
redis.cache.db = 0
; 短信发送间隔(秒)
sms.mintime = 60
; 每天发送量(次)
sms.maxday = 50
; 邮件发送间隔
mail.mintime = 60
;登录错误次数
login.errcnt = 5
;登录账号个数
login.user = 5
[cli : common]
application.directory = APPLICATION_PATH "/application"
application.modules="Cli"
[www : common]
[test : common]
[aws : common]
[git : common]
[m : common]
[appapi : common]
- 修改本机hosts文件,增加如下内容
10.10.1.5 www.testboxjp.com
- 启动虚拟机
cd ~/Workspace/test/vagrant
vagrant up
- 访问测试环境
使用浏览器分别访问hosts文件中配置的域名:www.testboxjp.com
测试环境说明
- 启动boxjp测试环境
cd ~/Workspace/test/vagrant
vagrant up
- 关闭测试环境
cd ~/Workspace/test/vagrant
vagrant halt
- 登录测试环境
cd ~/Workspace/test/vagrant
vagrant ssh
- 销毁测试环境(虚拟机)
cd ~/Workspace/test/vagrant
vagrant destroy
- 测试环境nginx,redis,mysql,php-fpm 配置文件
nginx: /etc/nginx
redis: /etc/redis.conf
php.ini: /opt/remi/php56/root/etc/php.ini
php-fpm.ini: opt/remi/php56/root/etc/php-fpm.conf
mysql: /etc/my.cnf
- 如何启动nginx,redis,mysql, php-fpm
systemctl start nginx
systemctl start redis
systemctl start mysqld
systemctl start php-fpm
- nginx 日志目录
/var/log/nginx/
- msyql
账号:root
密码:123456