Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
DevOps (4)
- Ansible (2) —
Soshi Nemoto
Mulodo Vietnam Co., Ltd.
Our Purpose
Make ourselves ‘Business partner’ from
‘factory’.
Points
Engineering knowledge <- * TODAY *
Logical Thinking
Co-operation work
— Study Group —
What’s DevOps?
Mindset of filling gap between Dev and Ops.
It’s not any technologies or solutions.
C.A.M.S
Culture
Bust silos. Don’t say “no”. Involve everyone.
Automation
XXX as Code. Ask machines to do same things.
Metrics
monitor, find failure, Improve, make a plan.
Share
Dev->Ops, Ops->Dev, share metrics.
Feedback of previous study
Feedback of previous study (2)
What’s Vagrant?
manager of Virtual Machines
Vagrant can manage …
Virtual Box
VMware (Fusion)
AWS EC2 ….
Trigger of automation engine.
Vagrant run …
Ansible
Chef
Puppet ….
Feedback of previous study (3)
What’s ansible?
A radically simple IT automation engine
for ‘infrastructure as Code’…
“Ask machines to do SAME things”
Trial
Simple usage (hosts and playbook)
Set in Vagrantfile
Ansible (2)
A radically simple IT automation engine
What’s Idempotence?
How to install version
specified application
AGENDA
What’s Idempotence?
The property that can be applied
multiple times without changing
the result beyond the initial
application. (wikipedia)
Ansible is idempotence !?
What’s Idempotence?
The property that can be applied
multiple times without changing
the result beyond the initial
application. (wikipedia)
Ansible is idempotence !?
Ansible playbook should be idempotence.
Why do you learn Ansible here?
DevOps -> Automation (C.A.M.S.)
Why do you learn Ansible here?
DevOps -> Automation (C.A.M.S.)
Automation
Infrastructure as Code.
Clarify specification.
- playbook
Guarantee same result.
- Idempotence
Why do you learn Ansible here?
DevOps -> Automation (C.A.M.S.)
Automation
Infrastructure as Code.
Clarify specification.
- playbook
Guarantee same result.
- Idempotence
Why do you learn Ansible here?
DevOps -> Automation (C.A.M.S.)
Automation
Infrastructure as Code.
Clarify specification.
- playbook
Guarantee same result.
- Idempotence
You need to check results carefully for each
operation, if it is not guaranteed to get same
result when you do it repeatedly.
Idempotence
Love
it
!
What’s Idempotence?
How to install version
specified application
How to build ‘tarball’?
How to create playbooks?
AGENDA
Application
Server applications is NOT gifts
from Buddha.
Server application is NOT
packages of YUM/Apt/RPM.
Almost server apps are
only C/C++ applications.
You can install Apps without Package manager.
How to make C/C++ apps?
#include "stdio.h"
int main(int argc, char *argv[])
{
printf("Hello, world!n");
return 0;
}
hello.c
$ gcc -o hello hello.c
$ ls
hello* hello.c
$ ./hello
Hello, world!
$
compile
execute
More complex C++ apps
Shared libraries (*.so files)
Objects which are built from
only classes/functions.
Header files (*.h)
Definition I/F of classes, functions…
+
Shared object file (*.so)
Built binary of classes, functions…
How to link to .so file?
application
Static link
include libs inside
the application
application
Dynamic link
Use libraries directly
from the application.
While compiling, header files are used to get
I/F of classes/functions of libraries.
Complex applications
PHP
Ex. php
…
It used many libs.
libxml2.so libkrb5.so
$ ldd `which php` | wc -l
43
$
In my case, 43 libs
are used.
$ otool -L `which php` (on OSX)
PHP
Ex. php
…
You need to check every libs(headers) are
exists for each extensions.
libxml2.so libkrb5.so
In my case, 43 libs
are used.
Too Heavy !!
$ ldd `which php` | wc -l
43
$
$ otool -L `which php` (on OSX)
It used many libs.
Complex applications
More complex C++ apps (4)
Make
Configure
Great task runner. Love it.
(BSD) make, GNU make (gmake)
$ make
$ make install
Check environment of the system.
- checking libs and its versions.
- create Makefile for your option.
GNU Autotools
Tools to create configure scripts for your
applications. It’s too troublesome to
create ‘configure’ by yourself.
Okay, I’m ready to start

(Go fast..)
Preparation (fix spec)
PHP
Version : 5.4.44
Modules
DSO style.
prefix : /usr/local
gd : disable
intl : enable
pear : /usr/local/lib/php
pdo : enable
mysql : enable
mbstring : enabled
mbregex : enable
Preparation (for Vagrant)
$ vagrant sandbox status
[default] Sandbox mode is on
$ vagrant sandbox rollback
[default] Rolling back the virtual machine...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
$ vagrant sandbox status
[default] Sandbox mode is on
$
check ‘sandbox mode is ON’
Rollback your vagrant machine to
pure vagrant, if you’ve already
modified it.
Preparation (httpd, mysqld)
To test PHP build,
Install MySQL, httpd(apache2) by
package manager.
[vagrant@vagrant-centos65 ~]$ sudo yum install mysql
mysql-server httpd httpd-devel
Login: Vagrant machine
$ vagrant ssh
Last login: Thu Dec 10 01:57:16 2015 from 10.0.2.2
[vagrant@vagrant-centos65 ~]$
Build (get php tarball)
[vagrant@vagrant-centos65 ~]$ mkdir tmp
[vagrant@vagrant-centos65 ~]$ cd tmp
[vagrant@vagrant-centos65 tmp]$ sudo yum install wget
Loaded plugins: fastestmirror, versionlock
Determining fastest mirrors
epel/metalink | 4.9 kB 00:00
:
Installed size: 1.8 M
Is this ok [y/N]: y
:
Complete!
[vagrant@vagrant-centos65 tmp]$ wget http://sg2.php.net/
distributions/php-5.4.44.tar.gz
[vagrant@vagrant-centos65 tmp]$ ls -al php-5.4.44.tar.gz
-rw-rw-r-- 1 vagrant vagrant 15878182 Aug 6 23:00
php-5.4.44.tar.gz
[vagrant@vagrant-centos65 tmp]$
get tarball
Build (unarchive)
[vagrant@vagrant-centos65 tmp]$ gzip -d php-5.4.44.tar.gz
[vagrant@vagrant-centos65 tmp]$ ls -al php-5.4.44.tar*
-rw-rw-r-- 1 vagrant vagrant 107755008 Aug 6 23:00 php-5.4.44.tar
[vagrant@vagrant-centos65 tmp]$ tar xvf php-5.4.44.tar
php-5.4.44/
php-5.4.44/.gdbinit
php-5.4.44/.gitattributes
:
php-5.4.44/build/scan_makefile_in.awk
php-5.4.44/build/shtool
[vagrant@vagrant-centos65 tmp]$
Unarchive (please learn gzip/tar)
or
[vagrant@vagrant-centos65 tmp]$ tar zxvf php-5.4.44.tar.gz
php-5.4.44/
php-5.4.44/.gdbinit
php-5.4.44/.gitattributes
:
php-5.4.44/build/scan_makefile_in.awk
php-5.4.44/build/shtool
[vagrant@vagrant-centos65 tmp]$
Build (check configure options)
[vagrant@vagrant-centos65 php-5.4.44]$ ./configure --help > conf.list
[vagrant@vagrant-centos65 php-5.4.44]$ less conf.list
Get option list
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
:
:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]
:
:
PEAR:
--with-pear=DIR Install PEAR in DIR [PREFIX/lib/php]
--without-pear Do not install PEAR
:
:
CXXCPP C++ preprocessor
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
Report bugs to the package provider.
Build (configure options)
configure options
$configure 
--with-apxs2 
--prefix=/usr/local 
--with-mysql 
--enable-intl 
--with-pear=/usr/local/lib/php 
--enable-mbstring 
--enable-mbregex 2>&1 | tee 00congif.log
$configure 
--with-apxs2 
--with-mysql 
--enable-intl 
--enable-mbstring 
--enable-mbregex 2>&1 | tee 00config.log
Build (configure-1 )
[vagrant@vagrant-centos65 php-5.4.44]$ ./configure --with-apxs2 --
with-mysql --enable-intl --enable-mbstring --enable-mbregex 2>&1 |
tee 00config.log
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
:
checking libxml2 install dir... no
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2
installation.
[vagrant@vagrant-centos65 php-5.4.44]$
You need “libxml2”.
Try configure with your option
[vagrant@vagrant-centos65 tmp]$ sudo yum install libxml2 libxml2-devel
Loaded plugins: fastestmirror, versionlock
:
Total download size: 8.6 M
Is this ok [y/N]: y
Downloading Packages:
:
Complete!
[vagrant@vagrant-centos65 tmp]$
Build (configure-2 )
Search “libxml2” in yum packages.
[vagrant@vagrant-centos65 tmp]$ sudo yum search libxml2
Loaded plugins: fastestmirror, versionlock
:
libxml2.x86_64 : Library providing XML and HTML support
libxml2.i686 : Library providing XML and HTML support
libxml2-devel.i686 : Libraries, includes, etc. to develop XML and HTML applications
libxml2-devel.x86_64 : Libraries, includes, etc. to develop XML and HTML applications
:
Name and summary matches only, use "search all" for everything.
[vagrant@vagrant-centos65 tmp]$
Install the lib and devel packages.
Build (configure-2 )
Try repeatedly until success.
[vagrant@vagrant-centos65 php-5.4.44]$ ./configure --with-apxs2 --
with-mysql --enable-intl --enable-mbstring --enable-mbregex 2>&1 |
tee 00config.log
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
:
Thank you for using PHP.
config.status: creating php5.spec
:
config.status: executing default commands
[vagrant@vagrant-centos65 php-5.4.44]$
libxml2
libxml2-devel
icu
libicu-devel
Required packages
Build (make )
Compile and link.
[vagrant@vagrant-centos65 php-5.4.44]$ make 2>&1 | tee 01make.log
/bin/sh /home/vagrant/tmp/php-5.4.44/libtool --silent --preserve-dup-
deps --mode=compile cc -Iext/date/lib -Iext/date/ -I/home/vagrant/tmp/
php-5.....
:
:
:
:
:
:
:
:
:
Build complete.
Don't forget to run 'make test'.
[vagrant@vagrant-centos65 php-5.4.44]$
It takes minutes.
Have a break.
Build (make install )
Install binaries and libraries.
[vagrant@vagrant-centos65 php-5.4.44]$ sudo make install 2>&1 | tee 02install.log
Installing PHP SAPI module: apache2handler
:
libtool: install: cp .libs/libphp5.so /usr/lib64/httpd/modules/libphp5.so
:
Installing PHP CLI binary: /usr/local/bin/
:
Installing PDO headers: /usr/local/include/php/ext/pdo/
[vagrant@vagrant-centos65 php-5.4.44]$
check
[vagrant@vagrant-centos65 php-5.4.44]$ ls -al /usr/lib64/httpd/modules/libphp5.so
-rwxr-xr-x 1 root root 253886 Dec 10 06:16 /usr/lib64/httpd/modules/libphp5.so
[vagrant@vagrant-centos65 php-5.4.44]$ php -v
PHP 5.4.44 (cli) (built: Dec 10 2015 06:03:36)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
[vagrant@vagrant-centos65 php-5.4.44]$
Note) please do ‘make test’ before install.
Now You know...
1. Required applications (packages)
- mysql, mysql-server
- httpd, httpd-devel
2. Required libraries (packages)
- libxml2, libxml2-devel
- icu, libicu-devel
3. Commands to install PHP.
What’s Idempotence?
How to install version
specified application
How to build ‘tarball’?
How to create playbooks?
AGENDA
Rollback
$ vagrant sandbox rollback
[default] Rolling back the virtual machine...
0%...10%...20%...30%...40%...50%...60%...70%...80%...
90%...100%
0%...10%...20%...30%...40%...50%...60%...70%...80%...
90%...100%
$ vagrant sandbox status
[default] Sandbox mode is on
$
Your vagrant is rollbacked.
- no httpd, mysqld, httpd.
structure
setup.yml
httpd.yml
mysqld.yml
php.yml
include
include
include
hosts
Vagrantfile
:
:
# Ansible
config.vm.provision "ansible" do |ansible|
ansible.playbook = "./setup.yml"
ansible.inventory_path = "./hosts"
ansible.limit = "httpd-server"
end

:
:
./Vagrantfile
‘./setup.yml’, ‘./hosts’ will be loaded.
Create playbooks (preparation-1)
# setup httpd
- include: playbooks/httpd.yml
# setup mysql
- include: playbooks/mysqld.yml
# setup php
- include: playbooks/php.yml
./setup.yml
[httpd-server]
192.168.33.50
./hosts
IP address of your Vagrant machine
Create playbooks (preparation-2)
httpd.yml - hosts: httpd-server
become: yes
tasks:
- name: install httpd yum packages
yum: name={{ item }} state=latest
with_items:
- httpd
- httpd-devel
- name: be sure httpd is running and enabled
service: name=httpd state=started enabled=yes
mysqld.yml - hosts: httpd-server
become: yes
tasks:
- name: install mysql yum packages
yum: name={{ item }} state=latest
with_items:
- mysql
- mysql-server
- name: be sure httpd is running and enabled
service: name=mysqld state=started enabled=yes
Create playbooks (php)
1. install related packages
2. create work directory
3. get a tarball
4. unarchive tarball
5. configure source
6. make source
7. make install source
A
B
D
C
step by step !
Create playbooks (php :A)
- hosts: httpd-server
vars:
src_url: 'http://sg2.php.net/distributions/php-5.4.44.tar.gz'
src_file: 'php-5.4.44.tar.gz'
src_dir: '/home/vagrant/src'
build_dir: '/home/vagrant/src/php-5.4.44'
tasks:
- name: "PHP:install related packages"
become: yes
yum: name=wget state=latest
yum: name={{ item }} state=latest
with_items:
- wget
- libxml2
- libxml2-devel
- icu
- libicu-devel
- name: "PHP:make build dir"
file: dest={{src_dir}} state=directory
$ vagrant provision
Create playbooks (php :B)
:
:
- name: "PHP:check local source"
command: ls -l {{src_dir}}/{{src_file}}
register: src_exist
ignore_errors: True
- name: "PHP:wget the php source"
get_url: url={{src_url}} dest={{src_dir}}
when: src_exist|failed
$ vagrant provision
Create playbooks (php :C)
- hosts: httpd-server
vars:
:
php_dso_file: '/usr/lib64/httpd/modules/libphp5.so'
:
tasks:
:
- name: "PHP:check DSO"
command: ls -l {{php_dso_file}}
register: dso_exist
ignore_errors: True
- name: "PHP:unarchive source"
command: chdir={{src_dir}} tar zxvf {{src_file}}
when: dso_exist|failed
$ vagrant provision
Create playbooks (php :D)
- hosts: httpd-server
vars:
:
configure_opt: '--with-apxs2 --with-mysql --enable-intl --enable-
mbstring --enable-mbregex'
:
tasks:
:
- name: "PHP:configure"
command: chdir={{build_dir}} ./configure {{configure_opt}}
when: dso_exist|failed
- name: "PHP:make"
command: chdir={{build_dir}} make
when: dso_exist|failed
- name: “PHP:make install"
become: yes
command: chdir={{build_dir}} make install
when: dso_exist|failed
$ vagrant provision
:
PLAY RECAP ********************************************************************
192.168.33.50 : ok=15 changed=6 unreachable=0 failed=0
$
You Got It !
success
Homework
B. put your own ‘php.ini’, ‘httpd.conf’ by
Ansible playbook.
- Note) Use ‘copy’ or ‘template’ modules.
- http://docs.ansible.com/ansible/copy_module.html
- http://docs.ansible.com/ansible/template_module.html
A. Learn UNIX(SystemV) commands.
- ldconfig
- ldd (on OSX, ‘otools -L’)
C. Restart httpd after php installation

More Related Content

DevOps(4) : Ansible(2) - (MOSG)

  • 1. DevOps (4) - Ansible (2) — Soshi Nemoto Mulodo Vietnam Co., Ltd.
  • 2. Our Purpose Make ourselves ‘Business partner’ from ‘factory’. Points Engineering knowledge <- * TODAY * Logical Thinking Co-operation work — Study Group —
  • 3. What’s DevOps? Mindset of filling gap between Dev and Ops. It’s not any technologies or solutions. C.A.M.S Culture Bust silos. Don’t say “no”. Involve everyone. Automation XXX as Code. Ask machines to do same things. Metrics monitor, find failure, Improve, make a plan. Share Dev->Ops, Ops->Dev, share metrics. Feedback of previous study
  • 4. Feedback of previous study (2) What’s Vagrant? manager of Virtual Machines Vagrant can manage … Virtual Box VMware (Fusion) AWS EC2 …. Trigger of automation engine. Vagrant run … Ansible Chef Puppet ….
  • 5. Feedback of previous study (3) What’s ansible? A radically simple IT automation engine for ‘infrastructure as Code’… “Ask machines to do SAME things” Trial Simple usage (hosts and playbook) Set in Vagrantfile
  • 6. Ansible (2) A radically simple IT automation engine
  • 7. What’s Idempotence? How to install version specified application AGENDA
  • 8. What’s Idempotence? The property that can be applied multiple times without changing the result beyond the initial application. (wikipedia) Ansible is idempotence !?
  • 9. What’s Idempotence? The property that can be applied multiple times without changing the result beyond the initial application. (wikipedia) Ansible is idempotence !? Ansible playbook should be idempotence.
  • 10. Why do you learn Ansible here? DevOps -> Automation (C.A.M.S.)
  • 11. Why do you learn Ansible here? DevOps -> Automation (C.A.M.S.) Automation Infrastructure as Code. Clarify specification. - playbook Guarantee same result. - Idempotence
  • 12. Why do you learn Ansible here? DevOps -> Automation (C.A.M.S.) Automation Infrastructure as Code. Clarify specification. - playbook Guarantee same result. - Idempotence
  • 13. Why do you learn Ansible here? DevOps -> Automation (C.A.M.S.) Automation Infrastructure as Code. Clarify specification. - playbook Guarantee same result. - Idempotence You need to check results carefully for each operation, if it is not guaranteed to get same result when you do it repeatedly.
  • 15. What’s Idempotence? How to install version specified application How to build ‘tarball’? How to create playbooks? AGENDA
  • 16. Application Server applications is NOT gifts from Buddha. Server application is NOT packages of YUM/Apt/RPM. Almost server apps are only C/C++ applications. You can install Apps without Package manager.
  • 17. How to make C/C++ apps? #include "stdio.h" int main(int argc, char *argv[]) { printf("Hello, world!n"); return 0; } hello.c $ gcc -o hello hello.c $ ls hello* hello.c $ ./hello Hello, world! $ compile execute
  • 18. More complex C++ apps Shared libraries (*.so files) Objects which are built from only classes/functions. Header files (*.h) Definition I/F of classes, functions… + Shared object file (*.so) Built binary of classes, functions…
  • 19. How to link to .so file? application Static link include libs inside the application application Dynamic link Use libraries directly from the application. While compiling, header files are used to get I/F of classes/functions of libraries.
  • 20. Complex applications PHP Ex. php … It used many libs. libxml2.so libkrb5.so $ ldd `which php` | wc -l 43 $ In my case, 43 libs are used. $ otool -L `which php` (on OSX)
  • 21. PHP Ex. php … You need to check every libs(headers) are exists for each extensions. libxml2.so libkrb5.so In my case, 43 libs are used. Too Heavy !! $ ldd `which php` | wc -l 43 $ $ otool -L `which php` (on OSX) It used many libs. Complex applications
  • 22. More complex C++ apps (4) Make Configure Great task runner. Love it. (BSD) make, GNU make (gmake) $ make $ make install Check environment of the system. - checking libs and its versions. - create Makefile for your option. GNU Autotools Tools to create configure scripts for your applications. It’s too troublesome to create ‘configure’ by yourself.
  • 23. Okay, I’m ready to start
 (Go fast..)
  • 24. Preparation (fix spec) PHP Version : 5.4.44 Modules DSO style. prefix : /usr/local gd : disable intl : enable pear : /usr/local/lib/php pdo : enable mysql : enable mbstring : enabled mbregex : enable
  • 25. Preparation (for Vagrant) $ vagrant sandbox status [default] Sandbox mode is on $ vagrant sandbox rollback [default] Rolling back the virtual machine... 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% $ vagrant sandbox status [default] Sandbox mode is on $ check ‘sandbox mode is ON’ Rollback your vagrant machine to pure vagrant, if you’ve already modified it.
  • 26. Preparation (httpd, mysqld) To test PHP build, Install MySQL, httpd(apache2) by package manager. [vagrant@vagrant-centos65 ~]$ sudo yum install mysql mysql-server httpd httpd-devel Login: Vagrant machine $ vagrant ssh Last login: Thu Dec 10 01:57:16 2015 from 10.0.2.2 [vagrant@vagrant-centos65 ~]$
  • 27. Build (get php tarball) [vagrant@vagrant-centos65 ~]$ mkdir tmp [vagrant@vagrant-centos65 ~]$ cd tmp [vagrant@vagrant-centos65 tmp]$ sudo yum install wget Loaded plugins: fastestmirror, versionlock Determining fastest mirrors epel/metalink | 4.9 kB 00:00 : Installed size: 1.8 M Is this ok [y/N]: y : Complete! [vagrant@vagrant-centos65 tmp]$ wget http://sg2.php.net/ distributions/php-5.4.44.tar.gz [vagrant@vagrant-centos65 tmp]$ ls -al php-5.4.44.tar.gz -rw-rw-r-- 1 vagrant vagrant 15878182 Aug 6 23:00 php-5.4.44.tar.gz [vagrant@vagrant-centos65 tmp]$ get tarball
  • 28. Build (unarchive) [vagrant@vagrant-centos65 tmp]$ gzip -d php-5.4.44.tar.gz [vagrant@vagrant-centos65 tmp]$ ls -al php-5.4.44.tar* -rw-rw-r-- 1 vagrant vagrant 107755008 Aug 6 23:00 php-5.4.44.tar [vagrant@vagrant-centos65 tmp]$ tar xvf php-5.4.44.tar php-5.4.44/ php-5.4.44/.gdbinit php-5.4.44/.gitattributes : php-5.4.44/build/scan_makefile_in.awk php-5.4.44/build/shtool [vagrant@vagrant-centos65 tmp]$ Unarchive (please learn gzip/tar) or [vagrant@vagrant-centos65 tmp]$ tar zxvf php-5.4.44.tar.gz php-5.4.44/ php-5.4.44/.gdbinit php-5.4.44/.gitattributes : php-5.4.44/build/scan_makefile_in.awk php-5.4.44/build/shtool [vagrant@vagrant-centos65 tmp]$
  • 29. Build (check configure options) [vagrant@vagrant-centos65 php-5.4.44]$ ./configure --help > conf.list [vagrant@vagrant-centos65 php-5.4.44]$ less conf.list Get option list `configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... : : --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] : : PEAR: --with-pear=DIR Install PEAR in DIR [PREFIX/lib/php] --without-pear Do not install PEAR : : CXXCPP C++ preprocessor Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider.
  • 30. Build (configure options) configure options $configure --with-apxs2 --prefix=/usr/local --with-mysql --enable-intl --with-pear=/usr/local/lib/php --enable-mbstring --enable-mbregex 2>&1 | tee 00congif.log $configure --with-apxs2 --with-mysql --enable-intl --enable-mbstring --enable-mbregex 2>&1 | tee 00config.log
  • 31. Build (configure-1 ) [vagrant@vagrant-centos65 php-5.4.44]$ ./configure --with-apxs2 -- with-mysql --enable-intl --enable-mbstring --enable-mbregex 2>&1 | tee 00config.log checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E : checking libxml2 install dir... no checking for xml2-config path... configure: error: xml2-config not found. Please check your libxml2 installation. [vagrant@vagrant-centos65 php-5.4.44]$ You need “libxml2”. Try configure with your option
  • 32. [vagrant@vagrant-centos65 tmp]$ sudo yum install libxml2 libxml2-devel Loaded plugins: fastestmirror, versionlock : Total download size: 8.6 M Is this ok [y/N]: y Downloading Packages: : Complete! [vagrant@vagrant-centos65 tmp]$ Build (configure-2 ) Search “libxml2” in yum packages. [vagrant@vagrant-centos65 tmp]$ sudo yum search libxml2 Loaded plugins: fastestmirror, versionlock : libxml2.x86_64 : Library providing XML and HTML support libxml2.i686 : Library providing XML and HTML support libxml2-devel.i686 : Libraries, includes, etc. to develop XML and HTML applications libxml2-devel.x86_64 : Libraries, includes, etc. to develop XML and HTML applications : Name and summary matches only, use "search all" for everything. [vagrant@vagrant-centos65 tmp]$ Install the lib and devel packages.
  • 33. Build (configure-2 ) Try repeatedly until success. [vagrant@vagrant-centos65 php-5.4.44]$ ./configure --with-apxs2 -- with-mysql --enable-intl --enable-mbstring --enable-mbregex 2>&1 | tee 00config.log checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E : Thank you for using PHP. config.status: creating php5.spec : config.status: executing default commands [vagrant@vagrant-centos65 php-5.4.44]$ libxml2 libxml2-devel icu libicu-devel Required packages
  • 34. Build (make ) Compile and link. [vagrant@vagrant-centos65 php-5.4.44]$ make 2>&1 | tee 01make.log /bin/sh /home/vagrant/tmp/php-5.4.44/libtool --silent --preserve-dup- deps --mode=compile cc -Iext/date/lib -Iext/date/ -I/home/vagrant/tmp/ php-5..... : : : : : : : : : Build complete. Don't forget to run 'make test'. [vagrant@vagrant-centos65 php-5.4.44]$ It takes minutes. Have a break.
  • 35. Build (make install ) Install binaries and libraries. [vagrant@vagrant-centos65 php-5.4.44]$ sudo make install 2>&1 | tee 02install.log Installing PHP SAPI module: apache2handler : libtool: install: cp .libs/libphp5.so /usr/lib64/httpd/modules/libphp5.so : Installing PHP CLI binary: /usr/local/bin/ : Installing PDO headers: /usr/local/include/php/ext/pdo/ [vagrant@vagrant-centos65 php-5.4.44]$ check [vagrant@vagrant-centos65 php-5.4.44]$ ls -al /usr/lib64/httpd/modules/libphp5.so -rwxr-xr-x 1 root root 253886 Dec 10 06:16 /usr/lib64/httpd/modules/libphp5.so [vagrant@vagrant-centos65 php-5.4.44]$ php -v PHP 5.4.44 (cli) (built: Dec 10 2015 06:03:36) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies [vagrant@vagrant-centos65 php-5.4.44]$ Note) please do ‘make test’ before install.
  • 36. Now You know... 1. Required applications (packages) - mysql, mysql-server - httpd, httpd-devel 2. Required libraries (packages) - libxml2, libxml2-devel - icu, libicu-devel 3. Commands to install PHP.
  • 37. What’s Idempotence? How to install version specified application How to build ‘tarball’? How to create playbooks? AGENDA
  • 38. Rollback $ vagrant sandbox rollback [default] Rolling back the virtual machine... 0%...10%...20%...30%...40%...50%...60%...70%...80%... 90%...100% 0%...10%...20%...30%...40%...50%...60%...70%...80%... 90%...100% $ vagrant sandbox status [default] Sandbox mode is on $ Your vagrant is rollbacked. - no httpd, mysqld, httpd.
  • 40. Vagrantfile : : # Ansible config.vm.provision "ansible" do |ansible| ansible.playbook = "./setup.yml" ansible.inventory_path = "./hosts" ansible.limit = "httpd-server" end
 : : ./Vagrantfile ‘./setup.yml’, ‘./hosts’ will be loaded.
  • 41. Create playbooks (preparation-1) # setup httpd - include: playbooks/httpd.yml # setup mysql - include: playbooks/mysqld.yml # setup php - include: playbooks/php.yml ./setup.yml [httpd-server] 192.168.33.50 ./hosts IP address of your Vagrant machine
  • 42. Create playbooks (preparation-2) httpd.yml - hosts: httpd-server become: yes tasks: - name: install httpd yum packages yum: name={{ item }} state=latest with_items: - httpd - httpd-devel - name: be sure httpd is running and enabled service: name=httpd state=started enabled=yes mysqld.yml - hosts: httpd-server become: yes tasks: - name: install mysql yum packages yum: name={{ item }} state=latest with_items: - mysql - mysql-server - name: be sure httpd is running and enabled service: name=mysqld state=started enabled=yes
  • 43. Create playbooks (php) 1. install related packages 2. create work directory 3. get a tarball 4. unarchive tarball 5. configure source 6. make source 7. make install source A B D C step by step !
  • 44. Create playbooks (php :A) - hosts: httpd-server vars: src_url: 'http://sg2.php.net/distributions/php-5.4.44.tar.gz' src_file: 'php-5.4.44.tar.gz' src_dir: '/home/vagrant/src' build_dir: '/home/vagrant/src/php-5.4.44' tasks: - name: "PHP:install related packages" become: yes yum: name=wget state=latest yum: name={{ item }} state=latest with_items: - wget - libxml2 - libxml2-devel - icu - libicu-devel - name: "PHP:make build dir" file: dest={{src_dir}} state=directory $ vagrant provision
  • 45. Create playbooks (php :B) : : - name: "PHP:check local source" command: ls -l {{src_dir}}/{{src_file}} register: src_exist ignore_errors: True - name: "PHP:wget the php source" get_url: url={{src_url}} dest={{src_dir}} when: src_exist|failed $ vagrant provision
  • 46. Create playbooks (php :C) - hosts: httpd-server vars: : php_dso_file: '/usr/lib64/httpd/modules/libphp5.so' : tasks: : - name: "PHP:check DSO" command: ls -l {{php_dso_file}} register: dso_exist ignore_errors: True - name: "PHP:unarchive source" command: chdir={{src_dir}} tar zxvf {{src_file}} when: dso_exist|failed $ vagrant provision
  • 47. Create playbooks (php :D) - hosts: httpd-server vars: : configure_opt: '--with-apxs2 --with-mysql --enable-intl --enable- mbstring --enable-mbregex' : tasks: : - name: "PHP:configure" command: chdir={{build_dir}} ./configure {{configure_opt}} when: dso_exist|failed - name: "PHP:make" command: chdir={{build_dir}} make when: dso_exist|failed - name: “PHP:make install" become: yes command: chdir={{build_dir}} make install when: dso_exist|failed $ vagrant provision
  • 48. : PLAY RECAP ******************************************************************** 192.168.33.50 : ok=15 changed=6 unreachable=0 failed=0 $ You Got It ! success
  • 49. Homework B. put your own ‘php.ini’, ‘httpd.conf’ by Ansible playbook. - Note) Use ‘copy’ or ‘template’ modules. - http://docs.ansible.com/ansible/copy_module.html - http://docs.ansible.com/ansible/template_module.html A. Learn UNIX(SystemV) commands. - ldconfig - ldd (on OSX, ‘otools -L’) C. Restart httpd after php installation