Thursday, June 9, 2016

How To Install Btrfs Tools And Manage BTRFS Operations

http://linuxpitstop.com/install-btrfs-tools-on-ubuntu-linux-to-manage-btrfs-operations


Hello everybody, today we are going to show you installation of Btrfs tools and its Operation. Btrfs is a new copy on write (CoW) filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, repair and easy administration. Jointly developed at multiple companies, Btrfs is licensed under the GPL and open for contribution from anyone. Considering the rapid development of Btrfs at the moment, Btrfs is currently considered experimental. But according to the wiki maintained by the btrfs community, many of the current developers and testers of Btrfs run it as their primary file system with very few “unrecoverable” problems. Thus, Linux distributions tend to ship with Btrfs as an option but not as the default. Btrfs is not a successor to the default Ext4 file system used in most Linux distributions, but it can be expected to replace Ext4 in the future.
Now we will be going to install the latest version of brtfs-tools on Ubuntu Linux based server.

Prerequisites

Before installing the Btrfs on your linux system, make sure that you are using the latest version of kernel as it has been included in the mainline kernel. After that you are required to install some packages that are are necessary and helps in the installation of Btrfs tools.
Let’s run the below command to install build tools on your Linux system.
# apt-get install git install asciidoc xmlto --no-install-recommends
installing build tools
Now run the command below to install some more libraries for your system and press ‘y’ to continue.
# apt-get install uuid-dev libattr1-dev zlib1g-dev libacl1-dev e2fslibs-dev libblkid-dev liblzo2-dev
required btrfs libs

Downloading Brtfs-tools

To download the latest stable version of brtfs-tools run the the following git command in your command line terminal.
# git clone git://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
download btrfs-toosl

Build Btrf-tools

Run the following command for preparing your btrf-tools to build for compilation after changing directory to the downloaded package as shown.
# cd btrfs-progs/
# ./autogen.sh
After generating the build you will be asked to type ‘./configure’ and ‘make’ to compile. Just flow the below commands one by one.
# ./configure
make
compiling btrfs-tools

Installing Btrfs-Tools

Once the btrfs-tools compilation process completes, we can install it by using ‘make install’ command as shown below.
# make install
After installation, run below command to verify the installed version of btrfs-tools on your system.
# btrfs version
Installing btrfs-tools

Managing Btrfs Operations

BTRFS aims to provide a modern answer for making storage more flexible and efficient. Now we are going to show you some of the useful operations of Btrfs. It stores data in chunks across all of the block devices on the system. The total storage across these devices is shown in the standard output of df -h.
Raw data and filesystem metadata are stored in one or many chunks, typically 1 GiB in size. When RAID is configured, these chunks are replicated instead of individual files.

Btrfs Filesystem creation

‘mkfs.btrfs’ can accept more than one device on the command line using different options to control the raid configuration for data (-d) and metadata (-m). Once you have added another disk to your system and you wish to mount it using btrfs, then run below command to create its system.
# mkfs.btrfs /dev/sdb
creating btrfs
Once you have create a filesystem, you can mount your new btrfs device using below command.
# mount /dev/sdb /mnt

Btrfs Device scanning

btrfs device scan is used to scan all of the block devices under /dev and probe for Btrfs volumes. This is required after loading the btrfs module if you’re running with more than one device in a filesystem.
Let’s run below command to scan all devices.
#btrfs device scan
To scan a single device use below command.
#btrfs device scan /dev/sdb
You can use below command to print information about all of the btrfs filesystems on the machine.
# btrfs filesystem show

Adding New devices

New physical disks can be added to an existing btrfs filesystem. The first step is to have the new block device mounted on the machine like have already done this. Afterwards, let btrfs know about the new device and re-balance the file system. The key step here is re-balancing, which will move the data and metadata across both block devices.
So, first run below command to add new devices to a mounted filesystem.
#btrfs device add /dev/sdb /mnt
Then use below command to balance (restripe) the allocated extents across all of the existing devices. For example, with an existing filesystem mounted at /mnt, you can add the device /dev/sdb to it.
# btrfs filesystem balance /mnt
new device
Run the following command that prints very useful information that you can use to debug and check how the BTRFS volume has been created.
# btrfs filesystem df /mnt
Data, single: total=1.00GiB, used=320.00KiB
System, DUP: total=32.00MiB, used=16.00KiB
Metadata, DUP: total=128.00MiB, used=112.00KiB
GlobalReserve, single: total=16.00MiB, used=0.00B
Adding in /etc/fstab
If you don’t have an initrd, or your initrd doesn’t perform a btrfs device scan, you can still mount your volume btrfs filesystem by passing your devices in the filesystem explicitly to the mount command by adding below entry in your ‘/etc/fstab’ file.
# vim /etc/fstab
/dev/sdb /mnt btrfs 0 0
A common practice in system administration is to leave some head space, instead of using the whole capacity of a storage pool (just in case). With btrfs one can easily shrink and expand the volumes.
Let’s shrink the volume a bit (about 25%) using below command.
# btrfs filesystem resize -1g /mnt
To grow the volume run below command.
# btrfs filesystem resize +150m /mnt
This is the opposite operation, you can make a BTRFS grow to reach a particular size (e.g. 150 more megabytes) as in above command. You can also take an “all you can eat” approach via the max option, meaning all of the possible space will be used for the volume with below command.
 #btrfs filesystem resize max /mnt

Removing devices

Use below command to remove devices online. It redistributes the any extents in use on the device being removed to the other devices in the filesystem.
#btrfs device delete /dev/sdb /mnt

Conclusion

Btrfs is intended to address the lack of pooling, snapshots, checksums, and integral multi-device spanning in Linux file systems. These features are being crucial as the use of Linux scales upward into larger storage configurations. Btrfs is designed to be a multipurpose filesystem, scaling well on very large block devices. There are alot of its other operational usages that you can use. So, don’t wait and let’s get started with btrfs and I hope you find this quite better than other Linux file systems.
If you enjoy our article(s) , please like/follow and share our social network pages so we may keep running this non profit venture.

How to effectively clear your bash history

http://www.techrepublic.com/article/how-to-effectively-clear-your-bash-history

If you're serious about security on your Linux machines, you might want to clear the bash history. Learn how to do this more effectively than with just a single command.


Image: Jack Wallen
On your Linux machines, a history of your bash commands is retained. This is great when you need to repeat a command or can't remember exactly how you executed a command in a previous session. However, this can also be seen as a security issue. What if someone gains access to your machine, opens a terminal window, and checks through your bash history to see what commands you've run?
Bash has a handy way to clear the history: issue the command history -c. There's a slight problem with that approach. Let me explain.

First off, your bash history is retained in the file ~/.bash_history. When you have a terminal open, and you issue a command, it writes the command to the history file. So issuing history -c will clear the history from that file. The problem comes about when you have multiple terminal windows open. Say you have two terminal windows open and you issue history -c from the first one and close that window. You then move to the second terminal window, and you type the exit command to close that window. Because you had a second bash window open, even after running the history -c command in the first, that history will be retained. In other words, the history -c command only works when it is issued from the last remaining terminal window.
How do you get around that? You empty the .bash_history file either on a per-instance basis or by using a crontab job to do it regularly. If security is a serious matter for you, consider setting up the crontab job. Here's how.
SEE: Linux Foundation launches badge program to boost open source security (ZDNet)

Clearing bash history on a regular basis

Before I show how to set up the crontab job for this, know that the ~/.bash_history file can be cleared with the command:
cat /dev/null > ~/.bash_history
That will empty out the contents of the file, but keep the file in place.
Let's say you want to clear the .bash_history file for user olivia (who administers your Linux server) at 11:00 p.m. every day. You would create a cron job under the olivia account. To do that, log in as the user olivia, open a terminal window, and issue the command crontab -e. When the crontab editor opens, enter the following:
00 23 * * * cat /dev/null > ~/.bash_history
Save that file and cron will start clearing out olivia's history at 11:00 p.m. every day.

A surefire method

This is a surefire method of clearing out your bash history. Don't always rely on the history -c command, because you never know when a second (or a third) terminal is still open, ready to keep that history retained.

Gathering insights from data: An overview of the Elastic stack

https://opensource.com/life/16/6/overview-elastic-stack

Gathering insights from data: An overview of the Elastic stack
Image credits : 
Tony Smith via Flickr (CC BY 2.0)
The Elastic stack is a versatile collection of open source software tools that make gathering insights from data easier. Formerly referred to as the ELK stack (in reference to Elasticsearch, Logstash, and Kibana), the growing list of tools that integrate with the platform (such as Beats) have outgrown the acronym but provide ever-growing capability for users and developers alike.
At the upcoming Southeast Linuxfest 2016, I'll be covering some of the steps to get started using each of these parts of the stack. In this article, we'll look at each in turn to summarize the capabilities, requirements, and interesting use cases that apply to each.

Beats & Logstash

Collecting data is where it all starts. Logstash and Beats both serve this need, though each is finely tuned to suit different needs and uses. Whether your priority is light resource usage or extensive features, either solution has been designed to meet those requirements.

Beats

Beats are lightweight, fast data shippers and collectors that typically do one thing and do it well. For example, Packetbeat collects and ships data about packet activity on a network interface, while Filebeat can tail a log file and send logs to be processed downstream. Beats are designed to be fast, portable, and easy to deploy on individual hosts for specific needs. There are even community-created Beats for uses like monitoring HTTP endpoints and NGINX health.
Written in Go and based upon the shared foundation of libbeat, Beats are meant to be easily implemented so that even resource-constrained environments can be measured easily and without much overhead.

Logstash

Logstash is similarly capable of collecting machine data, but where it shines is the plethora of open source plugins available to enrich data. For example, while collecting webserver logs is useful, deeply parsing the user-agent data to extract traffic statistics can be beneficial, which the useragent filter can do. Or, if using the Twitter plugin, you may want to perform sentiment analysis on user tweets.
Custom plugins are simple Ruby libraries, which enable users to extend functionality and prototype new features quickly. Performance isn't an afterthought, however: Logstash ships with JRuby by default, which opens up possibilities for concurrency and real threads.

Elasticsearch

Once data has been collected and enriched, storing it in Elasticsearch opens up a range of possibilities.
Elasticsearch is a search engine at its heart, with a myrid of use cases borne of its flexibility and ease of use. Based on Apache Lucene, Elasticsearch strives to make both the operational challenges (such as scalability and reliability) and application-based needs (like freetext search and autocomplete) easier for end users.
Operationally, Elasticsearch's elasticity stems from splitting indices into shards, which can be spread across multiple hosts to balance load and boost performance. With planning, this means that datasets can grow well beyond the capabilities of one machine to handle.
Some examples of the analytics that can be performed on Elasticsearch include:
  • Geo searching. When documents are inserted with geo metadata, results can be overlaid on a map to visualize how documents relate to real-world longitudes and latitudes.
  • Graphing. Recent plugins have added graph search to Elasticsearch, which can answer interesting questions such as relationships between data in the Panama Papers.
  • Aggregations. Answering questions such as which pages returned the most 500 errors become a matter of forming the right query for the fields in a log file.
While all these capabilities are driven by Elasticsearch's core, exposing them in a user-friendly interface is left to the next layer in the stack.

Kibana

Kibana is a browser-based visualization frontend for Elasticsearch. It enables users to easily consume data in aggregate that would otherwise be difficult to process; making logs, metrics, and unstructured data searchable and more usable for humans. Additional plugins can be used for specialized cases, such as Timelion for timeseries data.
Because Kibana persists most of its data within Elasticsearch, managing Kibana dashboards and visualizations is a similar exercise as managing other indices in Elasticsearch. Charts, graphs, and other visualizations sit atop Elasticsearch APIs which can be easily inspected for closer analysis or use in other systems.

An open ecosystem

Like other multi-faceted systems, the Elastic stack is supported by tools to help manage deployment and configuration, such as with Ansible, Puppet, and Chef. Standard distribution repositories are similarly available.
It's worth noting that all of these open source projects are spread across a wide array of languages. While Beats are written in Go for portable, efficient distribution of compiled binaries, Kibana uses Javascript for unified development of frontend and backend components. With many languages and an open codebase, users should feel free to get involved with the feature development and bugfixing efforts that matter to them.
Now is a great time to play with the stack and see what you can accomplish with it, with a wide variety of solutions and global community standing by to support users and developers alike.