2017年9月15日金曜日

Vagrantでdjangocmsがインストールされた仮想マシン(CentOS7.3)を構築する

以下のVagrantfiledjangocmsがインストールされた可能マシンを構築します。
仮想マシン構築後、http://192.168.55.109:8000/にアクセスしユーザ名admin、パスワードadminでログインします。

Vagrantfile

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/centos-7.3"
  config.vm.hostname = "djangocms"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "djangocms"
     vbox.cpus = 4
     vbox.memory = 4096 
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
  # private network
  config.vm.network "private_network", ip: "192.168.55.109", :netmask => "255.255.255.0"
  # bridge netwrok
  config.vm.network "public_network", ip: "192.168.1.109", :netmask => "255.255.255.0"
  config.vm.network "forwarded_port", guest:22, host:20022, id:"ssh"
  config.vm.provision "shell", inline: <<-SHELL

wget https://repo.continuum.io/archive/Anaconda3-4.4.0-Linux-x86_64.sh 
chmod +x Anaconda3-4.4.0-Linux-x86_64.sh
./Anaconda3-4.4.0-Linux-x86_64.sh -b -p /opt/anaconda
source /opt/anaconda/bin/activate
pip install --upgrade pip
pip install djangocms-installer

mkdir ~/myproject
cd ~/myproject
djangocms -f --languages ja -p . mysite
echo 'ALLOWED_HOSTS = ["*"]' >> /root/myproject/mysite/settings.py
sed -i -e "s/TIME_ZONE = 'UTC'/TIME_ZONE = 'Asia\\/Tokyo'/" /root/myproject/mysite/settings.py
sed -i -e "s/'en'/'ja'/g" /root/myproject/mysite/settings.py

echo '------------------'
useradd py
mv /root/myproject /home/py
chown -R py:py /home/py/myproject

cp /vagrant/djangocms.service /etc/systemd/system
sudo systemctl enable djangocms
sudo systemctl start djangocms

echo 'access : http://192.168.55.109:8000/'
echo 'user/pass : admin/admin'
SHELL
end
djangocms.service

[Unit]
Description=djangocms

[Service]
Type=simple
ExecStartPre=source /opt/anaconda/bin/activate
ExecStart=/opt/anaconda/bin/python manage.py runserver 192.168.55.109:8000
User=py
Group=py
WorkingDirectory=/home/py/myproject
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

0 件のコメント:

コメントを投稿