2018年9月23日日曜日

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

MezzanineはPython製のCMSです。

○Mezzanineの画面

デフォルトアカウント/パスワードはadmin/defaultです

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

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-18.04"
  config.vm.hostname = "ub1804mezzaninemariadb"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1804mezzaninemariadb"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.62", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.62", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
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
timedatectl set-timezone Asia/Tokyo

# 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 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.62
  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
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.62/'
echo 'access to http://192.168.55.62/admin/'
echo 'user: admin  password: default'
SHELL
end

0 件のコメント:

コメントを投稿