Create a Bash Alias in OSX/MacOS

Assalamualaikum,

When I had bought my Mac, the .bash_login file wasn’t there. I need to create it for myself so that I could put prompt info, alias, functions, etc. in it.

Here are the steps if you would like to create one:

  1. Start up Terminal
  2. Type cd ~/ to go to your home folder
  3. Type touch .bash_profile to create your new file.
  4. Edit .bash_profile with your favorite editor (or you can just type open -e .bash_profileto open it in TextEdit.
  5. Type . .bash_profile to reload .bash_profile and update any alias you add.

wassalam..

Posted in Mac, OSX, MacOS | Tagged , , ,

How to Install Cacti on CentOS 7

Assalamualaikum..

Cacti is a configurable, scalable network and resource monitoring system based on the RRDTool suite. It works on systems ranging from simple LAN installations, to multi data center LANs. Cacti provides user management, as well as acquisition of data from multiple sources in an easy-to-use interface. This guide sets up a Cacti installation on a CentOS 7 server.

Getting Started

To complete this guide, you will need the following:
• 1 Node running CentOS 7 with internet.

While good for learning how to set up Cacti on CentOS, it is better to install Cacti on a running server once you are familiar with the process, as monitoring is crucial for production-facing assets.

Tutorial

Let’s update all installed packages. Not only does this apply any known security fixes, but it also resolves issues in the base CentOS system.

yum update -y

Cacti depends on Apache, PHP, the MariaDB MySQL fork, and the associated modules needed to make PHP and Apache work together. We’ll install those next.

yum install nano httpd httpd-devel mariadb-server php-mysql php-pear php-common php-gd php-devel php php-mbstring php-cli -y

SNMP is also crucial to the Cacti stack. We’ll install net-snmp, the php-snmp module so PHP can retrieve SNMP data, and finally rrdtool.

yum install php-snmp net-snmp-utils net-snmp-libs rrdtool -y

Let’s start bringing up the various components Cacti needs. We’ll begin by launching Apache, MariaDB and SNMP.

systemctl start httpd.service
systemctl start snmpd.service
systemctl start mariadb.service

All of these should be configured to start at boot. Here we configure these components to launch when the server starts.

systemctl enable httpd.service
systemctl enable snmpd.service
systemctl enable mariadb.service

We must now secure access to Cacti. Leaving monitoring solutions open to public viewing is a security risk. This next step adds password authentication for Cacti.

mysql_secure_installation

Cacti needs a database, which will now be created. We’ll also create a cacti user and grant it all database privileges.

mysql -u root -p
MariaDB> CREATE DATABASE cactidb;
MariaDB> CREATE USER 'cactiuser'@'localhost' IDENTIFIED BY 'cactipassword';
MariaDB> GRANT ALL PRIVILEGES ON cactidb.* TO 'cactiuser'@'localhost';
MariaDB> FLUSH PRIVILEGES;
MariaDB> exit

It is finally time to install Cacti itself.

yum install epel-release -y
yum install cacti -y

Cacti ships with a cacti.sql database dump that should be imported into MySQL. We need to find where it was stored in order to perform the import.

rpm -ql cacti|grep cacti.sql
/usr/share/doc/cacti-0.8.8h/cacti.sql

Now we’ll actually import the schema we’ve just found. This command loads the cacti.sql dump into the database we created previously.

mysql -u cactiuser -p cactidb < /usr/share/doc/cacti-0.8.8h/cacti.sql

Cacti needs to know how to connect to the database. We must add the database name and credentials to its database configuration file.

nano /etc/cacti/db.php
[...]
database_default = "cactidb";
database_hostname = "localhost";
database_username = "cactiuser";
database_password = "cactipassword";
[...]

Apache must be accessible from the network so we can view Cacti’s statistics. Edit /etc/httpd/conf.d/cacti.conf.

nano /etc/httpd/conf.d/cacti.conf

Change these two lines:

# httpd 2.4
Require host localhost <---- This one

# httpd 2.2
Order deny,allow
Deny from all
Allow from localhost <---- This one

to:

# httpd 2.4
Require all granted

# httpd 2.2
Order deny,allow
Deny from all
Allow from all

Restart Apache so it picks up the configuration changes we’ve just made.

systemctl restart httpd.service

There is a crontab entry for Cacti that must be activated in order for it to create its graphs. Uncomment the line in /etc/cron.d/cacti.

nano /etc/cron.d/cacti

#*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

to:

*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

In order for Cacti to log its results, we’ll need to create an empty cacti.log.

mkdir /var/log/cacti
touch /var/log/cacti/cacti.log

The remaining installation steps are done via the web interface. Visit http://your_ip/cacti to finish the process.

When prompted for a username and password, enter “admin” for both. These should be changed as soon as possible.

P/S: If you get MySQL TimeZone error please follow below steps

root-bash> mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql> use mysql;
mysql> GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost;
mysql> flush privileges;

Conclusion

This CentOS 7 server is now being monitored by Cacti. While the results of monitoring an empty server are not terribly interesting, the true utility of monitoring becomes quickly apparent when it is used on a production server managing actual workloads. If this guide was helpful to you, kindly share it with others who may also be interested.

 

Wassalam..

Posted in Browser, cacti, Install, Linux, SQL | Tagged

How to Browsing the Web Using SSH Tunnel

Assalamualaikum,

Sometimes you need to configure something on your client office (router/firewall), but the only way to do that was to be on the their internal network and browse to it using a browser. Trying text based browsers didn’t work, the only way to access and administer the router was to use a full featured browser from behind the firewall itself. There was a DMZ linux machine that I could SSH to, but no VPN available. I figured out how to do it using Putty and Firefox, and this is how you do it.

What you need?

  1. Putty
  2. Firefox browser.

Configure SSH tunnel using Putty

Open Putty and Enter the hostname or IP of the machine you want to establish a remote connection to.  Next under Connection->SSH->Tunnels find the radio boxes under the Destination field and make sure Dynamic is selected.  Next under where it reads Add new forwarded port: enter a source port.  For this example lets use 696, enter this in the source port field and click the Add button.  You should see a value in the Forwarded ports: list that reads D696.  That’s all there is to the Putty side of things.  Next go back to the session area and save the current configuration as a saved session if you’d like, then Open the SSH connection.

Configure Firefox

Launch Firefox, select Tools->Options and click the Advanced tab. Within the Advanced tab, click on the Network tab and click the Settings button.

Within the Network Settings dialog, select the Manual proxy configuration radio button and enter the following for the SOCKS Host: and Port:

SOCKS Host: localhost
SOCKS Port: 696

Click OK on the Settings dialog, then Click OK on the Options dialog. Now you should be good to go.  Enter a new URL in the Firefox address bar and you’ll be browsing from the remote end of the SSH connection.

wassalam..

 

Posted in Browser, Linux, UNIX | Tagged , ,

How to Enable su Access in FreeBSD

Assalamualaikum,

How can a “normal” user get root rights, or actually switch to root account using the su command when working under FreeBSD?

To do that, that “normal” user needs to be in wheel group. So this command will enable a given user to be able to switch to root account with the command su – root or just su –

pw groupmod wheel -m [user]

example:

pw groupmod wheel -m hanief

Now that user hanief will be able to become root. This is a good security feature that FreeBSD has.

Thanks,

wassalam..

Posted in freeBSD, Linux, UNIX | Tagged , , ,

How to Search Deleted Accounts in Zimbra

police_bin

Assalamualaikum.

Zimbra keeps track of deleted accounts in its MySQL database. So if it will be necessary to search for accounts that may have existed some time ago, you can list all accounts by SQL.

As the zimbra user issue the following command:
mysql -e "select email, from_unixtime(deleted_at) from zimbra.deleted_account order by deleted_at"

screen-shot-2017-02-21-at-19-41-42

wassalam..

..

Posted in SQL, Zimbra | Tagged , , ,

How to Search File with Specific File Size

clean-your-room

Assalamualaikum..

Cleaning up your machine is very important to make sure your box is running in optimum performance and healthy. You may use command df -h regularly to check your partition size. But it will not tell you which file is growing and consume the space. Of course you can go through df -h and issue the command du -sh to check the size. But using this way, you need to crawl all over the path one by one. This is not really convenient. Below command will show you how to find out which file is taking space in your machine by using the specific file size.

# su - root
# find / -xdev -type f -size +100M

above command will search all files that having size bigger than 100MB in / partition. You can change the value.

The following command will find you the top 50 largest files (>100M) on your filesystem, and sort by the biggest:

find / -xdev -type f -size +100M -exec du -sh {} ';' | sort -rh | head -n50

For all files and directories, it’s even easier:

du -ahx / | sort -rh | head -20
(the -x flag is what’s required to constrain du to a single filesystem)

If you’re not using GNU sort (from coreutils), use it without -h:

du -ax / | sort -rn | head -20
For currently directory only (for quicker results), replace / with .

happy linuxing

wassalam..

..

Posted in Linux | Tagged , , ,