Continuation of Last time.
This time, a memo when I did 2. and 3.
In the default box of CentOS, ssh access is not possible as root, and vagrant user⁺ authentication with private key is required. This can be confirmed with vagrant ssh-config.
2017/01/30 19:26:06|C:\Vagrant\CentOS0-2>vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile C:/Vagrant/CentOS0-2/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL
Since it is troublesome to promote root one by one, allow SSH access as root. First, edit the following two places with sshd_config on the guest. PermitRootLogin yes PasswordAuthentication yes
Access to guests is possible with the following settings. SSH port: 2222 User: vagrant Private key: C: \ Vagrant \ CentOS0-2 \ .vagrant \ machines \ default \ virtualbox \ private_key
After logging in, use su -
to promote root (password is vagrant)
[root@cnenyuy5l3c ~]# cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.orig
[root@cnenyuy5l3c ~]# vi /etc/ssh/sshd_config
[root@cnenyuy5l3c ~]# diff /etc/ssh/sshd_config /etc/ssh/sshd_config.orig
42c42
< PermitRootLogin yes
---
> #PermitRootLogin yes
66c66
< PasswordAuthentication yes
---
> PasswordAuthentication no
[root@cnenyuy5l3c ~]#
Next, reload the guest by writing the following in the .Vagrantfile. config.ssh.username = 'root' config.ssh.password = 'vagrant' config.ssh.insert_key = 'true'
2017/01/30 19:41:18|C:\Vagrant\CentOS0-2>vagrant reload
==> default: Attempting graceful shutdown of VM...
default: Guest communication could not be established! This is usually because
default: SSH is not running, the authentication information was changed,
default: or some other networking issue. Vagrant will force halt, if
default: capable.
==> default: Forcing shutdown of VM...
==> default: Checking if box 'centos/6' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 5000 (guest) => 5000 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: root
default: SSH auth method: password
==> default: Machine booted and ready!
[default] GuestAdditions 5.1.12 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => C:/Vagrant/CentOS0-2
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
First, install the prerequisite modules.
[root@cnenyuy5l3c ~]# yum install openssl-devel
[root@cnenyuy5l3c ~]# yum install sqlite-devel
[root@cnenyuy5l3c ~]# yum groupinstall "Development tools"
Then install Python. 2.6.6 is included by default, but since it is old, the latest (2.7.12) is included.
[root@cnenyuy5l3c ~]# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[root@cnenyuy5l3c ~]#
[root@cnenyuy5l3c ~]# curl -O https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
[root@cnenyuy5l3c ~]# ls
anaconda-ks.cfg install.log install.log.syslog Python-2.7.12.tar.xz
[root@cnenyuy5l3c ~]# xz -dv Python-2.7.12.tar.xz
[root@cnenyuy5l3c ~]# tar xvf Python-2.7.12.tar
[root@cnenyuy5l3c ~]# cd Python-2.7.12
[root@cnenyuy5l3c Python-2.7.12]# ./configure --prefix=/opt/local
[root@cnenyuy5l3c Python-2.7.12]# make && make altinstall
[root@cnenyuy5l3c Python-2.7.12]# ls -l /usr/bin/python*
-rwxr-xr-x. 2 root root 9032 Aug 18 15:14 /usr/bin/python
lrwxrwxrwx. 1 root root 6 Dec 15 11:11 /usr/bin/python2 -> python
-rwxr-xr-x. 2 root root 9032 Aug 18 15:14 /usr/bin/python2.6
[root@cnenyuy5l3c Python-2.7.12]# rm /usr/bin/python
rm: remove regular file `/usr/bin/python'? y
[root@cnenyuy5l3c Python-2.7.12]#
[root@cnenyuy5l3c Python-2.7.12]# cp -p /opt/local/bin/python2.7 /usr/bin/python
[root@cnenyuy5l3c Python-2.7.12]# python
Python 2.7.12 (default, Jan 30 2017, 11:04:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[root@cnenyuy5l3c Python-2.7.12]#
Note that yum only works with 2.6, so only yum should be set to refer to 2.6.
[root@cnenyuy5l3c Python-2.7.12]# which yum
/usr/bin/yum
[root@cnenyuy5l3c Python-2.7.12]# vi /usr/bin/yum
[root@cnenyuy5l3c Python-2.7.12]# head -1 /usr/bin/yum
#!/usr/bin/python2.6
After that, install virtualenv (and pip used for its installation) to keep the development environment separate.
[root@cnenyuy5l3c Python-2.7.12]# curl -kL https://bootstrap.pypa.io/get-pip.py | /opt/local/bin/python2.7
[root@cnenyuy5l3c Python-2.7.12]# ls /opt/local/bin/
2to3 easy_install easy_install-2.7 idle pip pip2 pip2.7 pydoc python2.7 python2.7-config smtpd.py wheel
[root@cnenyuy5l3c Python-2.7.12]# cd ~
[root@cnenyuy5l3c ~]# vi .bashrc
[root@cnenyuy5l3c ~]# cat .bashrc
## CUSTOM START
export PATH=$PATH:/opt/local/bin/
## CUSTOM END
[root@cnenyuy5l3c ~]#
[root@cnenyuy5l3c ~]# source .bashrc
[root@cnenyuy5l3c ~]# /opt/local/bin/pip2.7 install virtualenv
Pass it through the pip path. The last test so far.
[root@cnenyuy5l3c ~]# mkdir testpj
[root@cnenyuy5l3c ~]# cd testpj
[root@cnenyuy5l3c testpj]#
[root@cnenyuy5l3c testpj]#
[root@cnenyuy5l3c testpj]# virtualenv env
New python executable in /root/testpj/env/bin/python2.7
Also creating executable in /root/testpj/env/bin/python
Installing setuptools, pip, wheel...done.
[root@cnenyuy5l3c testpj]# ls
env
[root@cnenyuy5l3c testpj]#
[root@cnenyuy5l3c testpj]# . env/bin/activate
(env) [root@cnenyuy5l3c testpj]#
(env) [root@cnenyuy5l3c testpj]# python
Python 2.7.12 (default, Jan 30 2017, 11:04:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> quit()
(env) [root@cnenyuy5l3c testpj]#
(env) [root@cnenyuy5l3c testpj]# deactivate
[root@cnenyuy5l3c testpj]#
Virtualenv started and stopped in Python 2.7.
Install flask in virtualenv.
[root@cnenyuy5l3c testpj]# . env/bin/activate
(env) [root@cnenyuy5l3c testpj]#
(env) [root@cnenyuy5l3c testpj]# easy_install Flask
Create the following test app file and start it.
app.py
from flask import Flask
app = Flask(__name__)
@app.route(‘/’)
def hello_world():
return "Hello World!"
if __name__ == '__main__':
app.run(host='0.0.0.0')
Launch the application.
(env) [root@cnenyuy5l3c testpj]# python app.py
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
Access 5000 on the host machine and check the operation.
Up to here for this time.
Recommended Posts