Use realm/adcli to join RHEL7/8/9 to AD


For RHEL 7

# yum install realmd oddjob oddjob-mkhomedir sssd adcli krb5-workstation authconfig

adcli info test.com
# adcli join test.com
Password for Administrator@TEST.COM:  <---- Enter Admin password

The join operation creates an /etc/krb5.keytab keytab that the machine will authenticate with. you can run below command to show several entries
# klist -kte

Configure /etc/krb5.conf to use AD domain:

[libdefaults]
default_realm = TEST.COM
dns_lookup_realm = true
dns_lookup_kdc = true
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
udp_preference_limit  = 1

[realms]
TEST.COM = {
#kdc = ad1.test.com
#admin_server = ad1.test.com
}

[domain_realm]
.test.com = TEST.COM
test.com = TEST.COM


Use authconfig to set up the Name Service Switch (/etc/nsswitch.conf) and PAM stacks(/etc/pam.d/password-authand /etc/pam.d/system-auth):

# authconfig --enablesssd --enablesssdauth --enablelocauthorize --enablemkhomedir --update

#cat /etc/sssd/sssd.conf
[sssd]
domains = test.com

config_file_version = 2
services = nss, pam

[domain/test.com]
access_provider = simple
ad_domain = test.com
ad_gpo_access_control = permissive
ad_server = ad1.test.com, ad2.test.com
auto_private_groups = true   #all ad users have gid same as uid
cache_credentials = true
default_shell = /bin/bash
fallback_homedir = /home/%u    # same as local user home folder location
id_provider = ad
krb5_realm = TEST.COM
krb5_store_password_if_offline = true
ldap_id_mapping = true     # use id mapping from kerberos instead of postix uid/gid defintion in AD
ldap_schema = ad
ldap_user_ssh_public_key = sshPublicKey
realmd_tags = manages-system, joined-with-samba
simple_allow_groups = ssh users
use_fully_qualified_names = false

[nss]

[pam]

# chown root:root /etc/sssd/sssd.conf
# chmod 600 /etc/sssd/sssd.conf

# id username


For RHEL 8/9

# yum install realmd sssd oddjob oddjob-mkhomedir krb5-workstation authselect-compat adcli [samba-common-tools]

#realm discover example.com
#realm list
#realm join example.com
 Password for Administrator:

#authselect select sssd with-mkhomedir with-faillock without-nullok --force
#systemctl enable sssd.service --now
#systemctl enable oddjobd.service --now

A keytab is a file containing pairs of Kerberos principals and encrypted keys

[root@test1 ~]# more /etc/realmd.conf
[users]
default-home = /home/%U
default-shell = /bin/bash

[service]
automatic-install = yes

[providers]
sssd = yes

[active-directory]
default-client = sssd

[test.com]
fully-qualified-names = no
automatic-id-mapping = yes


# other commands

#realm leave
#klist -k /etc/krb5.keytab
#authconfig --test

 Ansible.cfg Best Practice

                            

Ansible.cfg is the important parameters to control how Ansible and ansible-playbook behaves.

The following parameters are best practice, please put it to the same folder as ansible.cfg file.


Reference:  

https://www.ansible.com/blog/using-ansible-to-manage-rhel-5-yesterday-today-and-tomorrow

https://docs.ansible.com/ansible/latest/reference_appendices/config.html 


[ssh_connection]
ssh_args = '-o ControlMaster=auto -o ControlPersist=60s  -o ServerAliveInterval=60 -o ServerAliveCountMax=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
retries=5
pipelining = True

[defaults]
command_warnings=False
host_key_checking = false
timeout = 60
remote_tmp = /tmp

How to install ansible2.11 with python36 on RHEL7

                                  by Jephe Wu - http://linuxtechres.blogspot.com


Install python36 packages from subscription or RHEL7.9 ISO

[root@test ]# more /etc/yum.repos.d/local.repo
[localrepo]
name=Unixmen Repository
baseurl=file:///cdrom
gpgcheck=0
enabled=1

yum localinstall python3 python3-pip python3-rpm-generators python3-rpm-macros python3 python3-setuptools

    

Use EPEL

[root@test ]# grep proxy /etc/yum.conf
proxy=http://proxy.domain.com:8080

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

 

use pip3 to install ansible

pip3 install --upgrade pip

pip3 cache purge

export LANG=en_AU.UTF8

pip3 install ansible   ( or python3 -m pip install ansible )

pip3 install pywinrm

 

Check if win_ modules are there

run ansible-doc win_reboot

find /user/local/  -name "win_*"

 

 

[root@test unixadm]# pip3 install pywinrm
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Collecting pywinrm
Downloading pywinrm-0.4.2-py2.py3-none-any.whl (44 kB)
|████████████████████████████████| 44 kB 920 kB/s
Collecting requests>=2.9.1
Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)
|████████████████████████████████| 62 kB 1.2 MB/s
Collecting six
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting xmltodict
Downloading xmltodict-0.12.0-py2.py3-none-any.whl (9.2 kB)
Collecting requests-ntlm>=0.3.0
Downloading requests_ntlm-1.1.0-py2.py3-none-any.whl (5.7 kB)
Collecting charset-normalizer~=2.0.0
Downloading charset_normalizer-2.0.9-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
Downloading certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
|████████████████████████████████| 149 kB 28.9 MB/s
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.7-py2.py3-none-any.whl (138 kB)
|████████████████████████████████| 138 kB 37.7 MB/s
Collecting idna<4,>=2.5
Downloading idna-3.3-py3-none-any.whl (61 kB)
|████████████████████████████████| 61 kB 11.2 MB/s
Requirement already satisfied: cryptography>=1.3 in /usr/local/lib64/python3.6/site-packages (from requests-ntlm>=0.3.0->pywinrm) (36.0.0)
Collecting ntlm-auth>=1.0.2
Downloading ntlm_auth-1.5.0-py2.py3-none-any.whl (29 kB)
Requirement already satisfied: cffi>=1.12 in /usr/local/lib64/python3.6/site-packages (from cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm) (1.15.0)
Requirement already satisfied: pycparser in /usr/local/lib/python3.6/site-packages (from cffi>=1.12->cryptography>=1.3->requests-ntlm>=0.3.0->pywinrm) (2.21)
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests, ntlm-auth, xmltodict, six, requests-ntlm, pywinrm
WARNING: The script normalizer is installed in '/usr/local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2021.10.8 charset-normalizer-2.0.9 idna-3.3 ntlm-auth-1.5.0 pywinrm-0.4.2 requests-2.26.0 requests-ntlm-1.1.0 six-1.16.0 urllib3-1.26.7 xmltodict-0.12.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

 

Note: pip3 will download packages from site below

 

 How to find out which process is using swap space

                                     Jephe  Wu  - http://linuxtechres.blogspot.com

 

https://dbsysupgrade.com/how-to-display-processes-using-swap-space/


Use command below to find out pid and percentage of swap usage.

# find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" -v TOTSWP="$(cat /proc/meminfo | sed -n -e "s/^SwapTotal:[ ]*\([0-9]*\) kB/\1/p")" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") {used_swap=process["VmSwap"];sub(/[ a-zA-Z]+/,"",used_swap);percent=(used_swap/TOTSWP*100); printf "%10s %-30s %20s %6.2f%\n",process["Pid"],process["Name"],process["VmSwap"],percent} }' '{}' \; | awk '{print $(NF-2),$0}' | sort -hr | head | cut -d " " -f2-

Installing Ansible with winrm module for Windows server automation

                    by Jephe Wu - http://linuxtechres.blogspot.com

Steps

set proxy for /etc/yum.conf

proxy= http://proxy.domain.com:8080

Disable redhat registration

[root@ansible01 pluginconf.d]# grep enabled /etc/yum/pluginconf.d/subscription-manager.conf

enabled=0

Install EPEL release for yum repo

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Download and install ansible packages from EPEL together with local RHEL7 ISO mount

yum localinstall *  => install all below packages



Testing playbook


[root@ansible01 ~]# more hosts.ini
[win:vars]
ansible_user='DOMAIN\jephe'
ansible_password=xxxxxxxxxxx
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
#ansible_winrm_scheme=http
ansible_port=5985
#ansible_winrm_transport=kerberos
#ansible_winrm_transport=credssp
ansible_winrm_transport=ntlm

[win]
192.168.1.10

root@ansible01 ~]# ansible -i hosts.ini win  -m win_ping

192.168.1.10 | SUCCESS => {
    "changed": false,
    "ping": "pong"

}

[root@ansible01 ~]# more win_play.yml
---

- name: test
  hosts: all
  become_method: runas

  tasks:

    - name: whoami

      win_shell: mkdir c:\tmp\jewu2

[root@ansible01 ~]# ansible-playbook -i hosts.ini win_play.yml

PLAY [test] ****************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************
ok: [192.168.1.10]

TASK [whoami] **************************************************************************************************************************************
changed: [192.168.1.10]

PLAY RECAP *****************************************************************************************************************************************

192.168.1.10              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
===============

 How to manually configure ntpd and chronyd on RHEL 6/7/8

                              by Jephe Wu   - http://linuxtechres.blogspot.com



Add below lines into /etc/chrony.conf or /etc/ntp.conf

server x.x.x.x iburst

server y.y.y.y iburst 


Manually update time once

systemctl stop ntpd

ntpdate x.x.x.x

 

systemctl stop chronyd

chronyd -q 'server x.x.x.x iburst'


[root@server1 ]#  chronyd -q 'server 192.168.1.100 iburst'
2021-11-25T05:08:34Z chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG)
2021-11-25T05:08:34Z Initial frequency -11.868 ppm
2021-11-25T05:08:38Z System clock wrong by 0.000087 seconds (step)
2021-11-25T05:08:38Z chronyd exiting

Show current ntp stauts

ntpq -pn

chronyc [-n] sources


How to setup an ideal rsync task between two Linux servers

                                            by Jephe Wu - http://linuxtechres.blogspot.com

 

Summary

There's some issue for syncing server a(source) to server b (dest.) which caused server b partition full, in order to solve the problem, we need to adjust some rsync parameters for cronjob task.


Original rsync task under root cronjob

*/30 * * * *  /usr/bin/rsync --numeric-ids -avr --exclude=.snapshot 192.168.1.10::share/* /share

Note: this has caused server b /share partition full due to it won't delete files on destination site.


In order to make a full sync working again, we will need to manually run task below which will delete first to free up space, then sync files again.

/usr/bin/rsync --numeric-ids -avr --delete --delete-before --ignore-errors --exclude=.snapshot 192.168.1.10::share/* /share


The rsync daemon config on server a is below:

[root@servera share]# more /etc/rsyncd.conf

reverse lookup = false

[share]
  path = /share
  numeric ids = yes
  max connections = 10
  list = true



After full sync completed, we will change cronjob to below:


*/30 * * * *  /usr/bin/rsync --numeric-ids -avr --delete --delete-before --ignore-errors --exclude=.snapshot 192.168.1.10::share/* /share >> /var/log/rsync-cron.log

Note: sometimes, you will encounter error message 'IO error encountered -- skipping file deletion' for rsync command, you can use '--ignore-errors' option as above to avoid this issue.



 How to check if a remote server port is open or not

                                      by Jephe Wu - http://linuxtechres.blogspot.com


Objective: test from a Linux client to decide if remote server port is open or not

Method 1:  telnet

e.g. telnet server1 389  - check if tcp/389 is open on server1 to client


Method 2: nc 

e.g. nc -vz server1 389  - check if tcp/389 is open on server1 to client

or nc -w 5 -vz server1 389 to specify timeout value


Method 3: openssl

Sometimes, there's no telnet or nc available/installed on client, we can try openssl

e.g.  openssl s_client -connect server1:389

 

Method 4: curl 

server 1 has ip 1.2.3.4


[root@server1 unixadm]# curl -v  telnet://1.2.3.4:10002
* About to connect() to 1.2.3.4 port 10002 (#0)
*   Trying 1.2.3.4...
* Connected to 1.2.3.4 (1.2.3.4) port 10002 (#0)

Method 5: from Windows Powershell

PS c:\users\jwu> Test-NetConnection -computername xxxx -port 443


Method 6: Linux bash shell

(timeout 1 bash -c "</dev/tcp/x.x.x.x/8080" && echo -n PORT OPEN || echo -n PORT CLOSED)


 How to configure manual entries in /etc/resolv.conf instead of DNS1/DNS2 in ifcfg-ens192

                                  by Jephe Wu  - http://linuxtechres.blogspot.com


Summary

There are two things in RHEL7 which will use DNS1/DNS2 in /etc/sysconfig/network-scripts/ifcfg-ens192 instead of manual configuration for /etc/resolv.conf for nameserver lines.

1)  use NetworkManager in ifcfg-ens192 and also update dns in /etc/NetworkManager/NetworkManager.conf under main section by default

2) PEERDNS in ifcfg-ens192 will overwrite /etc/resolv.conf nameserver with DNS1/DNS2 anyway although IP is static not dhcp


Steps

You need to disable networkmanager and also PEERDNS


1) disable networkmanager


[root@server1 network-scripts]# grep -i nm_controlled ifcfg-ens192
NM_CONTROLLED=no

2) or disable dns in NetworkManager.conf

[root@server2 network-scripts]# grep dns /etc/NetworkManager/NetworkManager.conf
dns=none


3) also you need to disable PEERDNS


[root@server1 network-scripts]# grep -i peerdns /etc/sysconfig/network-scripts/ifcfg-ens192
PEERDNS=no


4) reload NetworkManager and restart network to make sure /etc/resolv.conf is not being emptied first before reboot

systemctl reload NetworkManager

systemctl restart network


5) reboot

 How to resize VM partition on Vmware 

                                          by Jephe Wu - http://linuxtechres.blogspot.com

Extend a LVM partition

  1. from Vcenter, to edit configure, to add a new hard disk with required size
  2.   echo "- - -" > /sys/class/scsi_host/host#/scan  for each host*  (replace # with actual numbers)
  3. dmesg and cat /proc/partition to confirm new disk is added.

      4. fdisk /dev/sdb to create a new partition and use t  to change it to 8e LVM

      5 . pvcreate /dev/sdb1

     6. vgextend vg_root /dev/sdb1

     7. lvextend -l +100%FREE /dev/vg_root/lv_root

or  8. lvextend -L +20G /dev/vg_root/lv_root (if only increase 20G)

     9.  resize2fs /dev/mapper/vg_root-lv_root 

or xfs_growfs mountpoint (if it's xfs partition)


Modify existing sdb LVM PV disk size and use it in vg

1. echo "- - -" > /sys/class/scsi_host/host#/scan  for each host*  (replace # with actual numbers)

or

echo 1 > /sys/block/sdb/device/rescan

 

2.  use pvscan or  fdisk -l | grep -i sdb to confirm new disk size

3. blockdev --rereadpt /dev/sdb  to resize LVM volume size

4. pvresize /dev/sdb  to resize PV


Resize Procedure for /dev/sdb1 PV

https://access.redhat.com/solutions/57183

1. Confirm the actual storage size with fdisk -ul /dev/sdb. Observe the increased disk size. Depending on how the storage is presented, a system reboot may be necessary for this to appear.

2. Resize the partition on the disk. To achieve this, observe the starting sector in fdisk -ul /dev/sdb, then remove the partition with fdisk and re-create it with the same starting sector but the (default) last sector of the drive as the ending sector. Then write the partition table and confirm the change (and the correct starting sector) with fdisk -ul /dev/sdb.

3. Run pvresize /dev/sdb1 to grow (resize) the PV onto the rest of the expanded partition. This will create free extents within the Volume Group which then can be used to grow a Logical Volume. Running lvresize command with -r as lvresize -r will grow the filesystem within the Logical Volume as well.

Another solution would be creating a new partition under the same device starting where the first partition ended and using the rest of the cylinders to create the same, then put this new partition under LVM with the pvcreate command, extend the current VG (vgextend vg-name pv-name), then extend the current LV (lvextend) and finally resize the current filesystem (resize2fs).


Create a new LVM partition with new disk

pvcreate /dev/sdx1 

vgcreate vg01 /dev/sdx1

lvcreate -l +100%FREE -n apps vg01
mkfs -t xfs /dev/mapper/vg01_apps


For rollback

1) Unmount the mountpoint

umount -v /var/www

2) Check for filesystem error

e2fsck -f /dev/vg-repo/lv-repo

3) Reduce the logical volume

lvreduce --resize2fs -L -100G (-l 5119)  /dev/vg-repo/lv-repo

Note: use vgdisplay to record down existing used logic extent number, it's 5119 in this case before increase

4) Check for filesystem error

e2fsck -f /dev/vg-repo/lv-repo

5) Mount the filesystem back to the same mountpoint

mount /dev/vg-repo/lv-repo /var/www

6) Reduce the VG in order to release the PV /dev/sde1

vgreduce vg-repo /dev/sde1

7) Remove the PV

pvremove /dev/sde1

8) Remove the new created disk from vcenter in the backup plan?


How to change default boot entry in RHEL7

by Jephe Wu

https://access.redhat.com/solutions/1605183

Check default kernel configured 

grubby --default-kernel


Check default kernel is kernel or kernel-uek


cat /etc/sysconfig/kernel

Check entry numbering

 
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
or
grep ^menu  /etc/grub2.cfg | awk -F\'   '{print $2}'

setup default entry to reboot

use number below or menu output above
grub2-set-default 1

Note: this will change /boot/grub2/grubenv

change /etc/default/grub requires to rebuild /etc/grub2.cfg


grub2-mkconfig -o /boot/grub2/grub.cfg





Installing Oracle database 19c on Oracle Linux 7


by Jephe Wu

Preparation

Download 19c database rpm 
yum install tigervnc-server xterm
yum install oracle-database-preinstall-19c.x86_64
yum localinstall oracle-database-ee-19c-1.0-1.x86_64.rpm

yum install wget
wget https://yum.oracle.com/repo/OracleLinux/OL6/9/base/x86_64/getPackage/xorg-x11-twm-1.0.3-5.1.el6.x86_64.rpm
rpm -ivh xorg-x11-twm-1.0.3-5.1.el6.x86_64.rpm 

su - oracle
vncserver 

 type in oracle as password

ssh -X -i /home/local/ANT/wujephe/jephe-sydney.pem ec2-user@52.62.117.20 -L 5901:localhost:5901

Use Linux Remmina to connect to VNC localhost:1 with password 'oracle'.

Users and groups preparation

As preinstall rpm won't create asm* groups by itself, you might need to manually create them first.

Check /etc/groups for group id usage to find out which are available then create accordingly.
# groupadd -g 54421 oinstall
# groupadd -g 54322 dba
# groupadd -g 54323 oper
# groupadd -g 54324 backupdba
# groupadd -g 54325 dgdba
# groupadd -g 54326 kmdba
# groupadd -g 54327 asmdba
# groupadd -g 54328 asmoper
# groupadd -g 54329 asmadmin
# groupadd -g 54330 racdba

# useradd --uid 54321 --gid oinstall --groups dba,oper,asmdba,racdba,backupdba,dgdba,kmdba oracle

# useradd --uid 54322 --gid oinstall --groups dba,asmadmin,asmdba,asmoper,racdba grid

You might need to run usermod to change oracle user groups as it's being created by oracle-database-ee-19c-1.0-1.x86_64.rpm

usermod -G dba,oper,asmdba,racdba,backupdba,dgdba,kmdba oracle

Otherwise, when installing database software, it might not able to find ASM disk group.

Refer to https://access.redhat.com/documentation/en-us/reference_architectures/2017/html/deploying_oracle_rac_database_12c_release_2_on_red_hat_enterprise_linux_7/ref_config_details#user_groups

Note: for oracle and grid user, it's very important for them to belong to secondary group as follows

usermod -G dba,asmdba,backupdba,dgdba,kmdba,racdba oracle
usermod -G asmadmin,asmdba,racdba grid

Directory preparation

login as root , run
mkdir -p /u01/app/19.0.0/grid
mkdir -p /u01/app/oracle
chown -R grid:oinstall /u01
chown oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/

Note: grid infrastructure installation will ask for ORACLE_HOME directory which is for some logging within grid, just use default value prompted.



For grid installation
login as grid user
$ cd /u01/app/19.0.0/grid
$ unzip -q /u01/softwares/grid_home.zip
$ ./gridSetup.sh   # within vnc window

Install cvuqdisk rpm before starting grid installation

[root@localhost 19.0.0]# cd grid/cv/rpm/
[root@localhost rpm]# ls
cvuqdisk-1.0.10-1.rpm

[root@localhost rpm]# rpm -ivh cvuqdisk-1.0.10-1.rpm
Preparing...                          ################################# [100%]
Using default group oinstall to install package
Updating / installing...
   1:cvuqdisk-1.0.10-1                ################################# [100%]

Device consistency 

use UDEV rules

https://oracle-base.com/articles/linux/udev-scsi-rules-configuration-in-oracle-linux 

[root@ip-172-31-6-220 rules.d]# more 99-oracleasm.rules

KERNEL=="sd?1", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent", RESULT=="360014057643ce73dd3a4080b6832a913", SYMLINK+="asm-disk1", OWNER="grid", GROUP="oinstall", MODE="0660"

[root@ip-172-31-6-220 rules.d]# ll /dev/sda1

brw-rw----. 1 grid oinstall 8, 1 Jun 21 00:42 /dev/sda1

[root@ip-172-31-6-220 rules.d]# ll /dev/asm-disk1

lrwxrwxrwx. 1 root root 4 Jun 21 00:42 /dev/asm-disk1 -> sda1

[root@ip-172-31-6-220 rules.d]# /usr/lib/udev/scsi_id -g -u -d /dev/sda1

360014057643ce73dd3a4080b6832a913

[root@ip-172-31-6-220 rules.d]# udevadm control --reload-rules

[root@ip-172-31-6-220 rules.d]# udevadm trigger

use ASMFD


$ su root
# export ORACLE_HOME=/u01/app/19.0.0/grid
# export ORACLE_BASE=/tmp
Use Oracle ASM command line tool (ASMCMD) to provision the disk devices for use with Oracle ASM Filter Driver.
# cd /u01/app/19.0.0/grid/bin
# ./asmcmd afd_label DATA1 /dev/sdb --init
# ./asmcmd afd_label DATA2 /dev/sdc --init
# ./asmcmd afd_label DATA3 /dev/sdd --init

to unlabel:

# /u01/app/19.0.0/grid/bin/asmcmd afd_unlabel /dev/sdb -f --init

Verify the device has been marked for use with Oracle ASMFD.
# ./asmcmd afd_lslbl /dev/sdb
# ./asmcmd afd_lslbl /dev/sdc
# ./asmcmd afd_lslbl /dev/sdd

Log in as the grid user, and start the Oracle Grid Infrastructure installer by running the following command:
$ /u01/app/19.0.0/grid/gridSetup.sh

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/ostmg/administer-filter-driver.html#GUID-6F16B5EC-BE7D-44FA-A05B-A62CF33763D3

Note: above requires /dev/sdb to be owned by grid:oinstall based on my testing, otherwise, Grid will fail to open ASM disk,  maybe put into /etc/rc.d/rc.local as follows

chown grid:oinstall /dev/sdb

VNC preparation

login as grid and oracle user, run
vncserver :1 and vncserver :2 to start vnc server


Installation for database

$ mkdir -p /u01/app/oracle/product/19.0.0/dbhome_1
$ chgrp oinstall /u01/app/oracle/product/19.0.0/dbhome_1
$ cd /u01/app/oracle/product/19.0.0/dbhome_1
$ unzip -q /tmp/db_home.zip
$ cd /u01/app/oracle/product/19.0.0/dbhome_1
$ ./runInstaller

References

https://dbaclass.com/article/move-spfile-file-system-asm-rac/
https://access.redhat.com/documentation/en-us/reference_architectures/2017/html-single/deploying_oracle_rac_database_12c_release_2_on_red_hat_enterprise_linux_7/index

https://oracle-base.com/articles/12c/oracle-db-12cr2-rac-installation-on-oracle-linux-7-using-virtualbox


Issues


Error 49802 Initializing ADR when running gridSetup.sh

=> make sure /u01/app/19.0.0/grid and subdirectory are owned by grid:oinstall

chown grid:oinstall -R /u01/app/19.0.0/grid

 
ORA-15107: missing or invalid ASM disk name
=> change /etc/udev/rules.d/99-oracleasm.rules from /dev/sd?1


[root@localhost rules.d]# more 99-oracleasm.rules
KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM=="/usr/lib/udev/scsi_id -g -u -d /dev/$parent", RESULT=="1ATA_VBOX_HARDDISK_VB9ded913b-c5b04341", SYMLINK+="asm-disk1", OWNER="grid", GROUP="asmad

min", MODE="0660"


[grid@localhost ~]$ /u01/app/19.0.0/grid/bin/asmca -silent -oui_internal -configureASM -diskString '/dev/sd*' -diskGroupName DATA -diskList /dev/sdb1 -redundancy EXTERNAL -au_size 4
SYS_PASSWORD_PROMPT

ASMSNMP_PASSWORD_PROMPT


[FATAL] [DBT-30002] Disk group DATA creation failed.
ORA-15018: diskgroup cannot be created
ORA-15107: missing or invalid ASM disk name



[grid@localhost ~]$ /u01/app/19.0.0/grid/bin/asmca -silent -oui_internal -configureASM -diskString '/dev/sd*' -diskGroupName DATA -diskList /dev/sdb -redundancy EXTERNAL -au_size 4
SYS_PASSWORD_PROMPT

ASMSNMP_PASSWORD_PROMPT


ASM has been created and started successfully.


[DBT-30001] Disk groups created successfully. Check /u01/app/19.0.0/grid_base/cfgtoollogs/asmca/asmca-190625AM092007.log for details.












Setting up iscsi sharing between RHEL7

by Jephe Wu

=== On target side

1. Add a volume on AWS EC2 console and assign volume to the EC2 VM

confirmed new volume in /proc/partitions

fdisk /dev/xvdf

to create one partition with linux type

2.  yum install targetcli
systemctl enable target
systemctl start target

3. setup target lun

[root@ip-172-31-4-10 ec2-user]# targetcli
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> iscsi/
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 1]
  o- iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c .................................................... [TPGs: 1]
    o- tpg1 ................................................................................................. [no-gen-acls, no-auth]
      o- acls ............................................................................................................ [ACLs: 0]
      o- luns ............................................................................................................ [LUNs: 0]
      o- portals ...................................................................................................... [Portals: 1]
        o- 0.0.0.0:3260 ....................................................................................................... [OK]
/iscsi> iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c/tpg1


/iscsi/iqn.20...391e0b7c/tpg1> /
/> /backstores/block create name=block_backend dev=/dev/xvdf
Created block storage object block_backend using /dev/xvdf.
/> iscsi/
/iscsi> iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c/tpg1
/iscsi/iqn.20...391e0b7c/tpg1> luns/ create /backstores/block/block_backend
Created LUN 0.
/iscsi/iqn.20...391e0b7c/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
  o- acls ................................................................................................................ [ACLs: 0]
  o- luns ................................................................................................................ [LUNs: 1]
  | o- lun0 ................................................................... [block/block_backend (/dev/xvdf) (default_tg_pt_gp)]
  o- portals .......................................................................................................... [Portals: 1]
    o- 0.0.0.0:3260 ........................................................................................................... [OK]
/iscsi/iqn.20...391e0b7c/tpg1> /

/iscsi> iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c/tpg1

/iscsi/iqn.20...391e0b7c/tpg1> acls/
/iscsi/iqn.20...b7c/tpg1/acls> create iqn.1994-05.com.redhat:413be97b32f2
Created Node ACL for iqn.1994-05.com.redhat:413be97b32f2
Created mapped LUN 0.

/iscsi/iqn.20...391e0b7c/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
  o- acls ................................................................................................................ [ACLs: 1]
  | o- iqn.1994-05.com.redhat:413be97b32f2 ........................................................................ [Mapped LUNs: 1]
  |   o- mapped_lun0 ............................................................................... [lun0 block/block_backend (rw)]
  o- luns ................................................................................................................ [LUNs: 1]
  | o- lun0 ................................................................... [block/block_backend (/dev/xvdf) (default_tg_pt_gp)]
  o- portals .......................................................................................................... [Portals: 1]
    o- 0.0.0.0:3260 ........................................................................................................... [OK]


====on client side

[root@ip-172-31-8-24 ec2-user]#  yum install iscsi-initiator-utils


[root@ip-172-31-0-31 iscsi]# iscsiadm -m discovery -t st -p 172.31.4.10 
172.31.4.10:3260,1 iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c

[root@ip-172-31-0-31 iscsi]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c -l
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c, portal: 172.31.4.10,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.ip-172-31-4-10.x8664:sn.82d2391e0b7c, portal: 172.31.4.10,3260] successful.

[root@ip-172-31-0-31 iscsi]# dmesg | grep sda
[348576.211493] sd 4:0:0:0: [sda] 20971520 512-byte logical blocks: (10.7 GB/10.0 GiB)
[348576.221556] sd 4:0:0:0: [sda] Write Protect is off
[348576.226764] sd 4:0:0:0: [sda] Mode Sense: 43 00 00 08
[348576.227815] sd 4:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[348576.256350]  sda: sda1
[348576.263152] sd 4:0:0:0: [sda] Attached SCSI disk

there's no need to enable any client service, as kernel will detect iscsi drive automatically below

----
[   12.312069] Loading iSCSI transport class v2.0-870.
[   12.354416] iscsi: registered transport (tcp)
[   12.382519] scsi host2: iSCSI Initiator over TCP/IP
[   12.398666] scsi 2:0:0:0: Direct-Access     LIO-ORG  block_backend    4.0  PQ: 0 ANSI: 5
[   12.417146] scsi 2:0:0:0: alua: supports implicit and explicit TPGS
[   12.422931] scsi 2:0:0:0: alua: device naa.600140563a0ac28e2414b52a3c5f8f89 port group 0 rel port 1
[   12.431126] scsi 2:0:0:0: alua: Attached
[   12.438279] scsi 2:0:0:0: alua: transition timeout set to 60 seconds
[   12.445803] scsi 2:0:0:0: alua: port group 00 state A non-preferred supports TOlUSNA
[   12.458154] scsi 2:0:0:0: Attached scsi generic sg0 type 0
[   12.506779] sd 2:0:0:0: [sda] 20971520 512-byte logical blocks: (10.7 GB/10.0 GiB)
[   12.543041] sd 2:0:0:0: [sda] Write Protect is off
[   12.547556] sd 2:0:0:0: [sda] Mode Sense: 43 00 00 08
[   12.564423] sd 2:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   12.597412]  sda: sda1
[   12.609015] sd 2:0:0:0: [sda] Attached SCSI disk
----

References


iscsiadm -m session [-P1 | -P3]
login all Luns exported on the target: iscsiadm -m discovery -t st -l
node and discovery database directory: /var/lib/iscsi
disconnect: iscsiadm -m node -T target_iqn_name -p ipaddress -u
remove target from database so it won't connect upon reboot: iscsiadm -m node -T target_iqn_name -p ipaddress --op delete
delete all bindings for iface0: iscsiadm -m node -I iface0 --op=delete
logout all target: iscsiadm -m node -U all
login all node: iscsiadm -m node -L all
rescan lun: iscsiadm -m node -p 192.168.40.10 --rescan
check /var/lib/iscsi interface directory:



How to install a minimal X11 GUI vnc environment on RHEL7/8 for Oracle installation

by Jephe Wu

Summary

In RHEL7, since Redhat removed twm window manager and used mwm instead, however x11 is still configured to use /usr/bin/twm though, if Oracle DBA needs to install Oracle database on RHEL7 remotely with a minimal X11 environment,  there's a way to make it so.

Steps


1.  create symbolic link /usr/bin/mwm to /usr/bin/twm 


cd /usr/bin

ln -sf mwm twm 

Note: if you still would like to use twm, you can install from RHEL6 below

download twm window manager from RHEL6

wget http://mirror.centos.org/centos/6/os/x86_64/Packages/xorg-x11-twm-1.0.3-5.1.el6.x86_64.rpm

2. install tigervnc-server and xterm
yum install tigervnc-server xterm

rpm -ivh xorg-x11-twm-1.0.3-5.1.el6.x86_64.rpm (optional for twm)

3. run vncserver :1 on RHEL7 after ssh with required user (usually oracle)

4. use vncviewer to connect to RHEL7 ip address at 5901 port

Note: or you can use ssh port forwarding to forward local port 5901 to remote server with ssh(putty)

Or  ssh -L 5901:localhost:5901 remote_server_ip

Reference

http://houseofbrick.com/twm-window-manager-on-rhel-7/ 
https://docs.oracle.com/cd/E52668_01/E54669/html/ol7-vnc-config.html


How to setup minimum privileges for Oracle 12c on-prem or EC2 for DMS full load and CDC migration

Jephe Wu - http://linuxtechres.blogspot.com


1.  create user and tablespace first
create tablespace jephe
create user jephe identified by jephe default tablespace jephe;
grant connect,resource,create view to jephe;
revoke unlimited tablespace from jephe;
alter user jephe quota unlimited on jephe;

2. grant required privileges for user jephe
grant create session to jephe;
grant create view to jephe;
grant select any table to jephe;
grant select on all_views to jephe;
grant SELECT ANY TRANSACTION to jephe;
grant SELECT on V_$ARCHIVED_LOG to jephe;
grant SELECT on V_$LOG to jephe;
grant SELECT on V_$LOGFILE to jephe;
grant SELECT on V_$DATABASE to jephe;
grant SELECT on V_$THREAD to jephe;
grant SELECT on V_$PARAMETER to jephe;
grant SELECT on V_$NLS_PARAMETERS to jephe;
grant SELECT on V_$TIMEZONE_NAMES to jephe;
grant SELECT on V_$TRANSACTION to jephe;
grant SELECT on ALL_INDEXES to jephe;
grant SELECT on ALL_OBJECTS to jephe;
grant SELECT on ALL_TABLES to jephe;
grant SELECT on ALL_USERS to jephe;
grant SELECT on ALL_CATALOG to jephe;
grant SELECT on ALL_CONSTRAINTS to jephe;
grant SELECT on ALL_CONS_COLUMNS to jephe;
grant SELECT on ALL_TAB_COLS to jephe;
grant SELECT on ALL_IND_COLUMNS to jephe;
grant SELECT on ALL_LOG_GROUPS to jephe;
grant SELECT on SYS.DBA_REGISTRY to jephe;
grant SELECT on SYS.OBJ$ to jephe;
grant SELECT on DBA_TABLESPACES to jephe;
grant SELECT on ALL_TAB_PARTITIONS to jephe;
grant SELECT on ALL_ENCRYPTED_COLUMNS to jephe;
# the following is required for successful connection test
grant SELECT on V_$LOGMNR_LOGS to jephe;
grant SELECT on V_$LOGMNR_CONTENTS to jephe;
# the following is requried during CDC phase to add redo logs for logminer
grant execute on dbms_logmnr to jephe;
grant logmining to jephe;


# how to check the existing privileges

select * from dba_role_privs where grantee = 'JEPHE'; 'minimum is empty'
select * from dba_sys_privs where grantee = 'JEPHE';
select * from dba_tab_privs where grantee = 'JEPHE';

How to reduce AWS EBS root volume size

Jephe Wu - http://linuxtechres.blogspot.com

Objective:  reduce the AWS EBS root volume size from 8G to 4G since file system only used less than 3G.
Environment:  Amazon Linux AMI 2015.03 (HVM), SSD Volume Type - ami-fd9cecc7, t2.macro instance type with 8G gp EBS volume as root volume (default creation steps with launch instance wizard)

Diagram

original instance: jephe-base, with 8G ebs root volume, need to shrink it to 5G 
lab1 instance: used for the whole shrink process test
ebs volume 'source': created from snapshot of root volume from original instance.
ebs volume 'dest':  manually created new volume with 5G 



Steps:
1.  create another small instance named lab1
Amazon Linux AMI 2015.03 (HVM), SSD Volume Type - ami-fd9cecc7 , t2.macro, 8G gp ebs volume.

2.  make snapshot backup and create volume from it
stop the original base instance, detach its 8G volume, make snapshot of it, then create test volume named 'source' from snapshot, so we can work on the source volume instead of original base volume 

3. create another new volume named 'dest' with expected size (5g) and within same AZ as instance lab1
Note: the actual file system size of base volume must be less than 5G

4. attach volume F and G to small instance lab1 as /dev/xvdf and /dev/xvdg respectively
so the Linux OS will see /dev/xvdf, /dev/xvdf1 and /dev/xvdg as follows

5. while lab1 instance is running, attach both volume source and dest to it as /dev/sdf and /dev/sdg.

[ec2-user@ip-10-0-11-185 ~]$ more /proc/partitions
major minor  #blocks  name

 202        0    8388608 xvda
 202        1    8386543 xvda1
 202       80    8388608 xvdf
 202       81    8386543 xvdf1
 202       96    5242880 xvdg


6. fsck and resize2fs to minimum 

[root@ip-10-0-11-185 mnt]# e2fsck -f /dev/xvdf1
e2fsck 1.42.12 (29-Aug-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/: 38013/524288 files (0.2% non-contiguous), 606002/2096635 blocks

[root@ip-10-0-11-185 mnt]# resize2fs -M -p /dev/xvdf1
resize2fs 1.42.12 (29-Aug-2014)
Resizing the filesystem on /dev/xvdf1 to 944604 (4k) blocks.
Begin pass 2 (max = 139004)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 64)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 4518)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/xvdf1 is now 944604 (4k) blocks long.

[root@ip-10-0-11-185 mnt]# resize2fs -M -p /dev/xvdf1
resize2fs 1.42.12 (29-Aug-2014)
Resizing the filesystem on /dev/xvdf1 to 940777 (4k) blocks.
The filesystem on /dev/xvdf1 is now 940777 (4k) blocks long.

[root@ip-10-0-11-185 mnt]# resize2fs -M -p /dev/xvdf1
resize2fs 1.42.12 (29-Aug-2014)
Resizing the filesystem on /dev/xvdf1 to 940770 (4k) blocks.
The filesystem on /dev/xvdf1 is now 940770 (4k) blocks long.

7. calculate the actual file system size after resize2fs -M, round it up a bit to 300
[root@ip-10-0-11-185 mnt]# echo "scale=5; 940770*4/(1024*16)" | bc
229.68017

8.  make partition for /dev/xvdg by fdisk
[root@ip-10-0-11-185 mnt]# fdisk /dev/xvdg
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xaa83e894.

Command (m for help): p

Disk /dev/xvdg: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xaa83e894

    Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@ip-10-0-11-185 mnt]# fdisk -l /dev/xvdg

Disk /dev/xvdg: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xaa83e894

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdg1            2048    10485759     5241856   83  Linux

[root@ip-10-0-11-185 mnt]# cat /proc/partitions 
major minor  #blocks  name

 202        0    8388608 xvda
 202        1    8386543 xvda1
 202       80    8388608 xvdf
 202       81    8386543 xvdf1
 202       96    5242880 xvdg
 202       97    5241856 xvdg1

9.  use dd to copy file system 
[root@ip-10-0-11-185 mnt]# dd if=/dev/xvdf1 of=/dev/xvdg1 bs=16M count=230 
230+0 records in
230+0 records out
3858759680 bytes (3.9 GB) copied, 113.625 s, 34.0 MB/s

Note: you can run kill -USR1 pidofdd from another terminal to get the dd progress

10. mount /dev/xvdg1 to /mnt/g and bind mount /dev to /mnt/g/dev 

[root@ip-10-0-11-185 mnt]# mount /dev/xvdg1 g
[root@ip-10-0-11-185 mnt]# cd g
[root@ip-10-0-11-185 g]# ls
bin  boot  dev  etc  home  lib  lib64  local  lost+found  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var

[root@ip-10-0-11-185 g]# mount --bind /dev /mnt/g/dev/


11. install grub on /dev/xvdg

[root@ip-10-0-11-185 g]# chroot .
[root@ip-10-0-11-185 /]# ls
bin  boot  dev  etc  home  lib  lib64  local  lost+found  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var
[root@ip-10-0-11-185 /]# grub
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> find /boot/grub/stage1
find /boot/grub/stage1
 (hd0,0)
 (hd1,0)
 (hd2,0)
grub> root (hd2,0)
root (hd2,0)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd2)
setup (hd2)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd2)"...  29 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd2) (hd2)1+29 p (hd2,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.
grub> quit
quit
[root@ip-10-0-11-185 /]# exit
exit
[root@ip-10-0-11-185 g]# cd /

[root@ip-10-0-11-185 /]# umount /mnt/g/dev
[root@ip-10-0-11-185 /]# umount /mnt/g/
[root@ip-10-0-11-185 /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  919M  6.8G  12% /
devtmpfs        490M   72K  490M   1% /dev
tmpfs           499M     0  499M   0% /dev/shm


[root@ip-10-0-11-185 ec2-user]# e2fsck -f /dev/xvdg1
e2fsck 1.42.12 (29-Aug-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/: 38013/237568 files (0.3% non-contiguous), 587515/940770 blocks

Now stop instance lab1, detach all 3 volumes including os base volume for lab1, attach dest volume to lab1 with root device as /dev/xvda. start up instance lab1 again to make sure it can start up successfully.

Now, stop test instance lab1, detach volume named 'dest' , stop original instance and detach its volume,  attach volume 'dest' to original instance to start up.

Note: during ec2 instance startup, it will automatically resize file sytem to the maximum.

Here is the df -h result after startup the 'dest' volume with original instance jephe-base.

[root@ip-172-31-13-17 ec2-user]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      4.8G  2.2G  2.7G  46% /
devtmpfs        490M   56K  490M   1% /dev
tmpfs           499M     0  499M   0% /dev/shm



How to create AWS NAT and Bastion Hosts in VPC

Jephe Wu - http://linuxtechres.blogspot.com


Objective:  Use VPC wizard to create public and private subnets in different AZ and use NAT service for private subnets and access servers on private subnets through bastion host.

Steps:


1. Use VPC wizard to create required subnets.


We will create the following VPC network and subnets:
10.0.0.0/16 with subnets:

10.0.0.0/24 public subnet A in ap-southeast-2a with Elastic IP 1 hosting company web server and NAT box
10.0.1.0/24 private subnet C in ap-southeast-2a  hosting SQL server, access Internet through NAT box in public subnet A
10.0.10.0/24 public subnet B in ap-southeast-2b with Elastic IP 2 hosting a bostion server which is Windows 2008 R2 base OS, jumphost for accessing SQL server in subnet C
10.0.11.0/24 private subnet D in ap-southeast-2b hosting other servers or applications, accessing Internet through NAT box in public subnet A


Above wizard will only create subnet A and C and NAT box. 
After that, follow normal procedure to create Internet facing web server instance with elastic IP and automatic assigned or manually specified private IP e.g. 10.0.0.104/24

Eventually, we need to create 2 more subnet in another AZ manually to make it like this:

Network Diagram:
----Internet --- public subnet A (with 10.0.0.0/24)  --- private subnet C ( with 10.0.1.0/24)  [ ap-southeast-2a ]
----Internet ----pubic subnet B  (with 10.0.10.0/24) ---- private subnet D  (with 10.0.11.0/24) [ ap-southeast-2b ]
          

2. Configure NAT box
After finishing wizard, the NAT is up and running, you still need to configure the following to make it as masquerading NAT box for your entire VPC network 10.0.0.0/16, by default, it only allow the outbound Internet traffic.

  • check security group configuration of NAT box instance, by default, it doesn't allow the entire VPC 10.0.0.0/16 for incoming traffic which will block Internet access for all private subnets.
Also, check other settings such as disable src/destination check, the routing table for private subnet hosts routing table (must be pointing to NAT box ENI).

You can also ssh into NAT box from Internet to check iptables rules and ip forwarding:

[root@ip-10-0-0-104 ec2-user]# iptables -L -v -n -t nat | grep 10.0
  531 31715 MASQUERADE  all  --  *      eth0    10.0.0.0/16          0.0.0.0/0 

[root@ip-10-0-0-104 ec2-user]# more /proc/sys/net/ipv4/ip_forward
1

[root@ip-10-0-0-104 ec2-user]# grep nameserver /etc/resolv.conf 
nameserver 10.0.0.2

2.1 use NAT instance as port forwarding for RDS instance (e.g. to RDS Postgres)
Firstly make sure from Nat box e.g 10.0.20.254, you can telnet to e.g. 10.0.23.114 port 5432, then run commands below on NAT box
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 5432 -j DNAT --to 10.0.23.114:5432
iptables -A FORWARD -p tcp -d 10.0.23.114 --dport 5432 -j ACCEPT (might be optional)
iptables -A POSTROUTING -t nat -p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 --dport 5432 -j SNAT --to 10.0.20.254
Note: 10.0.23.114 is the RDS internal ip and 10.0.20.254 is NAT internal ip 
Now add the external application ip into the NAT box security group to allow connection.

3. Configure Bostion Windows Server in public subnet C

Create another 2 more subnets C and D in another AZ ap-southeast-2b,  replace public subnet C routing table from ENI of NAT box to igw so that we can access it from Internet as jumphost.


4. Create SQL server database host in private subnet B
configure security group setting to only allow the internal IP of Bostion Windows server or the whole private subnet 10.0.0.0/16.

Notes for security group:
You can also specify another security group groupid in the customer IP part to quote the same security group settings. 

For either Linux or Windows server, if you remove your current connection source IP from security group while you are on the servers, the existing connection will be still okay, but if you exit ssh/rdp, the new connection won't be able to make.