Saturday, 5 August 2017

EX405 - Red Hat Certificate of Expertise in Configuration Management with Puppet

As per Red Hat Training team (08/05/2017):
The Red Hat Enterprise Linux version for DO405 is RHEL 7,Satellite version is 6 and Puppet version is 3.
....thanks a lot for the info about the minor version....

From Red Hat website Ex405 :Red Hat Certificate of Expertise in Configuration Management with Puppet

Study points for the exam

To help you prepare, the exam objectives highlight the task areas you can expect to see covered in the exam. Red Hat reserves the right to add, modify, and remove exam objectives. Such changes will be made public in advance.
Candidates should be able to perform these tasks:
  • Install and configure Puppet.
  • Create and maintain Puppet manifests.
    • Create new Puppet manifests.
    • Debug existing Puppet manifests.
  • Create Puppet modules.
    • Create reusable modules.
    • Create modules with classes, name spaces, variables, and conditionals.
    • Create modules that install software on target nodes and deploy configuration files.
  • Use facter to obtain system information.
    • Create custom facts.
    • Use facts to change Puppet behavior.
  • Create Git repositories.
    • Create and perform simple management of a Git repository.
    • Add files to a Git repository.
    • Apply changes and commit changed files to a Git repository.
  • Implement Puppet in a Red Hat Satellite 6 environment.
As with all Red Hat performance-based exams, configurations must persist after restart without intervention.

Install Puppet Server:

# firewall-cmd --permanent --add-service=https
# firewall-cmd --permanent --add-port={8140/tcp,61613/tcp}
# firewall-cmd --reload
  • Add your FQDN into /etc/hosts
  • Unzip the install and from the folder run
# ./puppet-enterprise-installer
  • After confirming the Install you'll be asked to open a browser and connect to https://<puppetmaster-hostname>:3000 to continue the install
  • Select Monolithic install (all in one server) and follow the instructions

Install Puppet nodes:

  • Download and Install the Puppet Agent from the PuppetMaster by running the following on your node:
# curl -k https://<puppetmaster-hostname>:8140/packages/current/install.bash | sudo bash
  • Once installed the agent won't work until his certificate is signed.

Register Puppet nodes to a Puppet server:

  •  Go to the PuppetMaster and note on the TOP RIGHT "1 Node Request" 

  • Click on "1 Node Request" and then "Accept" the node
  • Test the agent by running
# puppet agent -t

Create new Puppet manifests:

  •  On the PuppetMaster go to the modules dir 
# cd /etc/puppetlabs/puppet/environments/production/modules/
  • Create a basic module structure
# mkdir -p helloworld/manifest
# cd helloworld/manifest
# vi init.pp

class helloworld{

  notify { 'hello, world!': }

}
 

# vi motd.pp

class helloworld::motd{

file{ '/etc/motd':
  owner   => 'root',
  group   => 'root',
  mode    => 0644,
  content => "hello, world!\n",
  }
}



Tuesday, 17 January 2017

No memory cache has been configured.


To fix this error make sure you have latest php5-apcu installed:

sudo apt-get install php5-apcu

edit config.php

sudo vi /nextcloud/config/config.php

add the following line in your directive

'memcache.local' => '\OC\Memcache\APCu',

restart the webserver

sudo service nginx restart

php does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.

To fix this error edit php5-fpm config file

sudo vi /etc/php5/fpm/pool.d/www.conf

uncomment the following line


env[PATH] = /usr/local/bin:/usr/bin:/bin

and restart php5-fpm

sudo service php5-fpm restart

Thursday, 29 December 2016

RPI - Dynamic IP address

Create your own website using a Free Dynamic DNS service ( I used NoIP)

Once registered and installed the client on your Raspberry Pi you can create a startup script to automatically restart the client after a RPI reboot


  • Create a script in /etc/init.d/noip

# sudo vi /etc/init.d/noip

      copy and paste the following:

#! /bin/sh
# /etc/init.d/noip

### BEGIN INIT INFO
# Provides:     noip
# Required-Start: networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start noip at boot time
# Description: Start noip at boot time
### END INIT INFO

# . /etc/rc.d/init.d/functions  # uncomment/modify for your killproc

DAEMON=/usr/local/bin/noip2
NAME=noip2
NOIP=`ps -ef|grep -q [n]oip2`
STATUS=$?

test -x $DAEMON || exit 0

case "$1" in
    start)
    echo -n "Starting dynamic address update: "
    start-stop-daemon --start --exec $DAEMON
    echo "noip2."
    ;;
    stop)
    echo -n "Shutting down dynamic address update:"
    start-stop-daemon --stop --oknodo --retry 30 --exec $DAEMON
    echo "noip2."
    ;;

    restart)
    echo -n "Restarting dynamic address update: "
    start-stop-daemon --stop --oknodo --retry 30 --exec $DAEMON
    start-stop-daemon --start --exec $DAEMON
    echo "noip2."
    ;;

    status)
        if [ ${STATUS} -eq "0" ];then
        echo "noip2 running..."
        else
        echo "noip2 Not running..."
        fi
    ;;

    *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
esac
exit 0
  • Set exec permissions
# sudo chmod 755 /etc/init.d/noip
  • Add script to Startup/Shutdown
# sudo update-rc.d noip defaults

Raspberry Pi - quick update script


Quick and easy script to upgrade Raspberry Pi
#! /bin/bash

if [ "$EUID" -ne 0 ]
then
echo "Please run as root"
exit 1
fi

#First Clean Up
echo "First Clean Up old downloaded and no longer required packages......."
apt-get clean
apt-get -y autoremove
echo "Clean Up Done"
echo ""

#Update package list
echo "Update your system's package list....."
apt-get update
echo "Package list updated"
echo ""

#Upgrade all installed packages
echo "Update all installed packages to latest versions....."
apt-get -y dist-upgrade

echo "Update Completed rebooting system...."
reboot

Monday, 19 May 2014

Find....

  • Find and compress files older then X days
find /path/to/files/ -type file -mtime 1 -exec gzip {} \;

1 means 24 hours old
-1 means less than 24 hours old
+0 means more than 24 hours old
+1 means more than 48 hours old

  • Find and compress files older then 5 days and exclude files already compressed (ext .gz)

find /path/to/files/ \( ! -name *.gz \) -type file -mtime +5 -exec gzip {} \;

Wednesday, 24 October 2012

How to create LVM on HP-UX

HP-UX


  • Create a new LVM
  • Extend an existing LVM

Create a new LVM


         STEPS:

      • Create the Physical Volume
      • Create the Volume Group
      • Create a Logical Volume
      • Create the File System


1.Check the list of devices, look for a new disk. The new devices will have a hardware path, but no device file associated with it  (no /dev/dsk/c*t*d* /dev/rdsk/c*t*d*)

# ioscan - fnkc disk

2.Create the device special file for the new hardware path

# insf

3.Check the list of devices to very the special files have been created

# ioscan -fnkC disk

4.Create the PV

# pvcreate /dev/rdsk/c*t*d*    (use -B to have a PV boot capable)

5.Create the Volume Group directory

# mkdir /dev/vgXX

6.Create the group file

Determine the minor number to use:

# ls -l /dev/*/group | sort +5

Choose the next unused number (0x0X0000)

# mknod /dev/vgXX/group c 64 0x0X0000

7.Create the volume group

# vgcreate -s 16 /dev/vgXX /dev/dsk/cxtxdx /dev/dsk/cxtydx

# vgextend /dev/vgxx /dev/dsk/cxtzdx

8.Create the Logical Volume

Check the space available on the VG

# vgdisplay -v vgXX ( Multiply the "Free PE" by "PE Size (MBytes)" to get spare capacity in MB of the volume group )

create the LV

# lvcreate -L 100 -n LVname /dev/vgXX

check the created LV

# vgdisplay -v LVname 

9.Create the FileSystem

# mkfs -F vxfs -o largefiles /dev/vgXX/LVname

10.Create the Mount Point

# mkdir -p <full path to mountpoint>

11.Set the proper ownership and permissions on the mount point

# chown owner:group /<mount point>
# chmod XXX /<mount point>

12.Mount the File System

Edit /etc/fstab using vi and add the proper entry

/dev/vgXX/LVname  /mountpoint vxfs rw,suid,largefiles 0 2

# mount /mountpoint

Check everything is ok

# bdf

DONE



Extend an existing LVM

          STEPS:
      • Add a disk to VG
      • Extend the LV
      • Extend the FS

1.Any devices that are on the ioscan, but are NOT on the vgdisplay are available for use

To get the list of devices:

# ioscan -fnC disk | sed 1,2d | xargs -n 10 | grep HITACHI

To get the list of disks used in the VG's

# vgdisplay -v | grep  "PV Name"

Compare the two and find unused disks 

2.Add unused disks to VG

# pvcreate /dev/rdsk/unused_cxtxdx

# vgextend /dev/vgxx /dev/dsk/unused_cxtxdx


3.Extend the Logical Volume

# lvextend -L XXXMb /dev/vgXX/LVname

4.Extend File System

First kill all process locking the FS then unmount the FS finally extend the FS and mount again the FS

# fuser -ku /dev/vgXX/LVname
# umount /dev/vgXX/LVname 
# extendfs /mountpoint
# mount /mountpoint


DONE




Monday, 22 October 2012

Install Tomcat 7


CentOS 5.7 - Tomcat 7.0.27 - JDK 7u4


  • Install Java
  • Install Tomcat


1.Download JDK

http://www.oracle.com/technetwork/java/javase/downloads/index.html

jdk-7u4-linux-i586.tar.gz


2.Download Tomcat

http://tomcat.apache.org/index.html

apache-tomcat-7.0.27.tar.gz


3.Install Java

a.create /usr/java

# mkdir  /usr/java

b.extract jdk-7u4-linux-i586.tar.gz in it

# tar xzf jdk-7u4-linux-i586.tar.gz

c.set JAVA_HOME in  ~/.bashrc or ~/.bash_profile

JAVA_HOME=/usr/java/jdk1.7.0_04  
export JAVA_HOME  
PATH=$JAVA_HOME/bin:$PATH  
export PATH  

d.reload .bash_profile

# source .bash_profile


4.Install Tomcat

a.copy tomcat in /usr/share

cp /root/tomcat/apache-tomcat-7.0.27.tar.gz /usr/share

b.extract tomcat

cd /usr/share
tar xzf apache-tomcat-7.0.27.tar.gz


c.Run tomcat with tomcat user

groupadd tomcat
useradd -s /bin/bash -g tomcat tomcat
chown -Rf tomcat.tomcat /usr/share/apache-tomcat-7.0.27/

d.create a startup script

# cd /etc/init.d/

# vi tomcat

---------------------------------------------------------------------
#!/bin/bash  
# description: Tomcat Start Stop Restart  
# processname: tomcat  
# chkconfig: 234 20 80  
JAVA_HOME=/usr/java/jdk1.7.0_04  
export JAVA_HOME  
PATH=$JAVA_HOME/bin:$PATH  
export PATH  
CATALINA_HOME=/usr/share/apache-tomcat-7.0.27  
  
case $1 in  
start)  
/bin/su tomcat $CATALINA_HOME/bin/startup.sh  
;;   
stop)     
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh  
;;   
restart)  
/bin/su tomcat $CATALINA_HOME/bin/shutdown.sh  
/bin/su tomcat $CATALINA_HOME/bin/startup.sh  
;;   
esac      
exit 0  
---------------------------------------------------

e.Change file permission for execution

# chmod 755 tomcat

f.Configure tomcat to automatically start

# chkconfig --add tomcat  
# chkconfig --level 234 tomcat on 

g.Test the script

# service tomcat start
# service tomcat restart
# service tomcat stop

h.Check the logs

# more /usr/share/apache-tomcat-7.0.27/logs/catalina.out

i.Start tomcat and connect to web

# service tomcat start
# http://yourIPaddress:8080


l.Configure access to Tomcat Manager gui

# vi $CATALINA_HOME/conf/tomcat-users.xml

m.Manage Memory Usage Using JAVA_OPTS : set our inital heap size, Xms, and our maximum heap size, Xmx, to the same value of 128 Mb

# vi Catalina.sh

JAVA_OPTS="-Xms128m -Xmx128m" 


DONE

Install LAMP on CentOS


CentOS 5.7


  • Install Mysql
  • Install Apache with Php

1.Install Mysql Server

# yum install mysql mysql-server

2.Start and Enable Mysql service

# systemctl start mysqld.service
# systemctl enable mysqld.service

Create Mysql password  with  :

# mysqladmin -u root password [your_password_here]

Check the connexion  to the databae server with:

# mysql -h localhost -u root -p

2.Install HTTPD and  PHP

a.Install Apache (httpd)

# yum install httpd php php-common

b.Start  and  enable  httpd  service

# /etc/init.d/httpd start

 ---OR---

# service httpd start

# chkconfig --levels 235 httpd on

3.Check if php works

create a .php test file

# vi /var/www/html/info.php

insert:

<?php
phpinfo();
?>

save and    open browser to check   : http://ip/info.php


DONE

Create MySql replication on CentOS



CentOS 5.7  - Mysql 5.5
  • Install MySql
  • Configure Master and Slave



Install Mysql


1. Remove previously installed MySQL (if applicable)

# yum erase mysql

2. Install additional repos

Navigate to temporary directory

# cd /tmp

Install EPEL repo

# wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

# rpm -Uvh epel-release-5-4.noarch.rpm

Install remi repo

# wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

# rpm -Uvh remi-release-5.rpm

3. Ensure the repo contains MySQL 5.5

# yum --enablerepo=remi list mysql mysql-server 

4. Install MySQL 5.5

# yum install --enablerepo=remi mysql*

5. Start MySQL and configure to start on boot

# service mysqld start

# chkconfig mysqld on 

6. Run mysql upgrade script

# mysql_upgrade -u root

7. Change Mysql default Password

# mysqladmin -u root password "XXXXX"

8. Check to ensure mysql 5.5 is installed. 

# mysql -uroot -p

SELECT version();


Configure Master and Slave

Master


1. Edit master configuration

# vi /etc/my.cnf

Comment out those lines if present

#skip-networking
#bind-address            = 127.0.0.1
 
Add those lines in [mysqld] section

log-bin = /var/logs/mysql/mysql-bin.log
binlog-do-db=my_database
server-id=1

2. restart MySQL

# service mysqld restart

3. Connect to mysql and create a replication user

mysql -u root -p
Enter password:

GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY '<some_password>';

FLUSH PRIVILEGES;

Next (still on the MySQL shell) do this:

USE exampledb;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

Write down this information, i will need it later on the slave

 File                        | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+---------------+-------------------+
| mysql-bin.000001 |      107  | employees        |                               |


quit

4. take a backup of db


# mysqldump -u root -p<password> --opt exampledb > exampledb.sql

5. Finally we have to unlock the tables in exampledb:

# mysql -u root -p
Enter password:
UNLOCK TABLES;
quit;


Slave

1. Create db

# mysql -u root -p
Enter password:
CREATE DATABASE exampledb;
quit;

2. Import data from master

mysql -u root -p<password> exampledb < /path/to/exampledb.sql

3. Edit slave config

 # vi /etc/my.cnf

For mysql 5.1
[mysqld]
server-id=2
master-host=192.168.0.100
master-user=slave_user
master-password=secret
master-connect-retry=60
replicate-do-db=exampledb

[mysqld_safe]
relay-log = /var/log/mysql/slave-relay.log
relay-log-index = /var/log/mysql/slave-relay-log.index

For mysql 5.5

[mysqld]
server-id=2
replicate-do-db=exampledb

[mysqld_safe]
relay-log = /var/log/mysql/slave-relay.log
relay-log-index = /var/log/mysql/slave-relay-log.index

4. From mysql shell

$ change master to master_host='192.168.0.11', master_port=3306, master_user='slave_user', master_password='slave_user', master_log_file='mysql-bin.000001', master_log_pos=107, master_connect_retry=10;


START SLAVE;

SHOW SLAVE STATUS \G;


DONE