Skip to content

Instantly share code, notes, and snippets.

@dJani97
Forked from dariadobsai/Helper files
Last active January 11, 2019 12:28
Show Gist options
  • Save dJani97/c9b884b237f1334c1869d7c2155983af to your computer and use it in GitHub Desktop.
Save dJani97/c9b884b237f1334c1869d7c2155983af to your computer and use it in GitHub Desktop.
RedHat RHCSA common workflows
többiektől:
https://onedrive.live.com/?authkey=%21ABRgmNAPtpE8n7E&cid=B70386FBC114FFC7&id=B70386FBC114FFC7%215152&parId=root&o=OneUp
partitioning & common database issues:
https://imgur.com/a/hsIw1hx
RHLEARN:
rhlearn.gilmore.ca
## Configure the network
1. nmtui
2. nmcli
A) If you don't have any NetworkManager connection:
A.1) Add new NetworkManager connection:
nmcli con add con-name "Exam" ifname eth0 type ethernet ip4 172.25.201.X/24 gw4 172.25.201.254
nmcli con mod "Exam" ipv4.dns "172.25.201.254"
nmcli con mod "Exam" ipv4.method manual
nmcli con mod "Exam" connection.autoconnect yes
A.2) Activate new NetworkManager connection:
nmcli con up "Exam"
A.3) Verify NetorkManager connection and /etc/resolv.conf file:
nmcli con show "Exam"
cat /etc/resolv.conf
-------------------------------------------------------------------------
B) If you already have NetworkManager connection:
B.1) Add another NetworkManager connection:
nmcli con add con-name "Exam" ifname eth0 type ethernet ip4 172.25.201.X/24 gw4 172.25.201.254
nmcli con mod "Exam" ipv4.dns "172.25.201.254"
nmcli con mod "Exam" ipv4.method manual
nmcli con mod "Exam" connection.autoconnect yes
B.1.2) Activate new NetworkManager connection:
nmcli con up "Exam"
B.1.3) Disable old NetworkManager connection to Automatically connect during system start-up:
nmcli con mod "System eth0" connection.autoconnect no
B.1.4) Check NetworkManager connections and verify new NetworkManager connection:
nmcli con show
nmcli con show --active
nmcli con show "Exam"
B.1.5) optional - remove old unwanted NetworkManager connection:
nmcli con del "System eth0"
B.2) Edit already existing NetworkManager connection:
nmcli con mod "System eth0" ip4 172.25.201.X/24
nmcli con mod "System eth0" ipv4.gateway 172.25.201.254
nmcli con mod "System eth0" ipv4.dns "172.25.201.254"
nmcli con mod "System eth0" ipv4.method manual
nmcli con mod "System eth0" connection.autoconnect yes
B.2.1) Activate updated NetworkManager connection:
nmcli con up "System eth0"
B.2.2) Verify updated NetworkManager connection:
nmcli con show "System eth0"
-------------------------------------------------------------------------
## Useful nmcli commands
# To see a list of network devices and their state:
nmcli dev
or
nmcli dev status
# Show detailed information about devices:
nmcli dev show
and
nmcli dev show (device)
# To bring down an interface and temporarily disable autoconnect use command:
nmcli dev dis (device)
# Connect the device
nmcli dev con (device)
# To disable or enable all managed interfaces use command:
nmcli net off
nmcli net on
# To turn off wifi:
nmcli r wifi off
-------------------------------------------------------------------------
### Source -> https://www.youtube.com/watch?v=v-soSvSsw18&feature=share
┌───────────────────────────┤ Edit Connection ├───────────────────────────┐
│ │
│ Profile name Exam____________________________________ │
│ Device ________________________________________ │
│ │
│ ═ ETHERNET <Show> │
│ │
│ ╤ IPv4 CONFIGURATION <Manual> <Hide> │
│ │ Addresses 10.0.2.103/8_____________ <Remove> │
│ │ <Add...> │
│ │ Gateway 10.0.2.1_________________ │
│ │ DNS servers 10.0.2.1_________________ <Remove> │
│ │ <Add...> │
│ │ Search domains <Add...> │
│ │ │
│ │ Routing (No custom routes) <Edit...> │
│ │ [ ] Never use this network for default route │
│ │ [ ] Ignore automatically obtained routes │
│ │ [ ] Ignore automatically obtained DNS parameters │
│ │ │
│ │ [ ] Require IPv4 addressing for this connection │
│ └ │
│ │
│ ═ IPv6 CONFIGURATION <Automatic> <Show> │
│ │
│ [X] Automatically connect │
│ [X] Available to all users │
│ │
│ <Cancel> <OK> │
# Change to root user:
sudo su -
-------------------------------------------------------------------------
# Change to some user:
sudo su - username
sudo -i -u username
-------------------------------------------------------------------------
# Change the owner
chown newuser file-name
chown -R newuser dir-name
-------------------------------------------------------------------------
# Change the group
chgrp newgroup file-name
chgrp -R newgroup dir-name
-------------------------------------------------------------------------
# Change the password of any user
passwd username
-------------------------------------------------------------------------
# Get and Set the access control list (ACL) of a FILE
getfacl file-name
setfacl -m "u:username:rwx" file-name
-------------------------------------------------------------------------
# Get and Set the access control list (ACL) of a DIRECTORY
getfacl /path/to/the/folder
setfacl -Rm "u:username:rwX" /path/to/the/folder (g for group)
setfacl -Rm "d:u:username:rwx" /path/to/the/directory (default access to the file)
Apache accesses several directories on the file system:
– The apache binary, apache modules and shared libraries in /usr/bin, /usr/lib
– Confguration fles in /etc/httpd/*
– Web content in /var/www/html (by default)
– Server logs in /var/log/httpd/*
– Executable scripts (cgi-bin, python, php, …) in the web application directories for e.g. /usr/share/owncloud/*
– Documentation in /usr/share/doc/apache (The documentation is available in html format served as a web site)
– Possible more custom fles/directories
-------------------------------------------------------------------------
sudo yum -y install httpd httpd-manual
-------------------------------------------------------------------------
systemctl enable httpd.service
-------------------------------------------------------------------------
systemctl status httpd
-------------------------------------------------------------------------
systemctl start httpd.service
or
apachectl start
-------------------------------------------------------------------------
# Network security
firewall-cmd --permanent --add-service=http --add-service=https
firewall-cmd --reload
-------------------------------------------------------------------------
# To serve the default content outside, a new context rule must be addded
semanage fcontext -a -t httpd_sys_content_t '/new/location(/.*)?'
-------------------------------------------------------------------------
# Allow writable access for a group to the DocumnetRoot
setfacl -R -m g:groupname:rwX /var/www/html
setfacl -R -m d:g:groupname:rwx /var/www/html
-------------------------------------------------------------------------
# Change ServerAdmin
/etc/httpd/conf/httpd.conf
content of file: ServerAdmin username (webmaster@serverX.example.com)
# Create default content page
in /var/www/html/ we create index.html
write someting to the file using vim
-------------------------------------------------------------------------
-------------------------------------------------------------------------
Source -> https://rhlearn.gilmore.ca/node/156/take (redhat)
Source -> https://www.youtube.com/watch?v=PatSrUO4o8w (video tutorial)
Source -> https://www.youtube.com/watch?v=HlF1egrT4Wg (video tutorial 2)
# Create partition with the type 8e (Linux LVM)
fdisk /dev/hdb
(new) n
(primary) p
(type) t
(list) L (or just simply enter 8e directly)
press p to display the partition setup
press w to write the partition table
-------------------------------------------------------------------------
# Create Physical Volume
pvcreate /dev/vdb1
-------------------------------------------------------------------------
# Create Volume Group
vgcreate vg_name /dev/vdb1 (can vary)
-------------------------------------------------------------------------
# Create Logical Volume
lvcreate -n lv_name -L 5G vg_name (can vary -l 100%FREE)
Source -> https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/logical_volume_manager_administration/lv
-------------------------------------------------------------------------
# Create File System
mkfs -t xfs -L "label" /dev/vg_name/lv_name
or
mkfs.xfs -L "label" /dev/vg_name/lv_name
-------------------------------------------------------------------------
# Create temporary dir
mkdir /mnt/mysql (/mnt exists)
-------------------------------------------------------------------------
# Do mounting
mount /dev/vg_name/lv_name/ /mnt/mysql
-------------------------------------------------------------------------
# Stop the Mariadb service
systemctl stop mariadb
-------------------------------------------------------------------------
# Source of the copy operation
cat etc/my.cnf | grep datadir
-------------------------------------------------------------------------
# Copy the datastore directory to the new location
cp -a /var/lib/mysql /mnt/
cp -a /var/lib/mysql/* /mnt/mysql
-------------------------------------------------------------------------
# Check the permissions
ls -laZ /mnt
-------------------------------------------------------------------------
# Unmount new file system from the temporary directory
umount /mnt/mysql
-------------------------------------------------------------------------
# Start Mariabd
systemctl start mariadb
-------------------------------------------------------------------------
# Stop the Mariadb service
systemctl stop mariadb
-------------------------------------------------------------------------
# Make new dir
mkdir /backup
-------------------------------------------------------------------------
# Move all the files into new dir
mv var/lib/mysql/* /backup/
-------------------------------------------------------------------------
# Mount Persistently
1) vi /etc/fstab
2) file content: /dev/vg_first/lv_fisrt /var/lib/mysql auto defaults 0 0
3) mount -a
-------------------------------------------------------------------------
# Start Mariabd
systemctl start mariadb
-------------------------------------------------------------------------
# Check Mariabd status
systemctl status mariadb
__ MYSQL DUMP __
mkdir /backup
mysqldump --all-databases > /backup/full-dump.sql
__ APPEND TO PATH __
vi ~/.bash_profile
# add the following line to the end:
export PATH="/root/development/bin:$PATH"
__ CREATE SWAP FILE __
dd if=/dev/zero of=/swap.file bs=1M count=17
chmod 600 /swap.file
chown root:root /swap.file
mkswap /swap.file
# test it: swapon, swapoff
vi /etc/fstab # and add the following to the end:
/swap.file none swap sw 0 0
__ complicated wc+grep __
mkdir /mnt/iso
mount /exam-common/VBoxGuestAdditions.iso /mnt/iso
cd /mnt/iso
grep -rl "Solaris" | grep ".sh" | xargs wc -l | head -n2
__ apache debug __
systemctl status apache -l
# invalid something:
yum provides <invalid-file-name>
yum reinstall <invalid-pkg-name>
#check content type (alternative path: /var/www/html)
ls -laZ /www-root/html
chmod apache:apache /www-root/html
semanage fcontext -a -t httpd_sys_content_type '/www-root/html(/.*)?'
# systemctl enable httpd !!!!
# Create File Systems
mkfs -t btrfs /dev/vdb1 (file systems: xfs, ext4..)
-------------------------------------------------------------------------
# Label (btrfs) File Systems
btrfs filesystem label /dev/vdb1 "label-name"
-------------------------------------------------------------------------
# Label (ext4) File Systems
e2label /dev/vdb1 label-name
-------------------------------------------------------------------------
# Label (xfs) File Systems
xfs_admin -L "label-name" /dev/vdb1
-------------------------------------------------------------------------
# Mount File Systems
1. create new temprorary directory
mkdir tempdir
-------------------------------------------------------------------------
2. apply mount command
mount /dev/vdb1 /tempdir
df -h (check mounting)
-------------------------------------------------------------------------
3. cp -pr /home/* /tempdir/
-------------------------------------------------------------------------
4. umount /tempdir
-------------------------------------------------------------------------
5. Get partition's UUID
blkid /dev/vdb1
or
lsblk -o name,uuid
-------------------------------------------------------------------------
6. persistent mounting
vi /etc/fstab
UUID=48516887-51fc-4930-af9f-735c9c0c3f2e /home btrfs defaults 0 0
mount -a
-------------------------------------------------------------------------
7. view mounted FSs
mount | grep vdb1
-------------------------------------------------------------------------
Source -> https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/storage_administration_guide/s2-disk-storage-parted-create-part#s3-disk-storage-parted-create-part-mkfs
# Login to mysql
mysql -u root -p
-------------------------------------------------------------------------
# Create database
CREATE DATABASE databasename;
-------------------------------------------------------------------------
# Use database
use databasename;
-------------------------------------------------------------------------
# Create tables of the database
MariaDB [databasename]> CREATE TABLE example (
did TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
dname VARCHAR(20),PRIMARY KEY(did));
MariaDB [databasename]> CREATE TABLE example (
id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(20),PRIMARY KEY(id));
-------------------------------------------------------------------------
# Show tables of the database
show tables;
-------------------------------------------------------------------------
# Show the schema or layout of the table using the DESCRIBE command
DESCRIBE databasename;
-------------------------------------------------------------------------
Source -> https://www.youtube.com/watch?v=qxPnGlIxYC8 (video tutorial)
Source -> https://www.theurbanpenguin.com/rhce-creating-a-database-in-mariadb-using-rhel-7-1/ (sql commands)
Source -> https://mariadb.com/kb/en/library/what-to-do-if-mariadb-doesnt-start/ (What to Do if MariaDB Doesn't Start)
netstat -tulnp
yum install mariadb mariadb-client
hostnamectl set-hostname <hostname>
setenforce Enforcing
blkid
vgextend <vg_name> /dev/sdc4
for i in /dev/sd[a-z];do parted $i unit s print; done
## blokk számolás:
stat <filename>
du -b <filename>
## Create Partitions
# List disks:
a) lsblk
b) lsblk -o name,label,fstype
-------------------------------------------------------------------------
# Create MBR disk partition
fdisk /dev/vdb
n (new partition)
p (primary partition)
1 (default partition number) can vary
enter (fist sector) can vary
enter (last sector) can vary
enter or t (define the type)
w (write changes)
-------------------------------------------------------------------------
# Create GPT disk partition
gdisk /dev/vdb
n (new partition)
p (primary partition)
1 (default partition number) can vary
enter (fist sector) can vary
enter (last sector) can vary
enter or L (define the type)
w (write changes)
y
-------------------------------------------------------------------------
### Source -> https://rhlearn.gilmore.ca/node/357/take
# SSH into CLIENT computer:
ssh username@desktopX
-------------------------------------------------------------------------
# Now that we are in the CLIENT computer, we do these commands:
# first we try to log into the SERVER with our password, it should work
ssh username@serverX
exit
# now we generate the key, and copy it onto the server
ssh-keygen
ssh-copy-id username@serverX
# then we try to log into the SERVER again, this time it shouldn't ask for password
ssh username@serverX
## Add new user
useradd -m username (-m for the home directory)
-------------------------------------------------------------------------
## Add new group
groupadd groupname
-------------------------------------------------------------------------
## Add user to the group
usermod -ag groupname username
-------------------------------------------------------------------------
Source -> https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/s1-users-tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment