Thursday, December 7, 2017

miscellaneous day to day admin task

1.) sort /etc/passwd on uid.

[anuj@oc5380700602 ~]$ sort -t: -k 3,4 -g /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

Sunday, October 15, 2017

learn how to use facter in puppet.

=====================================================
Following practical will help you to know how to use facter in puppet.
=====================================================

Facter is command tool which provides the node specific information, which is used by puppet master for node segregation of spacfic content managment


[root@pupprdclt1 ~]# facter | egrep "family | hostname|kernelversion"
kernelversion => 2.6.32
  hostname => "pupprdclt1",
  family => "RedHat",
[root@pupprdclt1

===================================================================
Check squid is not installed on puppet agent node, and we will use above mentioned facters in manifest on master server for the code deployment.
 ====================================================================

[root@pupprdclt1 ~]# yum list squid
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos-hn.viettelidc.com.vn
 * extras: mirrors.vinahost.vn
 * updates: mirrors.viethosting.com
Available Packages
squid.x86_64                                                        7:3.1.23-24.el6                                                         base
[root@pupprdclt1




===================================================================
Go to the Puppetmaster node and create squid module using facter specification
===================================================================

[root@puppetmaster ~]# mkdir /etc/puppetlabs/code/environments/production/modules/squid

[root@puppetmaster ~]# cd /etc/puppetlabs/code/environments/production/modules/squid

[root@puppetmaster squid]#mkdir manifest

root@puppetmaster squid]# ls -l
total 12
drwxr-xr-x. 2 root root 4096 Oct 15 06:13 manifests


[root@puppetmaster squid]# cd manifests

[root@puppetmaster manifests]#



[root@puppetmaster manifests]#vi install.pp
class squid::install{
        if $osfamily == 'RedHat'{  <--------using RedHat facter output of osfamily
                        package{'squid':
                        ensure => installed,
                        }
        }
        elsif $osfamily == 'Debian'{
                package{'httpd':
                ensure => installed,
                        }
                }
}


[root@puppetmaster manifests]# vi init.pp
class squid{
        include squid::install             <------------- calling squid class
}

:x!

[root@puppetmaster manifests]#

[root@puppetmaster squid]#


[root@puppetmaster manifests]# ls -l *.pp
-rw-r--r--. 1 root root  39 Oct 15 06:34 init.pp
-rw-r--r--. 1 root root 187 Oct 15 06:26 install.pp
[root@puppetmaster manifests]#

-----------------------------------
Now go on client and call manifest
-----------------------------------
[root@pupprdclt1 ~]# puppet agent -tv
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for pupprdclt1.linuxchamps.com
Info: Applying configuration version '1508074488'
Notice: Hello World
Notice: /Stage[main]/Main/Notify[Hello World]/message: defined 'message' as 'Hello World'
Notice: /Stage[main]/Squid::Install/Package[squid]/ensure: created <-------- see installing Squid on
Notice: Applied catalog in 112.75 seconds
===================================================================
 Now check squid is installed or not on puppet client
===================================================================
[root@pupprdclt1 ~]# yum list squid
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos-hn.viettelidc.com.vn
 * extras: mirrors.vinahost.vn
 * updates: mirrors.viethosting.com
Installed Packages
squid.x86_64                                                        7:3.1.23-24.el6                                                 @base
[root@pupprdclt1 ~]#

Learning Puppet

[root@anujpupetmaster ~]# cd /tmp/puppet-enterprise-2015.3.3-el-6-x86_64
[root@anujpupetmaster puppet-enterprise-2015.3.3-el-6-x86_64]# ./puppet-enterprise-installer
========================================================================================================================================================================

Puppet Enterprise v2015.3.3 installer

Puppet Enterprise documentation can be found at http://docs.puppetlabs.com/pe/2015.3/

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

STEP 1: GUIDED INSTALLATION

Before you begin, choose an installation method. We've provided a few paths to choose from.

- Perform a guided installation using the web-based interface. Think of this as an installation interview in which we ask you exactly how you want to install PE. In
order to use the web-based installer, you must be able to access this machine on port 3000 and provide the SSH credentials of a user with root access. This method
will login to servers on your behalf, install Puppet Enterprise and get you up and running fairly quickly.

- Use the web-based interface to create an answer file so that you can log in to the servers yourself and perform the installation locally. If you choose not to use
the web-based interface, you can write your own answer file, or use the answer file(s) provided in the PE installation tarball. Refer to Answer File Installation
(http://docs.puppetlabs.com/pe/2015.3/install_automated.html), which provides an overview on installing PE with an answer file.

?? Install packages and perform a guided install? [Y/n] Y

Installing setup packages.

Please go to https://anujpupetmaster:3000 in your browser to continue installation. Be sure to use https:// and that port 3000 is reachable through the firewall.

Your infrastructure has finished installing.
Thank you for installing Puppet Enterprise!
[root@anujpupetmaster puppet-enterprise-2015.3.3-el-6-x86_64]#

Monday, April 9, 2012

Top 10 Open Source Bug Tracking System

Logrotate in Linux server

Logs are important and usefull in security and administration. If a log grows too much, you compress it , back it up for some months or years and create a new log file. All this is done in a much better way by Logrotate. Logrotate enables you to compress the old logfile, and store it for as long as you want, to run every day, montly, or when you want, and if a file expires, it can send it to you by email or delete it, after for example, 2 years. Old logs can be stored in an alternative directory.

You set up logs configuring /etc/logrotate.conf or adding a new file in /etc/logrotate.d/
For example, a logrotate file for apache looks like this:
File: /etc/logrotate.d/httpd
-------8<------- /usr/local/apache/logs/*log { missingok notifempty sharedscripts postrotate /bin/kill -USR1 `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}

Suggestions to debug Segmentation Fault errors

Usually signal #11 (SIGSEGV) set, which is defined in the header file signal.h file. The default action for a program upon receiving SIGSEGV is abnormal termination. This action will end the process, but may generate a core file (also known as core dump) to aid debugging, or perform some other platform-dependent action. A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally.
Segmentation fault can also occur under following circumstances:
a) A buggy program / command, which can be only fixed by applying patch.
b) It can also appear when you try to access an array beyond the end of an array under C programming.
c) Inside a chrooted jail this can occur when critical shared libs, config file or /dev/ entry missing.
d) Sometime hardware or faulty memory or driver can also create problem.
e) Maintain suggested environment for all computer equipment (overheating can also generate this problem).
Suggestions to debug Segmentation Fault errors
To debug this kind of error try one or all of the following techniques :
Use gdb to track exact source of problem.
Make sure correct hardware installed and configured.
Always apply all patches and use updated system.
Make sure all dependencies installed inside jail.
Turn on core dumping for supported services such as Apache.
Use strace which is a useful diagnostic, instructional, and debugging tool.
Google and find out if there is a solution to problem.
Fix your C program for logical errors such as pointer, null pointer, arrays and so on.
Analyze core dump file generated by your system using gdb

Fix corrupted RPM database on CentOS 5 / Redhat enterprise Linux 5 / Fedora 7

If rpm / yum command hangs during operations or you see error messages - it means your rpm database corrupted. /var/lib/rpm/ stores rpm database just delete the same and rebuild rpm database:
Command to rebuild rpm database
rm -f /var/lib/rpm/__db*
rpm --rebuilddb
Rebuilding corrupted RPM database
One of our client reported that he is getting an error and RPM database is corrupted. He is using Red Hat Linux
Sometime it is possible to fix RPM database errors. I am surprised that many admins do not make back up of RPM DB (/var/lib/rpm).
Anyways if you ever messed up with RPM database, here is a quick guide to fix it (you must have rpmdb tools installed):
Take system to single user mode to avoid further damage and to make backup/restore process easy:
# init 1
Method # 1
Remove /var/lib/rpm/__db* files to avoid stale locks:
# cd /var/lib
# rm __db*
Rebuild RPM database:
# rpm --rebuilddb
# rpmdb_verify Packages
Method # 2
If you are still getting errors, then try your luck with following commands:
# mv Packages Packages-BAKUP
# db_dump Packages-BAKUP | db_load Packages
# rpm -qa
# rpm --rebuilddb
Segmentation Fault Occur on Linux

Usually signal #11 (SIGSEGV) set, which is defined in the header file signal.h file. The default action for a program upon receiving SIGSEGV is abnormal termination. This action will end the process, but may generate a core file (also known as core dump) to aid debugging, or perform some other platform-dependent action. A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally.
Segmentation fault can also occur under following circumstances:
a) A buggy program / command, which can be only fixed by applying patch.
b) It can also appear when you try to access an array beyond the end of an array under C programming.
c) Inside a chrooted jail this can occur when critical shared libs, config file or /dev/ entry missing.
d) Sometime hardware or faulty memory or driver can also create problem.
e) Maintain suggested environment for all computer equipment (overheating can also generate this problem).

Complete list of  recommended VS Code extensions  for writing and managing  AWS Terraform scripts , including syntax checking, variable supp...