November 2018
M T W T F S S
« Oct    
 1234
567891011
12131415161718
19202122232425
2627282930  

Categories

WordPress Quotes

A real decision is measured by the fact that you've taken a new action. If there's no action, you haven't truly decided.
Tony Robbins

Recent Comments

November 2018
M T W T F S S
« Oct    
 1234
567891011
12131415161718
19202122232425
2627282930  

Short Cuts

2012 SERVER (64)
2016 windows (9)
AIX (13)
Amazon (34)
Ansibile (18)
Apache (133)
Asterisk (2)
cassandra (2)
Centos (209)
Centos RHEL 7 (258)
chef (3)
cloud (2)
cluster (3)
Coherence (1)
DB2 (5)
DISK (25)
DNS (9)
Docker (28)
Eassy (11)
ELKS (1)
EXCHANGE (3)
Fedora (6)
ftp (5)
GIT (3)
GOD (2)
Grub (1)
Hacking (10)
Hadoop (6)
horoscope (23)
Hyper-V (10)
IIS (15)
IPTABLES (15)
JAVA (7)
JBOSS (32)
jenkins (1)
Kubernetes (2)
Ldap (5)
Linux (189)
Linux Commands (167)
Load balancer (5)
mariadb (14)
Mongodb (4)
MQ Server (22)
MYSQL (84)
Nagios (5)
NaturalOil (13)
Nginx (30)
Ngix (1)
openldap (1)
Openstack (6)
Oracle (34)
Perl (3)
Postfix (19)
Postgresql (1)
PowerShell (2)
Python (3)
qmail (36)
Redis (12)
RHCE (28)
SCALEIO (1)
Security on Centos (29)
SFTP (1)
Shell (64)
Solaris (58)
Sql Server 2012 (4)
squid (3)
SSH (10)
SSL (14)
Storage (1)
swap (3)
TIPS on Linux (28)
tomcat (60)
Uncategorized (29)
Veritas (2)
vfabric (1)
VMware (28)
Weblogic (38)
Websphere (71)
Windows (19)
Windows Software (2)
wordpress (1)
ZIMBRA (17)

WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.

Who's Online

23 visitors online now
4 guests, 19 bots, 0 members

Hit Counter provided by dental implants orange county

Performance Tuning in centos7

Performance Tuning in centos7

Tuned

In RedHat (and thus CentOS) 7.0, a daemon called “tuned” was introduced as a unified system for applying tunings to Linux. tuned operates with simple, file-based tuning “profiles” and provides an admin command-line interface named “tuned-adm” for applying, listing and even recommending tuned profiles.

Some operational benefits of tuned:

  • File-based configuration – Profile tunings are contained in a simple, consolidated files
  • Swappable profiles – Profiles are easily changed back/forth
  • Standards compliance – Using tuned profiles ensures tunings are not overridden or ignored

Note: If you use configuration management systems like Puppet, Chef, Salt, Ansible, etc., I suggest you configure those systems to deploy tunings via tuned profiles instead of applying tunings directly, as tuned will likely start to fight this automation, overriding the changes.

The default available tuned profiles (as of  RedHat 7.2.1511) are:

  • balanced
  • desktop
  • latency-performance
  • network-latency
  • network-throughput
  • powersave
  • throughput-performance
  • virtual-guest
  • virtual-host

The profiles that are generally interesting for database usage are:

  • latency-performance

    “A server profile for typical latency performance tuning. This profile disables dynamic tuning mechanisms and transparent hugepages. It uses the performance governer for p-states through cpuspeed, and sets the I/O scheduler to deadline.”

  • throughput-performance

    “A server profile for typical throughput performance tuning. It disables tuned and ktune power saving mechanisms, enables sysctl settings that improve the throughput performance of your disk and network I/O, and switches to the deadline scheduler. CPU governor is set to performance.”

  • network-latency – Includes “latency-performance,” disables transparent_hugepages, disables NUMA balancing and enables some latency-based network tunings.
  • network-throughput – Includes “throughput-performance” and increases network stack buffer sizes.

I find “network-latency” is the closest match to our recommended tunings, but some additional changes are still required.

T

Tuning a server according to specific requirements is not an easy task. You need to know a lot of system parameters and how to change them in a intelligent manner.
Red Hat offers a tool called tuned-adm that makes these changes easy by using tuning profiles.

The tuned-adm command requires the tuned package (if not already installed):

# yum install -y tuned

Tuning Profiles

A tuning profile consists in a list of system changes corresponding to a specific requirement.
To get the list of the available tuning profiles, type:

# tuned-adm list
Available profiles:
- balanced
- desktop
- latency-performance
- network-latency
- network-throughput
- powersave
- sap
- throughput-performance
- virtual-guest
- virtual-host
Current active profile: virtual-guest

Note: All these tuning profiles are explained in details in the tuned-adm man page.

To only get the active profile, type:

# tuned-adm active
Current active profile: virtual-guest

To get the recommended tuning profile in your current configuration, type:

# tuned-adm recommend
virtual-guest

To apply a different tuning profile (here throughput-performance), type:

# tuned-adm profile throughput-performance

cpu setting

tuned-adm profile throughput-performance
tuned-adm active
cpupower idle-set -d 4
cpupower idle-set -d 3
cpupower idle-set -d 2
cpupower frequency-set -g performance
# for more info /usr/lib/tuned/throughput-performance/tuned.conf

 

sysctl

kernel.numa_balancing=0

net.core.netdev_max_backlog = 300000
net.ipv4.tcp_sack = 0
net.core.netdev_budget=600
net.ipv4.tcp_timestamps=1
net.ipv4.tcp_low_latency=1
net.ipv4.tcp_rmem=16384 349520 16777216
net.ipv4.tcp_wmem=16384 349520 16777216
net.ipv4.tcp_mem = 2314209      3085613 4628418
net.core.rmem_max=16777216
net.core.wmem_max=16777216
net.core.somaxconn=2048
net.ipv4.tcp_adv_win_scale=1
net.ipv4.tcp_window_scaling = 1
#UDP buffer
net.core.rmem_max=16777216

Linux Kernel Tuning for Centos 7

 

tuned` should already be installed for Cent 7 and default profile is balanced.

tuned-adm profiles can be found in this directory

ls /usr/lib/tuned/
 
balanced/               latency-performance/    powersave/              virtual-guest/
desktop/                network-latency/        recommend.conf          virtual-host/
functions               network-throughput/     throughput-performance/

To see what the active profile is:

tuned-adm active

To activated tuned xxx

tuned-adm profile xxx

 

latency-performance

  • latency-performance
    • Profile for low latency performance tuning.
    • Disables power saving mechanisms.
    • CPU governor is set to performance and locked to the low C states (by PM QoS).
    • CPU energy performance bias to performance.
    • This profile is the Parent profile to “network-latency”.

Activate tuned latency-performance for CentOS 7

tuned-adm profile latency-performance

For CentOS 7, the latency-performance profile includes the following tweaks

cat /usr/lib/tuned/latency-performance/tuned.conf
[cpu]
force_latency=1
governor=performance
energy_perf_bias=performance
min_perf_pct=100
 
[sysctl]
kernel.sched_min_granularity_ns=10000000
vm.dirty_ratio=10
vm.dirty_background_ratio=3
vm.swappiness=10
kernel.sched_migration_cost_ns=5000000

network-latency

  • network-latency
    • This is a Child profile of “latency-performance”.
    • That this means is that if you were to activate network-latency profile via tuned, it would automatically enable latency-performance, then make some additional tweaks to improve network latency.
    • Disables transparent hugepages, and makes some net.core kernel tweaks.

 

cat /usr/lib/tuned/network-latency/tuned.conf
[main]
include=latency-performance
 
[vm]
transparent_hugepages=never
 
[sysctl]
net.core.busy_read=50
net.core.busy_poll=50
net.ipv4.tcp_fastopen=3
kernel.numa_balancing=0

throughput-performance

  • throughput-performance
    • This is the Parent profile to virtual-guest, virtual-host and network-throughput.
    • This profile is optimized for large, streaming files or any high throughput workloads.

 

cat /usr/lib/tuned/throughput-performance/tuned.conf
[cpu]
governor=performance
energy_perf_bias=performance
min_perf_pct=100
 
[vm]
transparent_hugepages=always
 
[disk]
readahead=>4096
 
[sysctl]
kernel.sched_min_granularity_ns = 10000000
kernel.sched_wakeup_granularity_ns = 15000000
vm.dirty_ratio = 40
vm.dirty_background_ratio = 10
vm.swappiness=10

virtual-guest

  • virtual-guest
    • Profile optimized for virtual guests based on throughput-performance profile.
    • It additionally decreases virtual memory swapiness and increases dirty_ratio settings.

 

cat /usr/lib/tuned/virtual-guest/tuned.conf
[main]
include=throughput-performance
 
[sysctl]
vm.dirty_ratio = 30
vm.swappiness = 30

virtual-host

  • virtual-host
    • Profile optimized for virtual hosts based on throughput-performance profile.
    • It additionally enables more aggressive write-back of dirty pages.

 

cat /usr/lib/tuned/virtual-host/tuned.conf
[main]
include=throughput-performance
 
[sysctl]
vm.dirty_background_ratio = 5
kernel.sched_migration_cost_ns = 5000000

I/O scheduler

echo 'deadline' > /sys/block/sda/queue/scheduler
vim /etc/grub2.cfg

menuentry ‘CAKE 3.0, with Linux 3.10.0-229.1.2.el7.x86_64′
set root=’hd0,msdos1’
linux16 /vmlinuz-3.10.0-229.1.2.el7.x86_64 root= …. elevator=deadline
initrd16 /initramfs-3.10.0-229.1.2.el7.x86_64.img

WinPE 10-8 Sergei Strelec

WinPE 10-8 Sergei Strelec (x86/x64/Native x86) 2018.01.05 English Version | File size: 2.89 GB

Bootable disk Windows 10 and 8 PE – for maintenance of computers, hard disks and partitions, backup and restore disks and partitions, computer diagnostics, data recovery, Windows installation.

WinPE 10-8 Sergei Strelec (x86/x64/Native x86) 2017.10.03 English Version

The World’s Most Advanced Microsoft Windows 10 USB Bootable OS

The Portable Microsoft Windows 10 Operating System For Cyber Agent

 

 

Backup and restore
Acronis True Image 2017 20.0 Build 8058
Acronis True Image Premium 2014 Build 6673
Acronis Backup Advanced 11.7.50064
Active Disk Image Professional 7.0.4
StorageCraft Recovery Environment 5.2.5.37836
FarStone Recovery Manager 10.10
QILING Disk Master 4.3.6.20170806
R-Drive Image 6.1 Build 6109
Symantec Veritas System Recovery 16.0.2.56166
Symantec Ghost 12.0.0.10561
TeraByte Image for Windows 3.15
AOMEI Backupper 4.0.6
Drive SnapShot 1.45.0.17689
Macrium Reflect 7.1.2801
Disk2vhd 2.01
Vhd2disk v0.2

Hard disk
Acronis Disk Director 12.0.3297
EASEUS Partition Master 12.5 WinPE Edition
Paragon Hard Disk Manager 15 10.1.25.1137
MiniTool Partition Wizard 10.2.2
AOMEI Partition Assistant 6.6.0
AOMEI Dynamic Disk Manager 1.2.0
Eassos PartitionGuru 4.9.5.508
Defraggler 2.21.993
Auslogics Disk Defrag 7.1.0
HDD Low Level Format Tool 4.40
Active KillDisk 10.1.1
FarStone DriveClone 11.10 Build 20150825 (WinPE10)

Diagnostics
HD Tune Pro 5.70
Check Disk GUI
Victoria 4.47
HDD Regenerator 2011
HDDScan 3.3
Hard Disk Sentinel Pro 5.01 Build 8557
Western Digital Data LifeGuard Diagnostics 1.31.0
CrystalDiskInfo 7.5.1
CrystalDiskMark 6.0.0
AIDA64 Extreme Edition 5.92.4300
BurnInTest Pro 8.1 Build 1025
PerformanceTest 9.0 Build 1022
ATTO Disk Benchmark 3.05
RWEverything 1.7
CPU-Z 1.82.1
PassMark MonitorTest 3.2 Build 1004
HWiNFO32 5.70 Build 3300
OCCT Perestroika 4.5.1
Keyboard Test Utility 1.4.0

Network programs
Opera 46
PENetwork 0.58.2
TeamViewer 6
Ammyy Admin 3.5
AeroAdmin 4.1 Build 2767
µTorrent 3.1.3
FileZilla 3.24.0
Internet Download Accelerator 6.10.1.1527
OpenVpn 2.4.4
PuTTY 0.70

Other programs
Active Password Changer 7.0.9.1
Reset Windows Password 4.2.0.470
PCUnlocker 3.8.0
UltraISO 9.7.0 Build 3476
Total Commander 9.00
Remote Registry (?86/64)
FastStone Capture 7.7
IrfanView 4.38
STDU Viewer
Bootice 1.3.4
Unlocker 1.9.2
7-ZIP
WinNTSetup 3.8.8.3
Double Driver 4.1.0
Imagex
GImageX 2.1.1
Media Player Classic
EasyBCD 2.3
EasyUEFI 3.0
SoftMaker Office
Far Manager 3.0 Build 5100
BitLocker
78Setup (author conty9)
Dism++ 10.1.1000.52B
WinHex 19.3
FastCopy 3.40
UltraSearch 2.12
Everything 1.4.1.877
Linux Reader 2.6
WinDirStat 1.1.2
Recover Keys 10.0.4.198
NirLauncher 1.20.25
Remote Registry Editor
Windows Recovery Environment (WinPE 10)

Data Recovery
R-Studio 8.5 Build 170117
Active File Recovery 15.0.7
Active Partition Recovery 15.0.0
Runtime GetDataBack for NTFS 4.33
Runtime GetDataBack for FAT 4.33
DM Disk Editor and Data Recovery 2.10.0
UFS Explorer Professional Recovery 5.23.1
Hetman Partition Recovery 2.7
Eassos Recovery 4.2.1.297
EaseUS Data Recovery Wizard 11.9

 

 

How-to extend a root LVM partition online

How-to extend a root LVM partition online

This guide will explain you how to extend a root LVM partition online.

There is also a quick remedy for the emergency situation when your root partition runs out of disk space. There is a feature specific to ext3 and ext4 that can help the goal of resolving the full disk situation. Unless explicitly changed during filesystem creation, both by default reserve five percent (5%) of a volume capacity to the superuser (root).

# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_main-lv_root
              ext4    8.4G  8.0G  952K 100% /
tmpfs        tmpfs    499M     0  499M   0% /dev/shm
/dev/vda1     ext4    485M   33M  428M   8% /boot

# dumpe2fs /dev/vg_main/lv_root | grep 'Reserved block count'
dumpe2fs 1.41.12 (17-May-2010)
Reserved block count:     111513

It turned out 111513 of 4KB blocks were reserved for the superuser, which was exactly five percent of the volume capacity.

How to enable it?

# tune2fs -m 0 /dev/vg_main/lv_root 
tune2fs 1.41.12 (17-May-2010)
Setting reserved blocks percentage to 0% (0 blocks)
# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_main-lv_root
              ext4    8.4G  8.0G  437M  95% /
tmpfs        tmpfs    499M     0  499M   0% /dev/shm
/dev/vda1     ext4    485M   33M  428M   8% /boot

Now that we have some free space on the root partition to work on we can extend the LVM partition:

Create a new partition of appropriate size using fdisk

fdisk /dev/sdb1

This is a key sequence on the keyboard to create a new LVM type (8e) partition:

n, p, 1, enter (accept default first sector), enter (accept default last sector), t, 8e, w

Create a new Physical Volume

# pvcreate /dev/sdb1
  Writing physical volume data to disk "/dev/sdb1"
  Physical volume "/dev/sdb1" successfully created

Extend a Volume Group

# vgextend vg_main /dev/sdb1
  Volume group "vg_main" successfully extended

Extend your LVM

– extend the size of your LVM by the amount of free space on PV

# lvextend /dev/vg_main/lv_root /dev/sdb1
  Extending logical volume lv_root to 18.50 GiB
  Logical volume lv_root successfully resized

– or with a given size

lvextend -L +10G /dev/vg_main/lv_root

Finally resize the file system online

# resize2fs /dev/vg_main/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_main/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_main/lv_root to 4850688 (4k) blocks.
The filesystem on /dev/vg_main/lv_root is now 4850688 blocks long.

Now we can set the reserved blocks back to the default percentage – 5%

tune2fs -m 5 /dev/mapper/vg_main-lv_root

Results:

# df -Th
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_main-lv_root
              ext4     19G  8.0G  9.4G  46% /
tmpfs        tmpfs    499M     0  499M   0% /dev/shm
/dev/vda1     ext4    485M   33M  428M   8% /boot

Firewalld Centos-7

As of Centos7 the default firewall application has changed from iptables to firewalld. FirewallD provides dynamic filterinc versus static ones in iptables. You can read more about details of the features included at Fedora project page here and or on their official homepage here.

This page will help me to unlearn the iptables and remember the firewalld commands.

Get Initial information

  • Get the status of firewalld
 firewall-cmd --state
  • Reload the firewall without loosing state information:
 firewall-cmd --reload
  • Get a list of all supported zones
 firewall-cmd --get-zones
  • Get a list of all supported services
 firewall-cmd --get-services
  • Get a list of all supported icmptypes
 firewall-cmd --get-icmptypes
  • List all zones with the enabled features.
 firewall-cmd --list-all-zones
  • Print zone <zone> with the enabled features. If zone is omitted, the default zone will be used.
 firewall-cmd [--zone=<zone>] --list-all
  • Get the default zone set for network connections
 firewall-cmd --get-default-zone
  • Set the default zone
 firewall-cmd --set-default-zone=<zone>

All interfaces that are located in the default zone will be pushed in the new default zone, that defines the limitations for new external initiated connection attempts. Active connections are not affected.

  • Get active zones
 firewall-cmd --get-active-zones
  • Get zone related to an interface
 firewall-cmd --get-zone-of-interface=<interface>

 

Update the basic rules

This prints the zone name, if the interface is part of a zone

  • Add an interface to a zone
 firewall-cmd [--zone=<zone>] --add-interface=<interface>

Add an interface to a zone, if it was not in a zone before. If the zone options is omitted, the default zone will be used. The interfaces are reapplied after reloads.

  • Change the zone an interface belongs to
 firewall-cmd [--zone=<zone>] --change-interface=<interface>

This is similar to the –add-interface options, but pushes the interface in the new zone even if it was in another zone before.

  • Remove an interface from a zone
 firewall-cmd [--zone=<zone>] --remove-interface=<interface>
  • Query if an interface is in a zone
 firewall-cmd [--zone=<zone>] --query-interface=<interface>

Returns if the interface is in the zone. There is no output.

  • List the enabled services in a zone
 firewall-cmd [ --zone=<zone> ] --list-services
  • Enable panic mode to block all network traffic in case of emergency
 firewall-cmd --enable-panic
  • Disable panic mode
 firewall-cmd --disable-panic
  • Query panic mode
 firewall-cmd --query-panic

This returns the state of the panic mode, there is no output. To get a visual state use

 firewall-cmd --query-panic && echo "On" || echo "Off"

Runtime zone handling

In the runtime mode the changes to zones are not permanent. The changes will be gone after reload or restart.

  • Enable a service in a zone
 firewall-cmd [--zone=<zone>] --add-service=<service> [--timeout=<seconds>]

This enables a service in a zone. If zone is not set, the default zone will be used. If timeout is set, the service will only be enabled for the amount of seconds in the zone. If the service is already active, there will be no warning message.

  • Example: Enable ipp-client service for 60 seconds in the home zone:
 firewall-cmd --zone=home --add-service=ipp-client --timeout=60
  • Example: Enable the http service in the default zone:
 firewall-cmd --add-service=http
  • Disable a service in a zone
 firewall-cmd [--zone=<zone>] --remove-service=<service>

This disables a service in a zone. If zone is not set, the default zone will be used.

  • Example: Disable http service in the home zone:
 firewall-cmd --zone=home --remove-service=http

The service will be disabled in the zone. If the service is not enabled in the zone, there will be an warning message.

  • Query if a service is enabled in a zone
 firewall-cmd [--zone=<zone>] --query-service=<service>

This returns 1 if the service is enabled in the zone, otherwise 0. There is no output.

  • Enable a port and protocol combination in a zone
 firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]

This enables a port and protocol combination. The port can be a single port or a port range -. The protocol can be either tcp or udp.

  • Disable a port and protocol combination in a zone
 firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
  • Query if a port and protocol combination in enabled in a zone
 firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

This command returns if it is enabled, there is no output.

Masquerading

This is used to hide internal addresses behind a public IP or port.

  • Enable masquerading in a zone
 firewall-cmd [--zone=<zone>] --add-masquerade

This enables masquerading for the zone. The addresses of a private network are mapped to and hidden behind a public IP address. This is a form of address translation and mostly used in routers. Masquerading is IPv4 only because of kernel limitations.

  • Disable masquerading in a zone
 firewall-cmd [--zone=<zone>] --remove-masquerade
  • Query masquerading in a zone
 firewall-cmd [--zone=<zone>] --query-masquerade

This command returns if it is enabled, there is no output.

  • Enable ICMP blocks in a zone
 firewall-cmd [--zone=<zone>] --add-icmp-block=<icmptype>

This enabled the block of a selected Internet Control Message Protocol (ICMP) message. ICMP messages are either information requests or created as a reply to information requests or in error conditions.

  • Disable ICMP blocks in a zone
 firewall-cmd [--zone=<zone>] --remove-icmp-block=<icmptype>
  • Query ICMP blocks in a zone
 firewall-cmd [--zone=<zone>] --query-icmp-block=<icmptype>

This command returns if it is enabled, there is no output.

  • Example: Block echo-reply messages in the public zone:
 firewall-cmd --zone=public --add-icmp-block=echo-reply
  • Enable port forwarding or port mapping in a zone
 firewall-cmd [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

The port is either mapped to the same port on another host or to another port on the same host or to another port on another host. The port can be a singe port <port> or a port range <port>-<port>. The protocol is either tcp or udp. toport is either port or a port range -. toaddr is an IPv4 address. Port forwarding is IPv4 only because of kernel limitations.

  • Disable port forwarding or port mapping in a zone
 firewall-cmd [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  • Query port forwarding or port mapping in a zone
 firewall-cmd [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

This command returns if it is enabled, there is no output.

  • Example: Forward ssh to host 127.0.0.2 in the home zone
 firewall-cmd --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2

Permanent zone handling

The permanent options are not affecting runtime directly. These options are only available after a reload or restart. To have runtime and permanent setting, you need to supply both. The –permanent option needs to be the first option for all permanent calls.

  • Get a list of supported permanent services
 firewall-cmd --permanent --get-services
  • Get a list of supported permanent icmptypes
 firewall-cmd --permanent --get-icmptypes
  • Get a list of supported permanent zones
 firewall-cmd --permanent --get-zones
  • Enable a service in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-service=<service>

This enables the service in the zone permanently. If the zone option is omitted, the default zone is used.

  • Disable a service in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-service=<service>
  • Query if a service is enabled in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-service=<service>

This command returns if it is enabled, there is no output.

  • Example: Enable service ipp-client permanently in the home zone
 firewall-cmd --permanent --zone=home --add-service=ipp-client
  • Enable a port and protocol combination permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>
  • Disable a port and protocol combination permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
  • Query if a port and protocol combination is enabled permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

This command returns if it is enabled, there is no output.

  • Example: Enable port 443/tcp for https permanently in the home zone
 firewall-cmd --permanent --zone=home --add-port=443/tcp
  • Enable masquerading permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-masquerade

This enables masquerading for the zone. The addresses of a private network are mapped to and hidden behind a public IP address. This is a form of address translation and mostly used in routers. Masquerading is IPv4 only because of kernel limitations.

  • Disable masquerading permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-masquerade
  • Query masquerading permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-masquerade

This command returns if it is enabled, there is no output.

  • Enable ICMP blocks permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-icmp-block=<icmptype>

This enabled the block of a selected Internet Control Message Protocol (ICMP) message. ICMP messages are either information requests or created as a reply to information requests or in error conditions.

  • Disable ICMP blocks permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-icmp-block=<icmptype>
  • Query ICMP blocks permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-icmp-block=<icmptype>

This command returns if it is enabled, there is no output.

  • Example: Block echo-reply messages in the public zone:
 firewall-cmd --permanent --zone=public --add-icmp-block=echo-reply
  • Enable port forwarding or port mapping permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

The port is either mapped to the same port on another host or to another port on the same host or to another port on another host. The port can be a singe port <port> or a port range <port>-<port>. The protocol is either tcp or udp. toport is either port or a port range -. toaddr is an IPv4 address. Port forwarding is IPv4 only because of kernel limitations.

  • Disable port forwarding or port mapping permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  • Query port forwarding or port mapping permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

This command returns if it is enabled, there is no output.

  • Example: Forward ssh to host 127.0.0.2 in the home zone
 firewall-cmd --permanent --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2

Direct options

The direct options give a more direct access to the firewall. These options require user to know basic iptables concepts, i.e. table (filter/mangle/nat/…), chain (INPUT/OUTPUT/FORWARD/…), commands (-A/-D/-I/…), parameters (-p/-s/-d/-j/…) and targets (ACCEPT/DROP/REJECT/…). Direct options should be used only as a last resort when it’s not possible to use for example –add-service=service or –add-rich-rule=’rule’. The first argument of each option has to be ipv4 or ipv6 or eb. With ipv4 it will be for IPv4 (iptables(8)), with ipv6 for IPv6 (ip6tables(8)) and with eb for ethernet bridges (ebtables(8)).

  • Pass a command through to the firewall. <args> can be all iptables, ip6tables and ebtables command line arguments
 firewall-cmd --direct --passthrough { ipv4 | ipv6 | eb } <args>
  • Add a new chain <chain> to a table <table>.
 firewall-cmd [--permanent] --direct --add-chain { ipv4 | ipv6 | eb } <table> <chain>
  • Remove a chain with name <chain> from table <table>.
 firewall-cmd [--permanent] --direct --remove-chain { ipv4 | ipv6 | eb } <table> <chain>
  • Query if a chain with name <chain> exists in table <table>. Returns 0 if true, 1 otherwise.
 firewall-cmd [--permanent] --direct --query-chain { ipv4 | ipv6 | eb } <table> <chain>

This command returns if it is enabled, there is no output.

  • Get all chains added to table <table> as a space separated list.
 firewall-cmd [--permanent] --direct --get-chains { ipv4 | ipv6 | eb } <table>
  • Add a rule with the arguments <args> to chain <chain> in table <table> with priority <priority>.
 firewall-cmd [--permanent] --direct --add-rule { ipv4 | ipv6 | eb } <table> <chain> <priority> <args>
  • Remove a rule with the arguments <args> from chain <chain> in table <table>.
 firewall-cmd [--permanent] --direct --remove-rule { ipv4 | ipv6 | eb } <table> <chain> <args>
  • Query if a rule with the arguments <args> exists in chain <chain> in table <table>. Returns 0 if true, 1 otherwise.
 firewall-cmd [--permanent] --direct --query-rule { ipv4 | ipv6 | eb } <table> <chain> <args>

This command returns if it is enabled, there is no output.

  • Get all rules added to chain <chain> in table <table> as a newline separated list of arguments.
 firewall-cmd [--permanent] --direct --get-rules { ipv4 | ipv6 | eb } <table> <chain>

Docker centos7

Introduction

In previous posts we have seen the installation and working of Docker. This post will explain the installation of the Docker Community Edition (CE) on CentOS. If you are looking for the Ubuntu installation you should check our this post.

 

Step 1 | Remove Old Versions

$ sudo yum remove docker docker-common docker-selinux docker-engine

Step 2 | Install Required Packages

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Step 3 | Setup the Docker CE Repository

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Step 4 | Update the Packages

$ sudo yum update

Step 5 |Install specific version (Production recommended)

$ sudo yum list docker-ce.x86_64  --showduplicates | sort -r

Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Available Packages

$ sudo yum install docker-ce-<VERSION>

Step 6 | Install through respository

$ sudo yum install docker-ce

Step 7 | Start Docker

$ sudo systemctl start docker

Step 8 | Verify the Installation

$ sudo docker run hello-world

This will install the Docker on CentOS.

Redis

what is Redis

Redis is a key-value storage system. Similar to Memcached, it supports storing relatively many value types, including string, list, set, and zset.
These data types support push / pop, add / remove, and intersection and union and difference sets and richer operations, all of which are atomic.
On this basis, Redis supports a variety of different sorts. Like memcached, data is cached in memory for efficiency.
The difference is that Redis periodically writes updated data to disk or writes modifications to additional log files and implements master-slave synchronization based on this. Redis is a high-performance key-value database.
The emergence of Redis, a large extent, to compensate for such lack of keyvalue memcached storage, in some cases can play a good complement to the relational database.

 

1, Redis installation

1.1 Pre-installation environment description

Using a CentOS 7 version of Linux system with
master ip of 192.168.1.110
slave ip of 192.168.1.111 The

1.2 Download Redis

Redis can go to the official website to download: https://redis.io/download , now the latest stable version has reached 4.0.
Used here is redis-4.0.1.tar.gz .

1.3 installation steps

$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar xzf redis-4.0.1.tar.gz -C /usr/local/
$ cd /usr/local/redis-4.0.1
$ make & make test
make Possible exceptions

make[1]: Leaving directory `/usr/local/redis-4.0.1/src’ make[1]: Entering directory `/usr/local/redis-4.0.1/src’
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/local/redis-4.0.1/src’
make: *** [test] Error 2
solution

yum install -y tcl

2, Redis simple configuration

All configuration changes are in this configuration file

/usr/local/redis-4.0.1/redis.conf

 

2.2 bound host address

Bind after the host to add ip,from behind Redis need to connect through the IP.

bind 127.0.0.1 192.168.1.110

2.3 Set Redis password

The password is set herejaven

# requirepass foobared
requirepass mohan

2.4 Set the Redis port number

The default port is6379

port 6379

3, test Redis

start up
/usr/local/redis-4.0.1/redis.conf
src/redis-server

src/redis-server redis.conf
Client connection

src/redis-cli
src/redis-cli -a mohan

/usr/local/redis-4.0.1/redis.conf
src/redis-cli shutdown
src/redis-cli -p 6666 shutdown

 

4, Redis master-slave replication configuration

Redis master-slave replication is very powerful, a master can have multiple slaves, and a slave can have multiple slaves, so go on, forming a powerful multi-level server cluster architecture. The following simple configuration.

Modify the slave’s redis configuration file

Master’s redis configuration file bindcan be set as long as

Slave redis modify the slave configuration file slaveof 10.211.55.3 6379 (mapped to the main server, 6379the port number)
can also be dynamically set:
Redis-cli connected to the slave node server, execute the following command.
slaveof 10.211.55.3 6379

If master sets the authentication password, you also need to configure masterauth. Here I set the master authentication password javen, so configure masterauth javen.

After configuring the slave start the Redis service, OK, master-slave configuration is completed (is not very simple).
The following test:
In the master and slave, respectively, the info command to view the results are as follows:

slave:

[root@centos-linux-2 redis-4.0.1]# src/redis-cli
127.0.0.1:6379> info

 

 

5, Redis remote connection

Usage: redis-cli [OPTIONS] [cmd [arg [arg …]]]

-h <host ip>, the default is 127.0.0.1

-p <port>, the default is 6379

-a <password>, redis lock, you need to pass the password

-help, Show help information

redis-cli -h 10.211.55.4 -p 6379 -a javen

 

Master and slave MySQL versions are MySQL5.6.31

Master and slave MySQL versions are MySQL5.6.31

Primary server IP: 192.168.1.178

From the server IP: 192.168.1.145

Master and slave are able to ping each other.

A?192.168.1.178?Master?
B?192.168.1.145?Slave?

 

service mysqld stop
service mysqld start
service mysqld restart

 

mysql> grant replication slave on *.* to ‘mohan’@’192.168.1.145’ identified by ‘123456’;
mysql> flush privileges;

vi /etc/my.cnf

port=3306

binlog-ignore-db=mysql
server-id=1
expire-logs-days=7
binlog-ignore-db=information_schema
binlog-ignore-db=performation_schema
binlog-ignore-db=sys
binlog-ignore-db=gogs

service mysqld restart

mysql -u root -proot -P3306
mysql> flush tables with read lock;

show master status;

mysql> show master status;
+——————+———-+————–+——————————————————-+——————-+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+——————+———-+————–+——————————————————-+——————-+
| mysql-bin.000001 | 154 | | mysql,information_schema,performation_schema,sys,gogs | |
+——————+———-+————–+——————————————————-+——————-+
1 row in set (0.00 sec)

5 Slave

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-bin=mysql-bin
server-id=3
binlog-ignore-db = mysql
binlog-ignore-db = information_schema
binlog-ignore-db = performation_schema
binlog-ignore-db = sys
log-slave-updates
slave-skip-errors=all
slave-net-timeout=60

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

 

service mysqld restart

 

mysql> stop slave;
mysql> change master to master_host=’192.168.1.178′,master_user=’mohan’,master_password=’123456′,master_log_file=’mysql-bin.000001′, master_log_pos= 154;
mysql> show slave status \G;

mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql>

Setting up MySQL server on aws EC2 instance

Launch an EC2 instance of type Amazon Linux AMI from your aws console.

SSH into your ec2 instance
ssh -i ec2-user@my_ec2_ip_address

Update the instance
sudo yum update -y

Install the mysqld server
sudo yum install -y mysql55-server

start the mysqld instance
sudo service mysqld start

the following command ensure launches mysqld on server restart
sudo chkconfig mysqld on

run the following command to set password for root user and delete test databases.
sudo mysql_secure_installation

make a note of the root password ????

Let’s try to create a user and database. This way we can control the database access levels.
mysql -uroot -pmy_root_password

I’m going to create a db_demo with demo_user having password demo123.
CREATE DATABASE db_demo;
USE db_demo;
CREATE USER 'demo_user'@'localhost' IDENTIFIED BY 'demo123';
GRANT ALL PRIVILEGES ON *.* TO 'demo_user'@'localhost' WITH GRANT OPTION;
CREATE USER 'demo_user'@'%' IDENTIFIED BY 'demo123';
GRANT ALL PRIVILEGES ON *.* TO 'demo_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;

That’s it. You are all set.

Note:

    • details on mysql privileges can be found here
    • Don’t forget to open the default port 3306 if you want to access the database outside the ec2 instance boundary
    • useful mysqld commands

  • sudo service mysqld start
  • sudo service mysqld stop
  • sudo service mysqld restart
  • sudo service mysqld status

 

Setting git on aws EC2 instance

Launch an EC2 instance of type Amazon Linux AMI from your aws console.

SSH into your ec2 instance
ssh -i ec2-user@my_ec2_ip_address

Update the instance
sudo yum update -y

install developer tools
sudo yum groupinstall -y "Development Tools"

install git
sudo yum install git

checkout the source code
git clone https://my.git.repo.git
cd my_local_git_folder
git checkout -f branch_to_checkout

Installing node.js on amazon EC2 instance

Launch an EC2 instance of type Amazon Linux AMI from your aws console.

SSH into your ec2 instance
ssh -i ec2-user@my_ec2_ip_address

Update the instance
sudo yum update -y

#install developer tools
sudo yum groupinstall -y "Development Tools"

Install the node using nvm as it allows you to switch between any version of the node ????
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install 4.4.5
node -e "console.log('Running Node.js ' + process.version)"

Install pm2
npm install pm2 -g --save

pull the source code in ec2 instance. run your node app using pm2
pm2 start app.js --name="api"