Wednesday, January 17, 2018

Creating an Offline YUM repository for LAN

http://linuxtechlab.com/offline-yum-repository-for-lan


In our earlier tutorial, we discussed “How we can create our own yum repository with ISO image & by mirroring an online yum repository”. Creating your own yum repository is a good idea but not ideal if you are only using 2-3 Linux machines on your network. But it definitely has advantages when you have large number of Linux servers on your network that are updated regularly or when you have some sensitive Linux machines that can’t be exposed to Internet directly.
When we have large number of Linux systems & each system is updating directly from internet, data consumed will be enormous. In  order to save the data, we can create an offline yum & share it over our Local network. Other Linux machines on network will then fetch system updates directly from this Local yum, thus saving data & also transfer speed also be very good since we will be on our local network.
We can share our yum repository using any of the following or both methods:
  • Using Web Server (Apache)
  • Using ftp (VSFTPD)
We will be discussing both of these methods but before we start, you should create a YUM repository using my earlier tutorial (READ HERE)

Using Web Server

Firstly we need to install web-server (Apache) on our yum server which has IP address 192.168.1.100. Since we have already configured a yum repository for this system, we will install apache web server using yum command,
$ yum install httpd
Next, we need to copy all the rpm packages to default apache root directory i.e. /var/www/html or since we have already copied our packages to /YUM, we can create a symbolic link from /var/www/html to /YUM
$ ln –s /var/www/html/Centos /yum
Restart you web-server to implement changes
$ systemctl restart httpd

Configuring  client machine

Configurations for sharing Yum repository on server side are complete & now we will configure our client machine, with an IP address 192.168.1.101, to receive updates from our created offline yum.
Create a file named offline-yum.repo in /etc/yum.repos.d folder & enter the following details,
$ vi /etc/yum.repos.d/offline-yum.repo
[Offline YUM]
name=Local YUM
baseurl=http://192.168.1.100/CentOS/7
gpgcheck=0
enabled=1
We have configured your Linux machine to receive updates over LAN from your offline yum repository. To confirm if the repository is working fine, try to install/update packages using yum command.

Using FTP server

For sharing our YUM over ftp, we will firstly install the required package i.e vsftpd
$ yum install vsftpd
Default root directory for vsftp is /var/ftp/pub, so either copy rpm packages to this folder or create a symbolic link from /var/ftp/pub,
$ ln –s /var/ftp/pub /YUM
Now, restart server for implement the changes
$ systemctl restart vsftpd

Configuring  client machine

We will now create a file named offline-yum.repo in /etc/yum.repos.d , as we did above & enter the following details,
$ vi /etc/yum.repos.d/offline-yum.repo
[Offline YUM]
name=Local YUM
baseurl=ftp://192.168.1.100/pub/CentOS/7
gpgcheck=0
enabled=1
Your client machine is now ready to receive updates over ftp. For configuring vsftpd server to share files with other Linux system , read tutorial here.

Both methods for sharing an offline yum over LAN are good & you can choose either of them, both of these methods should work fine. If you are having any queries/comments, please share them in the comment box down below.

Tlog - A Tool to Record / Play Terminal IO and Sessions

https://linoxide.com/linux-how-to/tlog-tool-record-play-terminal-io-sessions

Tlog is a terminal I/O recording and playback package for Linux Distros. It's suitable for implementing centralized user session recording. It logs everything that passes through as JSON messages. The primary purpose of logging in JSON format is to eventually deliver the recorded data to a storage service such as Elasticsearch, where it can be searched and queried, and from where it can be played back.  At the same time, they retain all the passed data and timing.
Tlog contains three tools namely tlog-rec, tlog-rec-session and tlog-play.
  • Tlog-rec tool is used for recording terminal input or output of programs or shells in general.
  • Tlog-rec-session tool is used for recording I/O of whole terminal sessions, with protection from recorded users.
  • Tlog-play tool for playing back the recordings.
In this article, I'll explain how to install Tlog on a CentOS 7.4 server.

Installation

Before proceeding with the install, we need to ensure that our system meets all the software requirements for compiling and installing the application. On the first step, update your system repositories and software packages by using the below command.
#yum update
We need to install the required dependencies for this software installation. I've installed all dependency packages with these commands prior to the installation.
#yum install wget gcc
#yum install systemd-devel json-c-devel libcurl-devel m4
After completing these installations, we can download the source package for this tool and extract it on your server as required:
#wget https://github.com/Scribery/tlog/releases/download/v3/tlog-3.tar.gz
#tar -xvf tlog-3.tar.gz
# cd tlog-3
Now you can start building this tool using our usual configure and make approach.
#./configure --prefix=/usr --sysconfdir=/etc && make
#make install
#ldconfig
Finally, you need to run ldconfig. It creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib).

Tlog workflow chart

Tlog working process
Firstly, a user authenticates to login via PAM.  The Name Service Switch (NSS) provides the information as tlog is a shell to the user. This initiates the tlog section and it collects the information from the Env/config files about the actual shell and starts the actual shell in a PTY. Then it starts logging everything passing between the terminal and the PTY via syslog or sd-journal.

Usage

You can test if session recording and playback work in general with a freshly installed tlog, by recording a session into a file with tlog-rec and then playing it back with tlog-play.

Recording to a file

To record a session into a file, execute tlog-rec on the command line as such:
tlog-rec --writer=file --file-path=tlog.log
This command will record our terminal session to a file named tlog.log and save it in the path specified in the command.

Playing back from a file

You can playback the recorded session during or after recording using tlog-play command.
tlog-play --reader=file --file-path=tlog.log
This command reads the previously recorded file tlog.log from the file path mentioned in the command line.

Wrapping up

Tlog is an open-source package which can be used for implementing centralized user session recording. This is mainly intended to be used as part of a larger user session recording solution but is designed to be independent and reusable.This tool can be a great help for recording everything users do and store it somewhere on the server side safe for the future reference. You can get more details about this package usage in this documentation. I hope this article is useful to you. Please post your valuable suggestions and comments on this.

Linux paste Command Explained For Beginners (5 Examples)

https://www.howtoforge.com/linux-paste-command

Sometimes, while working on the command line in Linux, there may arise a situation wherein you have to merge lines of multiple files to create more meaningful/useful data. Well, you'll be glad to know there exists a command line utility paste that does this for you. In this tutorial, we will discuss the basics of this command as well as the main features it offers using easy to understand examples.
But before we do that, it's worth mentioning that all examples mentioned in this article have been tested on Ubuntu 16.04 LTS.

Linux paste command

As already mentioned above, the paste command merges lines of files. Here's the tool's syntax:
paste [OPTION]... [FILE]...
And here's how the mage of paste explains it:
Write lines consisting of the sequentially corresponding lines from each FILE, separated by TABs, 
to standard output. With no FILE, or when FILE is -, read standard input.
The following Q&A-styled examples should give you a better idea on how paste works.

Q1. How to join lines of multiple files using paste command?

Suppose we have three files - file1.txt, file2.txt, and file3.txt - with following contents:
How to join lines of multiple files using paste command
And the task is to merge lines of these files in a way that each row of the final output contains index, country, and continent, then you can do that using paste in the following way:
paste file1.txt file2.txt file3.txt
result of merging lines

Q2. How to apply delimiters when using paste?

Sometimes, there can be a requirement to add a delimiting character between entries of each resulting row. This can be done using the -d command line option, which requires you to provide the delimiting character you want to use.
For example, to apply a colon (:) as a delimiting character, use the paste command in the following way:
paste -d : file1.txt file2.txt file3.txt
Here's the output this command produced on our system:
How to apply delimiters when using paste

Q3. How to change the way in which lines are merged?

By default, the paste command merges lines in a way that entries in the first column belongs to the first file, those in the second column are for the second file, and so on and so forth. However, if you want, you can change this so that the merge operation happens row-wise.
This you can do using the -s command line option.
paste -s file1.txt file2.txt file3.txt
Following is the output:
How to change the way in which lines are merged

Q4. How to use multiple delimiters?

Yes, you can use multiple delimiters as well. For example, if you want to use both : and |, you can do that in the following way:
paste -d ':|' file1.txt file2.txt file3.txt
Following is the output:
How to use multiple delimiters

Q5. How to make sure merged lines are NUL terminated?

By default, lines merged through paste end in a newline. However, if you want, you can make them NUL terminated, something which you can do using the -z option.
paste -z file1.txt file2.txt file3.txt

Conclusion

As most of you'd agree, the paste command isn't difficult to understand and use. It may offer a limited set of command line options, but the tool does what it claims. You may not require it on daily basis, but paste can be a real-time saver in some scenarios. Just in case you need, here's the tool's man page.