How to Install Web Server with MySQL database and PHP (Installing LAMP stack with puppet)
Requirement
You want to install a Web Server alongwith MySQL database and the powerful and most famous PHP programming language, popularly known as a LAMP stack!
Surely, you could do this manually by installing packages one by one for few machines. In case you have many machines to build with a LAMP stack, then use Puppet. I will show you how to do this build by automating using the powerful Puppet tool.
Pre-requisite
RHEL 6.4
YUM repository configured and working properly
A working Puppet Server
A working Puppet Client (there is an article I wrote in this blog)
Start!
On your puppet client follow below steps:
# mkdir -p /etc/puppet/modules/lamp/manifests
# vi /etc/puppet/modules/lamp/manifests/init.pp
class lamp {
# install httpd package
package { 'httpd':
ensure => installed,
}
# ensure httpd service is running
service { 'httpd':
ensure => running,
}
# install mysql-server package
package { 'mysql-server':
ensure => installed,
}
# ensure mysql service is running
service { 'mysqld':
ensure => running,
}
# install php package
package { 'php':
ensure => installed,
}
# ensure info.php file exists
file { '/var/www/html/info.php':
ensure => file,
content => '', # phpinfo code
require => Package['httpd'], # require 'httpd' package before creating
}
}
# install httpd package
package { 'httpd':
ensure => installed,
}
# ensure httpd service is running
service { 'httpd':
ensure => running,
}
# install mysql-server package
package { 'mysql-server':
ensure => installed,
}
# ensure mysql service is running
service { 'mysqld':
ensure => running,
}
# install php package
package { 'php':
ensure => installed,
}
# ensure info.php file exists
file { '/var/www/html/info.php':
ensure => file,
content => '', # phpinfo code
require => Package['httpd'], # require 'httpd' package before creating
}
}
Your basic lamp module is ready. All you need now is to create a manifest, which is nothing but few lines which will install the module.
#
vi /etc/puppet/manifests/site.ppnode default { }
node 'hostname of your client' {
include lamp
}
Save this file and run below command to test you lamp module.# puppet agent --test
[root@puppetclient02 puppet]# puppet agent --test
info: Creating a new SSL certificate request for puppetclient02.likwid.com
info: Certificate Request fingerprint (SHA256): 27:8E:58:F7:2B:85:87:59:1F:BC:BE:60:46:BE:C6:C6:0D:38:30:11:7E:22:D6:C6:54:77:63:98:77:B2:93:70
A new SSL certificate is automatically generated and sent to your Puppet master server. Now you should sign this certificate from your server side.
Login to you Puppet server and issue below command:# puppet cert list --all
[root@puppet02 manifests]# puppet cert list --all
"puppetclient02.likwid.com" (D7:48:67:F2:B2:63:1A:BD:79:5B:F4:BC:C3:CE:4C:7A)
+ "puppet02.likwid.com" (62:B1:87:04:4E:B1:3A:D2:04:4D:D1:5F:B5:06:EB:0A) (alt names: "DNS:puppet", "DNS:puppet.likwid.com", "DNS:puppet02.likwid.com")
You will see list of certificates, you should recognize your client hostname which is waiting to be signed. Sign the certificate with below command:
[root@puppet02 manifests]# puppet cert sign puppetclient02.likwid.com
notice: Signed certificate request for puppetclient02.likwid.com
notice: Removing file Puppet::SSL::CertificateRequest puppetclient02.likwid.com at '/var/lib/puppet/ssl/ca/requests/puppetclient02.likwid.com.pem'
Login to your puppet client server, after SSL certificate is signed, again run below command:
# puppet agent --test
[root@puppetclient02 puppet]# puppet agent --test
info: Retrieving plugin
err: /File[/var/lib/puppet/lib]: Could not evaluate: Could not retrieve information from environment production source(s) puppet://puppet02.likwid.com/plugins
info: Caching catalog for puppetclient02.likwid.com
info: Applying configuration version '1428774567'
notice: /Stage[main]/Lamp/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
info: /Stage[main]/Lamp/Service[mysqld]: Unscheduling refresh on Service[mysqld]
notice: Finished catalog run in 3.94 seconds
You should see an output something like above, because it will be a different output if for example you have httpd already installed, or mysql was stopped, it will be started and so on.If you have done everything as I told you above, your web server should be ready, test it by pointing your browser at you puppet client hostname/info.phpTest link is: http://puppetclient02/info.phpand you will see the php information page ready for you! All the packages installed automatically by puppet. It could even start the services in stopped state and maintain the web server in working condition.Thanks for following upto here, and cheers!
Comments
Post a Comment