Saturday, September 16, 2017

Working with Chef

Idea is to explore Chef and it's working, in order to do so was trying to deploy Zabbix monitoring tool,  Hence main focus is to check more on Chef instead of Zabbix tool.

Zabbix is another tool for monitoring Server / Devices in the network, the basic idea is simple there will be one server responsible for collecting, storing, analyzing and reporting various data points and there will be an agent which needs to install on each of Server / VMs which we need to monitor. Now the best part is its claim that data points are huge set starting from simple CPU / Memory to file and n/w throughput. This essentially allows multiple possibilities.

Server installation though was straightforward there was still some issue, even-though eventually it did turn on not sure how last error got resolved.

Zabbix server consists of Database and Front-end module, For this demo we used MySQL.

To try out the complete scenario I'm using RHEL 7.1 installed as VM using Oracle Virtual box.

Since will need connectivity to the Internet and some time VPN is essential I always prefer dual network setup,  First is NAT and second is a Host-Only adapter.

Even for NAT, I'm using DHCP server, Same goes with 'Host-Only adapter'.






Zabbix Server installation Instructions:
1.       Add Zabbix Repo
2.       Install packages
yum install zabbix-server-mysql zabbix-web-mysql
 Since Centos 7 doesn’t install mysql by default we will have to do it
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update
sudo yum install mysql-server
sudo systemctl start mysqld
To get required access
sudo mysql_secure_installation
3.       Configure MySQL
shell> mysql -uroot -p<root_password>
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by '<password>';
mysql> quit;

Issues
Here comes big issue, post-deployment Front-end was not coming up
1.       Recheck MySQL connectivity, SELinux, and firewall
Post restart service came up, still not sure what was issue
2.       Once Front end comes up it check pre-requisites
Issue over there was php modules were not getting loaded.
Ideally php.ini should include installed modules but that was not case,
Hence added following data in file manually
[root@zabbsrv ~]# cat /etc/php.ini
extension=mysql.so
extension=mysqli.so
extension=bcmath.so
extension=mbstring.so
extension=gd.so
extension=dom.so
extension=xmlwriter.so
extension=xmlreader.so
extension=ldap.so



Writing actual Chef Code
Chef generate cookbook zabbix_agent
This generate skeleton for our code now we can go ahead and add some recipes
Here is my receipes/default.rb
include_recipe "#{cookbook_name}::pre-req"
That’s it
For my pre-req file have tried couple of different items:
1.       Using bash:
bash 'install_something' do
  user 'root'
  cwd '/tmp'
  code <<-EOH
  rm -rf /tmp/test.err
  rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm >>/tmp/test.foo 2>>/tmp/test.err
  grep "is already installed" /tmp/test.err
  EOH
  #ignore_failure true
end

2.       Using yum repo
yum_repository 'zabbix' do
  description "Zabbix repo"
  baseurl zabbix_repo
  gpgkey zabbix_gpg
  action :create
end
3.       Using rpm
rpm_package 'zabbix-release' do
        allow_downgrade false
        action :upgrade
        #source 'http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm'
        source zabbix_rpm
end

yum_package 'zabbix-agent' do
        allow_downgrade false
        action :upgrade
end
To test these have used chef-solo, by creating knife.rb file.

Rpm method looks simple and easy,
Here is brief description on chef
In chef all actions are performed on resources, e.g. rpm_pacakge is resource type.
Action we will perform on it will be ‘upgrade’
Its source is ‘<actual location>’

Core coding will be if we work on resource which is not their however basic resource list is quite huge
https://docs.chef.io/resource.html
                                



No comments:

Post a Comment