2018年5月24日木曜日

VagrantでMezzanineとPercona Serverをインストールした仮想マシン(Debian Stretch/9.4)を構築する

MezzanineはPython製のCMSです。

○Mezzanineの画面


○構築方法
以下のVagrantfileを使用して、MezzanineとPercona Serverがインストールされた仮想マシン(Debian Stretch/9.4)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.4"
  config.vm.hostname = "db94mezzaninemariadb"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db94mezzaninemariadb"
     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
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

# install mariadb
echo "mariadb-server-10.0 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mariadb-server-10.0 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mariadb-server
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 "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 libmariadbclient-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
<VirtualHost *:80>
  ServerName 192.168.55.105
  WSGIDaemonProcess mezzanine processes=1 threads=25
  WSGIScriptAlias / /opt/mezzanine/mysite/mysite/wsgi.py
  Alias /static/ /opt/mezzanine/mysite/static/
  <Directory /opt/mezzanine/mysite>
    WSGIProcessGroup mezzanine
    WSGIApplicationGroup %{GLOBAL}
    Require all granted
  </Directory>
</VirtualHost>
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: default'
SHELL
end

0 件のコメント:

コメントを投稿