Friday, 27 October 2017

RHEL 7 Database MariaDb

                     MariaDB

 

MariaDB is a binary replacement for MYSQL,

MariaDB is Default Database RHEL 7

 

To Install MariaDB packages:

 

 

 

[root@server ~]# yum install -y mariadb mariadb-server

Loaded plugins: fastestmirror, langpacks

base                                                                  Determining fastest mirrors

Resolving Dependencies

--> Running transaction check

---> Package mariadb.x86_64 1:5.5.56-2.el7 will be installed

---> Package mariadb-server.x86_64 1:5.5.56-2.el7 will be installed

--> Processing Dependency: perl-DBI for package: 1:mariadb-server-5.5.56-2.el7.x86_64

--> Processing Dependency: perl-DBD-MySQL for package: 1:mariadb-server-5.5.56-2.el7.x86_64

--> Processing Dependency: perl(Data::Dumper) for package: 1:mariadb-server-5.5.56-2.el7.x86_64

--> Processing Dependency: perl(DBI) for package: 1:mariadb-server-5.5.56-2.el7.x86_64

--> Running transaction check

---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be installed

---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : perl-Data-Dumper-2.145-3.el7.x86_64                      Installing : 1:mariadb-5.5.56-2.el7.x86_64                            Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64               Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64              Installing : perl-IO-Compress-2.061-2.el7.noarch                      Installing : perl-Net-Daemon-0.48-5.el7.noarch                        Installing : perl-PlRPC-0.2020-14.el7.noarch                          Installing : perl-DBI-1.627-4.el7.x86_64                              Installing : perl-DBD-MySQL-4.023-5.el7.x86_64                        Installing : 1:mariadb-server-5.5.56-2.el7.x86_64                  

 

Installed:

mariadb.x86_64 1:5.5.56-2.el7                                       mariadb-server.x86_64 1:5.5.56-2.el7

 

Complete!

 

 

                                                                          

                                                                                            To Activate the MariaDB Service

 

 

[root@server ~]# systemctl enable mariadb.service

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

 

 

 

To Start the MariaDB

 

 

[root@server ~]# systemctl start mariadb

 

 

 

To Execute the basic setup: mysql_secure_installation

     Change the root password ?[Y/n] n

     Remove anonymous users? [Y/n]Y

     Disallow root login remotely? [Y/n]y

     Remove test database and acces to it? [Y/n]Y

     Reload privilege tables now? [Y/n]y

 

 

[root@server ~]# mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):

OK, successfully used password, moving on...

 

Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.

 

Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

 ... Success!

 

 

 

 

 

By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] y

 ... Success!

 

Normally, root should only be allowed to connect from 'localhost'.  This ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] y

 ... Success!

 

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] y

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

 

Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

 

Reload privilege tables now? [Y/n] y

 ... Success!

 

Cleaning up...

 

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

 

Thanks for using MariaDB!

 

 

To Check MariaDb Installed version.

 

[root@server ~]# mysql -V

mysql  Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (x86_64) using readline 5.1

 

 

 

To Add mysql to the firewall configuration and reload it

 

 

 

[root@server ~]# firewall-cmd --permanent --add-service=mysql

success

[root@server ~]# firewall-cmd --reload

success

[root@server ~]#

 

 

To Login to Mysql or MariaDB

 

 

 

[root@server ~]# mysql -u root -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 10

Server version: 5.5.56-MariaDB MariaDB Server

 

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

 

 

 

To Create database OnlineCourseDB

 

 

MariaDB [(none)]> create database OnlineCourseDB;

Query OK, 1 row affected (0.01 sec)

 

 

 

To List All Database in MariaDB Console

 

MariaDB [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| OnlineCourseDB     |

| mysql              |

| performance_schema |

+--------------------+

4 rows in set (0.00 sec)

 

 

To Remove database OnlineCourseDB

 

 

 

MariaDB [OnlineCourseDB]> drop database OnlineCourseDB;

Query OK, 2 rows affected (0.08 sec)

 

 

To go inside database OnlineCourseDB

 

MariaDB [(none)]> USE OnlineCourseDB;

Database changed

MariaDB [OnlineCourseDB]>

 

 

To Create Table CourseTBL in database OnlineCourseDB

 

 

MariaDB [OnlineCourseDB]> CREATE TABLE CourseTBL (

    -> CourseID INT NOT NULL AUTO_INCREMENT,

    -> CourseName VARCHAR(100),

    -> PRIMARY KEY(CourseID)

    -> );

Query OK, 0 rows affected (0.08 sec)

 

 

To Describe Table Structure CourseTBL

 

 

To Create Table ProgrammingTBL in database OnlineCourseDB

 

 

MariaDB [OnlineCourseDB]> CREATE TABLE ProgrammingTBL (

    -> ProgrammeID INT NOT NULL AUTO_INCREMENT,

    -> ProgrammeName VARCHAR(100) NOT NULL,

    -> InstructorID INT NOT NULL,

    -> ProgrammePrice DECIMAL(6,2) NOT NULL,

    -> ProgrammeIsAvailable BOOLEAN,

    -> PRIMARY KEY(ProgrammeID)

    -> );

Query OK, 0 rows affected (0.00 sec)

 

 

 

To Insert into table CourseTBL

 

MariaDB [OnlineCourseDB]> INSERT INTO CourseTBL (CourseName) VALUES ('JAVA'), ('PHP'), ('MYSQL');

Query OK, 3 rows affected (0.03 sec)

Records: 3  Duplicates: 0  Warnings: 0

 

 

 

 

To View selective Record from Table CourseTBL

 

 

MariaDB [OnlineCourseDB]> SELECT * FROM CourseTBL WHERE CourseName='JAVA';

+----------+------------+

| CourseID | CourseName |

+----------+------------+

|        1 | JAVA       |

+----------+------------+

1 row in set (0.00 sec)

 

 

To ALL Record from Table CourseTBL

 

 

MariaDB [OnlineCourseDB]> SELECT * FROM CourseTBL;

+----------+------------+

| CourseID | CourseName |

+----------+------------+

|        1 | JAVA       |

|        2 | PHP        |

|        3 | MYSQL      |

+----------+------------+

3 rows in set (0.00 sec)

 

 

To Insert record into table ProgrammingTBL

 

MariaDB [OnlineCourseDB]>MariaDB [OnlineCourseDB]> INSERT INTO ProgrammingTBL (ProgrammeName, InstructorID, ProgrammePrice, ProgrammeIsAvailable)

    -> VALUES ('JAVA', 100, 2000, 1),

    -> ('PHP', 103, 2300.0, 1),

    -> ('MYSQL',107, 8435.99, 1);

Query OK, 3 rows affected (0.00 sec)

Records: 3  Duplicates: 0  Warnings: 0

 

 

 

To view Selective record from table ProgrammingTBL

 

MariaDB [OnlineCourseDB]> SELECT * FROM ProgrammingTBL;

 

 

To update selective record from table ProgrammingTBL

 

MariaDB [OnlineCourseDB]> UPDATE ProgrammingTBL SET ProgrammePrice=9999.99 WHERE ProgrammeID=2;

Query OK, 1 row affected, 1 warning (0.05 sec)

Rows matched: 1  Changed: 1  Warnings: 1

 

 

 

 

To Delete selective Record table ProgrammingTBL

 

 

MariaDB [OnlineCourseDB]> DELETE FROM ProgrammingTBL WHERE ProgrammeID=2;

Query OK, 1 row affected (0.07 sec)

 

 

To Create User OnlineCourseuser with password agoutam

 

 

MariaDB [OnlineCourseDB]> CREATE USER OnlineCourseuser@localhost IDENTIFIED BY 'agoutam';

Query OK, 0 rows affected (0.00 sec

 

 

 

 

 

To provide permission to User OnlineCourseuser on database OnlineCourseDB

 

MariaDB [OnlineCourseDB]> GRANT ALL PRIVILEGES ON  OnlineCourseDB.* to OnlineCourseuser@localhost;

Query OK, 0 rows affected (0.01 sec)

 

MariaDB [OnlineCourseDB]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

 

 

To take Back up of database called OnlineCourseDB

 

 

[root@server ~]# mysqldump --user=root --password="root" --result-file=course.sql OnlineCourseDB

 

[root@server ~]# ls -lrt course.sql

-rw-r--r--. 1 root root 2867 Oct 27 15:39 course.sql

 

 

 

To view Dump Database sql file course.sql

 

 

[root@server ~]# tail -20 course.sql

-- Dumping data for table `ProgrammingTBL`

 

LOCK TABLES `ProgrammingTBL` WRITE;

/*!40000 ALTER TABLE `ProgrammingTBL` DISABLE KEYS */;

INSERT INTO `ProgrammingTBL` VALUES (1,'JAVA',100,2000.00,1),(3,'MYSQL',107,8435.99,1);

/*!40000 ALTER TABLE `ProgrammingTBL` ENABLE KEYS */;

UNLOCK TABLES;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;

/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;

/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

 

-- Dump completed on 2017-10-27 15:39:13

 

 

To Restore from back up course.sql to database  OnlineCourseDB

 

[root@server ~]# mysql --user=root --password="root" OnlineCourseDB<course.sql

 

Thursday, 26 October 2017

What Is Kerberos? Kerberos Authentication Explained.


RHEL7 Samba Network Sharing

Samba Network Sharing

                                     

 

 

Introduction

 

Most Linux systems are the part of networks that also run Windows systems. Using Linux Samba servers, your Linux and Windows systems can share directories and printers.

 

Samba is an open-source implementation of the Server Message Block (SMB) and Common Internet File System (CIFS) protocols that provides file and print services between clients across various operating systems

 

Samba Configuration File:

 

The default configuration file (/etc/samba/smb.conf) allows users to view their home directories as a Samba share. It also shares all printers configured for the system as Samba shared printers. In other words, you can attach a printer to the system and print to it from the Windows machines on your network.

 

            Samba Server and Samba Client Machine Details

 

 

[root@server ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain

::1         localhost localhost.localdomain

 

192.168.56.101 server.agoutam.com server

192.168.56.102 client.agoutam.com client

192.168.56.101 www.agoutam.com

 

 

Where :

            Samba Server Run : 192.168.56.101 server.agoutam.com server

            Samba Client Run : 192.168.56.102 client.agoutam.com client

 

 

Samba Services and Port for Firewall to open In order to Run Samba Service

 

Ports you need to open for two-way samba communication with Windows and Linux desktop systems.

 

NetBIOS-ns – 137/tcp # NETBIOS Name Service

netbios-dgm – 138/tcp # NETBIOS Datagram Service

netbios-ssn – 139/tcp # NETBIOS session service

microsoft-ds – 445/tcp # if you are using Active Directory

 

Port 445 (TCP) – NetBIOS was moved to 445 after 2000 and beyond, (CIFS)


# firewall-cmd --permanent --zone=public --add-service=samba

# firewall-cmd --reload

OR

# firewall-cmd --permanent --add-port=137/tcp

# firewall-cmd --permanent --add-port=138/tcp

# firewall-cmd --permanent --add-port=139/tcp

# firewall-cmd --permanent --add-port=445/tcp

 

 

 

 

 

To Install the Samba packages

 

 

[root@server ~]# yum install -y samba

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

Resolving Dependencies

--> Running transaction check

---> Package samba.x86_64 0:4.6.2-8.el7 will be installed

--> Processing Dependency: samba-libs = 4.6.2-8.el7 for package: samba-4.6.2-8.el7.x86_64

--> Processing Dependency: samba-common-tools = 4.6.2-8.el7 for package: samba-4.6.2-8.el7.x86_64

--> Processing Dependency: libxattr-tdb-samba4.so(SAMBA_4.6.2)(64bit) for package: samba-4.6.2-8.el7.x86_64

--> Processing Dependency: libxattr-tdb-samba4.so()(64bit) for package: samba-4.6.2-8.el7.x86_64

--> Running transaction check

---> Package samba-common-tools.x86_64 0:4.6.2-8.el7 will be installed---> Package samba-libs.x86_64 0:4.6.2-8.el7 will be installed

 

Total download size: 1.3 M

Installed size: 3.7 M

Downloading packages:

 (2/4): samba-4.6.2-8.el7.x86_64.rpm                                  (3/4): samba-common-tools-4.6.2-8.el7.x86_64.rpm                      (4/4): samba-libs-4.6.2-8.el7.x86_64.rpm                              ----------------------------------------------------------------

Total                                                                 1.5 MB/s | 1.3 MB  00:00:00

Running transaction

  Installing : pytalloc-2.1.9-1.el7.x86_64                              Installing : samba-libs-4.6.2-8.el7.x86_64                            Installing : samba-common-tools-4.6.2-8.el7.x86_64                    Installing : samba-4.6.2-8.el7.x86_64                                 Verifying  : pytalloc-2.1.9-1.el7.x86_64                              Verifying  : samba-libs-4.6.2-8.el7.x86_64                            Verifying  : samba-common-tools-4.6.2-8.el7.x86_64                    Verifying  : samba-4.6.2-8.el7.x86_64                              

Installed:

  samba.x86_64 0:4.6.2-8.el7

 

Dependency Installed:

  pytalloc.x86_64 0:2.1.9-1.el7                      samba-common-tools.x86_64 0:4.6.2-8.el7                      samba-libs.x86_64 0:4.6.2-8.el7

 

Complete!

 

 

 

 

To Create Shared Folder for Network sharing

 

 

[root@server ~]# mkdir -v /sambasharing

mkdir: created directory ‘/sambasharing’

 

 

To provide Permission to Shared Folder

 

[root@server ~]# chown 770 /sambasharing

 

 

To Create File inside Samba Shared Directory

 

 

 

[root@server sambasharing]# touch file1 file2 file3

[root@server sambasharing]# ls

file1  file2  file3

 

 

To Create Samba User and Password

 

 

[root@server sambasharing]# useradd agsamba

[root@server sambasharing]# smbpasswd -a agsamba

New SMB password:

Retype new SMB password:

Added user agsamba.

[root@server sambasharing]#

 

 

To Create samba group

 

 

[root@server sambasharing]# groupadd smbusers

 

 

To change ownership of /sambasharing folder to smbusers

 

 

[root@server sambasharing]# chown :smbusers /sambasharing

 

 

 

 

 

 

To Add user agsamba to Secondary Group smbusers

 

 

[root@server sambasharing]# usermod -G smbusers agsamba

[root@server sambasharing]# grep smbusers /etc/group

smbusers:x:1006:agsamba

 

 

To view Group Information of agsamba User.

 

 

[root@server sambasharing]# id agsamba

uid=1005(agsamba) gid=1005(agsamba) groups=1005(agsamba),1006(smbusers)

[root@server sambasharing]#

 

 

Verify Configuration changes using testparm command checks smb.conf configuration file for internal correctness

 

[root@server sambasharing]# testparm

Load smb config files from /etc/samba/smb.conf

rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

Processing section "[homes]"

Processing section "[printers]"

Processing section "[print$]"

Processing section "[sambadir]"

Loaded services file OK.

Server role: ROLE_STANDALONE

 

Press enter to see a dump of your service definitions

 

# Global parameters

[global]

        server string = Samba server Version %v

        workgroup = AGOUTAM SAMBA

        log file = /var/log/samba/log.%m

        max log size = 50

        printcap name = cups

        security = USER

        idmap config * : backend = tdb

        cups options = raw

        hosts allow = 127. 192.168.56.

 

 

[homes]

        comment = Home Directories

        browseable = No

        inherit acls = Yes

        read only = No

        valid users = %S %D%w%S

 

 

[printers]

        comment = All Printers

        path = /var/tmp

        browseable = No

        printable = Yes

        create mask = 0600

 

 

[print$]

        comment = Printer Drivers

        path = /var/lib/samba/drivers

        create mask = 0664

        directory mask = 0775

        write list = root

 

#sambadir is Name of Samba Sharing and /sambasharing is shared folder

[sambadir]

        comment = Centos7 Samba Share

        path = /sambasharing

        guest ok = Yes

        read only = No

 

To Enable Samba Service at Boot time.

 

 

[root@server sambasharing]# systemctl enable smb

Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.

 

 

 

To Start Samba Service

 

 

[root@server sambasharing]# systemctl start smb

 

 

To Set up the correct SELinux context for /sambasharing                                                                                       

 

 

[root@server sambasharing]# semanage fcontext -a -t samba_share_t "/sambasharing (/.*)?"                                                   

[root@server sambasharing]# restorecon -R /sambasharing

 

 

                               

 

To Add Samba Service and open default port in  firewall

 

 

[root@server sambasharing]# firewall-cmd --permanent --add-service=samba

success

 

 

To View status of Samba Service

 

[root@server sambasharing]# systemctl status smb

? smb.service - Samba SMB Daemon

   Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)

   Active: active (running) since Mon 2017-10-23 11:29:55 IST; 2min 22s ago

 Main PID: 2342 (smbd)

   Status: "smbd: ready to serve connections..."

   CGroup: /system.slice/smb.service

           ??2342 /usr/sbin/smbd

          

 

Oct 23 11:29:55 server systemd[1]: Starting Samba SMB Daemon...

Oct 23 11:29:55 server smbd[2342]: [2017/10/23 11:29:55.671610,  0] ../lib/...y)

Oct 23 11:29:55 server systemd[1]: Started Samba SMB Daemon.

Oct 23 11:29:55 server smbd[2342]:   STATUS=daemon 'smbd' finished starting...ns

Hint: Some lines were ellipsized, use -l to show in full.

 

          

Client Configuration to Connect to Samba server

    

 

To Install Samba client package

 

 

[root@client ~]# yum -y install samba-client samba-windbind

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

Package samba-client-4.6.2-8.el7.x86_64 already installed and latest version

No package samba-windbind available.

Nothing to do

[root@client ~]#

 

 

 

 

 

Verifying client instance i.e connecting from client Computer

smbclient <path> <credentials>

smbclient //192.168.56.101/sambadir -U agsamba

 

 

[root@client ~]# smbclient //192.168.56.101/sambadir -U agsamba

Enter SAMBA\agsamba's password:

Domain=[SERVER] OS=[Windows 6.1] Server=[Samba 4.6.2]

smb: \> ls

  .                                   D        0  Mon Oct 23 11:09:23 2017

  ..                                 DR        0  Mon Oct 23 11:06:58 2017

  file1                               N        0  Mon Oct 23 11:09:23 2017

  file2                               N        0  Mon Oct 23 11:09:23 2017

  file3                               N        0  Mon Oct 23 11:09:23 2017

 

                10873856 blocks of size 1024. 3439320 blocks available

smb: \>

 

 

 

To View Information of Samba Shared Directory

 

 

 

[root@client ~]# smbclient -L //192.168.56.101 -N

Anonymous login successful

OS=[Windows 6.1] Server=[Samba 4.6.2]

 

        Sharename       Type      Comment

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

        print$          Disk      Printer Drivers

        sambadir        Disk      Centos7 Samba Share

        IPC$            IPC       IPC Service (Samba server Version 4.6.2)

Anonymous login successful

OS=[Windows 6.1] Server=[Samba 4.6.2]

 

        Server               Comment

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

 

        Workgroup            Master

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

 

 

 

 

 

To Mount Samba file system on Client Machine

          

 

To install Packaged required for Mounting ,yum install cifs-utils

 

 

[root@client ~]# yum install -y cifs-utils

Loaded plugins: fastestmirror, langpacks

Loading mirror speeds from cached hostfile

Package cifs-utils-6.2-10.el7.x86_64 already installed and latest version

Nothing to do

 

 

 

 

To Create Mount Directory in Client Machine

 

 

 

[root@client ~]# mkdir /smb

 

 

 To Create Mount Point for Samba Network Sharing

 

 

 

[root@client ~]# mount.cifs //192.168.56.101/sambadir /smb -o user=agsamba

Password for agsamba@//192.168.56.101/sambadir:  *******

[root@client ~]# df -hT

Filesystem                Type      Size  Used Avail Use% Mounted on

/dev/mapper/centos-root   xfs        21G  7.2G   14G  34% /

devtmpfs                  devtmpfs  905M     0  905M   0% /dev

tmpfs                     tmpfs     920M     0  920M   0% /dev/shm

tmpfs                     tmpfs     920M  8.8M  911M   1% /run

tmpfs                     tmpfs     920M     0  920M   0% /sys/fs/cgroup

/dev/sda1                 xfs      1014M  178M  837M  18% /boot

tmpfs                     tmpfs     184M   12K  184M   1% /run/user/42

tmpfs                     tmpfs     184M     0  184M   0% /run/user/0

//192.168.56.101/sambadir cifs       11G  7.1G  3.3G  69% /smb

 

 

 

                                     

To  Access Samba Server from Window machine

                               

 

Step 1 :Got To Run And Type \\192.68.56.101\sambadir

Step 2:Window will open to Provide password for authentication Provide Password

Step 3:To View Samba Shared Directory in Window ,In Browser Type IP Address of Samba Server Host Machine

 

Step 4:To View Content of Samba Shared Directory,Go to sambadir where sambadir is name of samba Shared  folder

What is iSCSI and How Does it Work?