2017年11月29日水曜日

VagrantでMezzanineをインストールした仮想マシン(Ubuntu16.04)を構築する

以下のVagrantfileを使用して、Mezzanineをインストールした仮想マシンを構築する事が出来ます。
仮想マシンが構築された後、ブラウザからhttp://192.168.55.105/admin/で管理者画面にアクセスできます。
デフォルトのユーザはadmin、パスワードはdefaultです。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = "ub1604mezzanine"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1604mezzanine"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
  config.vm.network "private_network", ip: "192.168.55.105", :netmask => "255.255.255.0"
  config.vm.network "public_network", ip:"192.168.1.105", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
# update packages
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8

# install mysql
echo "mysql-server-5.7 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mysql-server-5.7 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mysql-server-5.7
mysql -uroot -proot -e "CREATE DATABASE mezzanine DEFAULT CHARACTER SET utf8;"
mysql -uroot -proot -e "CREATE USER mezzanine@localhost IDENTIFIED BY 'mezzanine';"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON mezzanine.* TO 'mezzanine'@'localhost';"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON mezzanine.* TO 'mezzanine'@'%';"
mysql -uroot -proot -e "FLUSH PRIVILEGES;"

# install apache2 and wsgi
apt-get -y install apache2 libapache2-mod-wsgi
a2enmod wsgi

# install mezzanine
apt-get -y install python-pip
pip install --upgrade pip
pip install mezzanine

apt-get -y install libmysqlclient-dev
pip install mysqlclient

mkdir -p /opt/mezzanine
cd /opt/mezzanine

mezzanine-project mysite

sed -i -e 's/"ENGINE": "django.db.backends.sqlite3",/"ENGINE": "django.db.backends.mysql",/' /opt/mezzanine/mysite/mysite/local_settings.py
sed -i -e 's/"NAME": "dev.db",/"NAME": "mezzanine",/' /opt/mezzanine/mysite/mysite/local_settings.py
sed -i -e 's/"USER": "",/"USER": "mezzanine",/' /opt/mezzanine/mysite/mysite/local_settings.py
sed -i -e 's/"PASSWORD": "",/"PASSWORD": "mezzanine",/' /opt/mezzanine/mysite/mysite/local_settings.py
sed -i -e 's/"HOST": "",/"HOST": "localhost",/' /opt/mezzanine/mysite/mysite/local_settings.py
sed -i -e 's/"PORT": "",/"PORT": "3306",/' /opt/mezzanine/mysite/mysite/local_settings.py
echo 'ALLOWED_HOSTS = ["*"]' >> /opt/mezzanine/mysite/mysite/local_settings.py

cd /opt/mezzanine/mysite
python manage.py createdb --noinput
python manage.py collectstatic --noinput

cat << EOF > /etc/apache2/sites-available/mezzanine.conf

  ServerName 192.168.55.105
  WSGIDaemonProcess mezzanine processes=1 threads=25
  WSGIScriptAlias / /opt/mezzanine/mysite/mysite/wsgi.py
  Alias /static/ /opt/mezzanine/mysite/static/
  
    WSGIProcessGroup mezzanine
    WSGIApplicationGroup %{GLOBAL}
    Require all granted
  

EOF

cat << EOF > /opt/mezzanine/mysite/mysite/wsgi.py
"""
WSGI config for mysite project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""

import os
import sys

from django.core.wsgi import get_wsgi_application
from mezzanine.utils.conf import real_project_name
sys.path.append("/opt/mezzanine/mysite")
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
                      "%s.settings" % real_project_name("mysite"))

application = get_wsgi_application()
EOF

chown -R www-data:www-data /opt/mezzanine

a2ensite mezzanine.conf
a2dissite 000-default.conf

systemctl restart apache2

echo 'access to http://192.168.55.105/';
echo 'access to http://192.168.55.105/admin/';
echo 'user: admin  password: defau;t'
SHELL
end

○Mezzanine画面


○Mezzanineログイン画面


○Mezzanine管理者画面


0 件のコメント:

コメントを投稿