How to use the Oracle database basically?


Recently, I need to study about the Oracle Database. In fact, I am not DBA. In this post, I will write the database queries to use later. I will use the Oracle SQL developer for this test.


1. Download and Connect database


I followed this instruction, which introduce how to connect to database. I need to download Oracle SQL developer from here. After download, I can connect database with connect button on the left of top.



2. Check the Database Properties.


select * from database_properties;


I can see configuration or properties from query like below. For example, I can see the "Default Temp Tablespace" which the user information is stored in.



3. Create (Drop) User


This is important part to understand about Oracle Database. In Oracle, there is "schema" term. I think this is also user. All of objects such as table are connected to this schema. For example, "schema.table_name" is used as the table name when I create table. This instruction show how to create user.


select * from dba_users;


I can get the all of users information in this database like below.



Now, I will create new user which is identified by the password.


create user virginiauser identified by password1;


I can see the new user created with "select * from dba_users;".



If you want to remove or revoke user, follows the command below.


drop user virginiauser;


4. Grant Privileges and role.


However, this user does not have any role and privileges. In this instruction, there are comments for roles.  


Role NameCreated By (Script)Description

CONNECT

SQL.BSQ

Includes the following system privileges: ALTER SESSION, CREATE CLUSTER, CREATE DATABASE LINK, CREATE SEQUENCE, CREATE SESSION, CREATE SYNONYM, CREATE TABLE, CREATE VIEW

RESOURCE

SQL.BSQ

Includes the following system privileges: CREATE CLUSTER, CREATE INDEXTYPE, CREATE OPERATOR, CREATE PROCEDURE, CREATE SEQUENCE, CREATE TABLE, CREATE TRIGGER, CREATE TYPE

DBA

SQL.BSQ

All system privileges WITH ADMIN OPTION

Note: The previous three roles are provided to maintain compatibility with previous versions of Oracle and may not be created automatically in future versions of Oracle. Oracle Corporation recommends that you design your own roles for database security, rather than relying on these roles.

EXP_FULL_DATABASE

CATEXP.SQL

Provides the privileges required to perform full and incremental database exports. Includes: SELECT ANY TABLE, BACKUP ANY TABLE, EXECUTE ANY PROCEDURE, EXECUTE ANY TYPE, ADMINISTER RESOURCE MANAGER, and INSERT, DELETE, and UPDATE on the tables SYS.INCVID, SYS.INCFIL, and SYS.INCEXP. Also the following roles: EXECUTE_CATALOG_ROLE and SELECT_CATALOG_ROLE.

IMP_FULL_DATABASE

CATEXP.SQL

Provides the privileges required to perform full database imports. Includes an extensive list of system privileges (use view DBA_SYS_PRIVS to view privileges) and the following roles: EXECUTE_CATALOG_ROLE and SELECT_CATALOG_ROLE.

DELETE_CATALOG_ROLE

SQL.BSQ

Provides DELETE privilege on the system audit table (AUD$)

EXECUTE_CATALOG_ROLE

SQL.BSQ

Provides EXECUTE privilege on objects in the data dictionary. Also, HS_ADMIN_ROLE.

SELECT_CATALOG_ROLE

SQL.BSQ

Provides SELECT privilege on objects in the data dictionary. Also, HS_ADMIN_ROLE.

RECOVERY_CATALOG_OWNER

CATALOG.SQL

Provides privileges for owner of the recovery catalog. Includes: CREATE SESSION, ALTER SESSION, CREATE SYNONYM, CREATE VIEW, CREATE DATABASE LINK, CREATE TABLE, CREATE CLUSTER, CREATE SEQUENCE, CREATE TRIGGER, and CREATE PROCEDURE

HS_ADMIN_ROLE

CATHS.SQL

Used to protect access to the HS (Heterogeneous Services) data dictionary tables (grants SELECT) and packages (grants EXECUTE). It is granted to SELECT_CATALOG_ROLE and EXECUTE_CATALOG_ROLE such that users with generic data dictionary access also can access the HS data dictionary.

AQ_USER_ROLE

CATQUEUE.SQL

Obsoleted, but kept mainly for release 8.0 compatibility. Provides execute privilege on DBMS_AQ and DBMS_AQIN.

AQ_ADMINISTRATOR_ROLE

CATQUEUE.SQL

Provides privileges to administer Advance Queuing. Includes ENQUEUE ANY QUEUE, DEQUEUE ANY QUEUE, and MANAGE ANY QUEUE, SELECT privileges on AQ tables and EXECUTE privileges on AQ packages.

SNMPAGENT

CATSNMP.SQL

This role is used by Enterprise Manager/Intelligent Agent. Includes ANALYZE ANY and grants SELECT on various views.


In my case, I am AWS Oracle RDS database. Look at the role assigned.


select * from dba_role_privs;


There are so many roles assigned.  There is no any role in user created before. However, there are so many role assigned for 'RDSADMIN' and master account.


RDSADMIN CRENETADMIN
XDBADMIN XDBADMIN
EXECUTE_CATALOG_ROLE EXECUTE_CATALOG_ROLE
CTXAPP CTXAPP
DATAPUMP_IMP_FULL_DATABASE DATAPUMP_EXP_FULL_DATABASE
OPTIMIZER_PROCESSING_RATE OPTIMIZER_PROCESSING_RATE
CAPTURE_ADMIN CAPTURE_ADMIN
IMP_FULL_DATABASE IMP_FULL_DATABASE
AQ_ADMINISTRATOR_ROLE AQ_ADMINISTRATOR_ROLE
EM_EXPRESS_BASIC EM_EXPRESS_BASIC
EM_EXPRESS_ALL EM_EXPRESS_ALL
DELETE_CATALOG_ROLE DELETE_CATALOG_ROLE
SODA_APP SODA_APP
RECOVERY_CATALOG_USER RECOVERY_CATALOG_USER
CONNECT CONNECT
OEM_ADVISOR OEM_ADVISOR
OEM_MONITOR OEM_MONITOR
SELECT_CATALOG_ROLE SELECT_CATALOG_ROLE
HS_ADMIN_SELECT_ROLE HS_ADMIN_SELECT_ROLE
DBA DBA
RESOURCE RESOURCE
  RDS_MASTER_ROLE
DATAPUMP_EXP_FULL_DATABASE DATAPUMP_IMP_FULL_DATABASE
XDB_SET_INVOKER XDB_SET_INVOKER
GATHER_SYSTEM_STATISTICS GATHER_SYSTEM_STATISTICS
SCHEDULER_ADMIN SCHEDULER_ADMIN
RECOVERY_CATALOG_OWNER RECOVERY_CATALOG_OWNER
HS_ADMIN_EXECUTE_ROLE HS_ADMIN_EXECUTE_ROLE
AQ_USER_ROLE AQ_USER_ROLE
EXP_FULL_DATABASE EXP_FULL_DATABASE


Now I will give 3 role for user which I created like below.


grant connect, resource, dba to virginiauser;


After this I can check the role status.



So far, I studied how to grant the privileges. However, I need to revoke these sometimes. 


revoke connect, resource, dba from virginiauser;


After granting roles to user, I need to give some privileges to this user. In oracle, there are two types of privileges, system and table.  At first, I will grant some privileges for the system.


RDSADMIN CRENETADMIN
INHERIT ANY PRIVILEGES  
GRANT ANY OBJECT PRIVILEGE GRANT ANY OBJECT PRIVILEGE
DROP ANY DIRECTORY DROP ANY DIRECTORY
UNLIMITED TABLESPACE UNLIMITED TABLESPACE
EXEMPT REDACTION POLICY EXEMPT REDACTION POLICY
CHANGE NOTIFICATION CHANGE NOTIFICATION
FLASHBACK ANY TABLE FLASHBACK ANY TABLE
ALTER SYSTEM  
ALTER PUBLIC DATABASE LINK ALTER PUBLIC DATABASE LINK
EXEMPT ACCESS POLICY EXEMPT ACCESS POLICY
ALTER DATABASE  
SELECT ANY TABLE SELECT ANY TABLE
RESTRICTED SESSION RESTRICTED SESSION
ALTER DATABASE LINK ALTER DATABASE LINK
CREATE EXTERNAL JOB  
EXEMPT IDENTITY POLICY EXEMPT IDENTITY POLICY
ADMINISTER DATABASE TRIGGER  
GRANT ANY ROLE  


I can give(remove) some system privileges like below.


grant UNLIMITED TABLESPACE TO myadmin;

revoke UNLIMITED TABLESPACE from myadmin;


After this, I can verify the status with "select * from dba_sys_privs" query.



Now, the table privileges left. In fact, I can not explain about this without the table. I will add more detail later in this post. Just look at the command how to see.


select * from dba_tab_privs where grantee='CRENETADMIN';



5. Create(Drop) Table


Before I create the Data table, I need to create table space. In this instruction, what kinds of parameters are required is explained. This command show the table spaces list. 


select * from dba_tablespaces;



There are some necessary factor for this table space. Fist is "Contents". There are three values to category. In the instruction, there are comments like below.


A permanent tablespace contains persistent schema objects. Objects in permanent tablespaces are stored in datafiles.


An undo tablespace is a type of permanent tablespace used by Oracle Database to manage undo data if you are running your database in automatic undo management mode. Oracle strongly recommends that you use automatic undo management mode rather than using rollback segments for undo.


A temporary tablespace contains schema objects only for the duration of a session. Objects in temporary tablespaces are stored in tempfiles. 


From this statements above, "Undo tablespace" is not friendly rather than others. Please, read these instructions, https://oracle-base.com/articles/9i/automatic-undo-management and https://docs.oracle.com/cd/B28359_01/server.111/b28310/undo002.htm#ADMIN11462. For this "Undo tablespace",  "automatic undo management" is required. The recently version is set as defaults. Also, I tried to change this configuration in AWS RDS. Howerer, I can not alter this.



Second is the datafile conecpt such as "bigfile" or "smallfile". In this instruction


A bigfile tablespace contains only one datafile or tempfile, which can contain up to approximately 4 billion (232) blocks. The maximum size of the single datafile or tempfile is 128 terabytes (TB) for a tablespace with 32K blocks and 32TB for a tablespace with 8K blocks.


A smallfile tablespace is a traditional Oracle tablespace, which can contain 1022 datafiles or tempfiles, each of which can contain up to approximately 4 million (222) blocks. 


From this statements, I can not understand "smallfile tablespace can contain multiple datafiles". Please look at this link


create tablespace homeworkts 

datafile 'D:\oradata\orcl\df1.dbf' size 4m, 

         'D:\oradata\orcl\df2.dbf' size 4m, 

         'D:\oradata\orcl\df3.dbf' size 4m; 


However, this command does not work in AWS RDS. Because RDS does not give any permission for this like below. I can not create the datafile.



There are so many options, however I can not handle all of things. I think I can create tablespace with these information. I hope this instruction will be helpful.






# Permament-Bigfile tablespace

create bigfile tablespace myspace;


# Permament-Bigfile tablespace

create bigfile temporary tablespace mytemp;


After this command, I can see the "select * from dba_tablespaces;" and "select * from dba_data_files;"


select tablespace_name,contents,bigfile from dba_tablespaces;



select file_name,tablespace_name,autoextensible from dba_data_files;



Now, I created table spaces. I can start to create table. Please look at this, there are sample example to create table. 


create table user.info ( name varchar2(15), id number(10) ) tablespace myspace;


This command create "error" like below. This error is occurred by table name.



In oracle, table name must be "schema (=user)"+"table name". This is the reason why the schema (=user) is import. Because of this, I have to revise the command below. "MYADMIN" is created user before.


create table MYADMIN.user_info ( name varchar2(15), id number(10) );


After this command I can see the table information with "select * from dba_tables;"


select * from dba_tables;

select * from dba_tables where owner='MYADMIN';



There are 2 things special. I insert "MYADMIN.user_info" as the table name. Howerver, oracle re-arrange this table name with "owner" and "table_name". Also, "USERS" tablespace is allocated for this table, which is default permanent tablespace. However I want that this table is located in "MYSAPCE" table space. Thus, it should be revised like below.


create table MYADMIN.user_info ( name varchar2(15), id number(10) ) tablespace myspace;


However, I can create this. Because this table name has already existed. Thus I need to drop this table with this command.


drop table MYADMIN.user_info;



Now, this is what I want.


6. Insert, Update, Delete Data


Before start this part, I need to covert account with "MYADMIN", which is used as the "schema name".


select * from user_tables;


"user_tables" show the information which belonged to logon account. If I can see table only I create, it is OK.



However, there is other way to find out logon current user. In this instruction, "select user from dual;" is command.


select user from dual;



I will follow this instruction. At first, I will try to insert some data into "user_info" table;


insert into user_info (id, name) values (101,'fox');

insert into MYADMIN.user_info (id, name) values (102,'wolf');


Please note that I can use both of "schema+table name" and "table name", because the current user is same as the schema name. After this command, look at the table information like below.


select * from MYADMIN.user_info;



Now, I will update the data. Please note I use "schema+table name" as the table name. It does not affect the result.


update MYADMIN.user_info set ID=103 where name='wolf';



Finally, Delete is left. This is not difficult to run.


delete from user_info where id=103;


7. Troubleshooting. (table privileges with other schema)


I am happy to learn how to insert, update and delete data. However, I need to think about my privileges. So far, I did not give any permission about table. The reason why this can be done is that this user is the "schema user". It look like admin user for this table. If I create another user (=schema), I wonder if this user can insert, update and delete with this table.


# create new (another) user

create user myuser indentified by myuser;


This user does not any role and privileges at the beginning. 





I can not logon into the Database. I add the role with "connect"


grant connect to myuser;


Now, I can login. However, I can not select, insert, update and delete over table. I need to give some privileges.



With administrator account, I will give this user some permissions. Please, look at the this instruction.


grant select, insert, update, delete on MYADMIN.user_info to MYUSER;

Now, I can select, insert, update and delete.




If I want to know what kinds of table privileges does this user has, use this command


select * from dba_tab_privs where grantee='MYUSER';


This is basic oracle database concept. I hope it will be helpful. If I have enough time to learn, I will handle more. However, I am not DBA engineer. I hope I can keep touch about this part again.


Reference


[ 1 ] https://docs.aws.amazon.com/ko_kr/AmazonRDS/latest/UserGuide/USER_ConnectToOracleInstance.html

[ 2 ] https://www.oracle.com/technetwork/developer-tools/sql-developer/downloads/index.html

[ 3 ] https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_8003.htm#SQLRF01503

[ 4 ] https://chartio.com/resources/tutorials/how-to-create-a-user-and-grant-permissions-in-oracle/

[ 5 ] https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7003.htm

[ 6 ] https://stackoverflow.com/questions/8496152/how-to-create-a-tablespace-with-multiple-datafiles

[ 7 ] https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sqlrf/CREATE-TABLESPACE.html#GUID-51F07BF5-EFAF-4910-9040-C473B86A8BF9

[ 8 ] https://www.java2s.com/Code/Oracle/User-Previliege/Getcurrentusername.htm

[ 9 ] https://www.oracle-dba-online.com/sql/insert_update_delete_merge.htm

How does the flannel work?


Recently, I am studying kubernetis. During studying, I have known about the flannel. There is some instruction to reproduct simply. I will follow this instruction.


1. Pre-requisite


There are some preparation. Docker and Etcd should be installed before. Here is instruction for installation of Docker. I will install community engine on 2 nodes running "ubuntu 16.04".


sudo apt-get remove docker docker-engine docker.io

sudo apt-get update

sudo apt-get install \

    apt-transport-https \

    ca-certificates \

    curl \

    software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo apt-key fingerprint 0EBFCD88

sudo add-apt-repository \

   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \

   $(lsb_release -cs) \

   stable"

sudo apt-get update

sudo apt-get install docker-ce  


And then, I will install Etcd. I have already written how to install and use Etcd in this post. However, it is more simple in this instruction. In my case, I will run the command in "root directory"


wget https://github.com/coreos/etcd/releases/download/v3.0.12/etcd-v3.0.12-linux-amd64.tar.gz

tar zxvf etcd-v3.0.12-linux-amd64.tar.gz

cd etcd-v3.0.12-linux-amd64


After installation, I will edit the "/etc/hosts" file before running this Etcd. Please note that host name has only single IP address on this file.


vi /etc/hosts

147.75.65.69    node1

147.75.65.63    node2


Each nodes can communicate with each other with these IP addresses.


# At node 1

nohup ./etcd --name docker-node1 --initial-advertise-peer-urls http://node1:2380 \

--listen-peer-urls http://node1:2380 \

--listen-client-urls http://node1:2379,http://localhost:2379 \

--advertise-client-urls http://node1:2379 \

--initial-cluster-token etcd-cluster \

--initial-cluster docker-node1=http://node1:2380,docker-node2=http://node2:2380 \

--initial-cluster-state new&


# At node 2

nohup ./etcd --name docker-node2 --initial-advertise-peer-urls http://node2:2380 \

--listen-peer-urls http://node2:2380 \

--listen-client-urls http://node2:2379,http://localhost:2379 \

--advertise-client-urls http://node2:2379 \

--initial-cluster-token etcd-cluster \

--initial-cluster docker-node1=http://node1:2380,docker-node2=http://node2:2380 \

--initial-cluster-state new&


Now, I am ready to start the flannel configuration.


cd etcd-v3.0.12-linux-amd64

./etcdctl cluster-health

member 43bb846a7344a01f is healthy: got healthy result from http://node2:2379

member a9aee06e6a14d468 is healthy: got healthy result from http://node1:2379

cluster is healthy


2. Flannel installation.


Download and install the flannel command on each nodes. In my case, I will run the command in "root directory"


wget https://github.com/coreos/flannel/releases/download/v0.6.2/flanneld-amd64 -O flanneld && chmod 755 flanneld


I will make configuration file to create the network topology.


vi flannel-network-config.json

{

    "Network": "172.16.0.0/12",

    "SubnetLen": 24,

    "SubnetMin": "172.16.16.0",

    "SubnetMax": "172.31.247.0",

    "Backend": {

        "Type": "vxlan",

        "VNI": 172,

        "Port": 8889

    }

}


In this documentation, there are the meaning of the above parameters. Especially, "SubnetLen" is IP address range allocated in each host. Flannel use the configuration from Etcd, /coreos.com/network/config. I will set the configuration on Node 1


# At node 1

cd etcd-v3.0.12-linux-amd64/

~/etcd-v3.0.12-linux-amd64$ ./etcdctl set /coreos.com/network/config < ../flannel-network-config.json


I can check if the configuration is set or not on Node 2.


# At node 2

cd etcd-v3.0.12-linux-amd64/

~/etcd-v3.0.12-linux-amd64$ ./etcdctl get /coreos.com/network/config | jq .

{

  "Network": "172.16.0.0/12",

  "SubnetLen": 24,

  "SubnetMin": "172.16.16.0",

  "SubnetMax": "172.31.247.0",

  "Backend": {

    "Type": "vxlan",

    "VNI": 172,

    "Port": 8889

  }

}


Now, I am ready to start the flannel. Before start flannel, I have to look at my network interface status.


# At node 1

nohup sudo ./flanneld -iface=bond0 &


# At node 2

nohup sudo ./flanneld -iface=bond0 &


After start flannel, I can see new interface which is named with "flannel.VNI". In this case, It should be flannel.172.


flannel.172 Link encap:Ethernet  HWaddr 82:41:de:d4:77:d3

          inet addr:172.16.75.0  Bcast:0.0.0.0  Mask:255.240.0.0

          inet6 addr: fe80::8041:deff:fed4:77d3/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1450  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:8 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


Also, I can get some information from Etcd.


cd etcd-v3.0.12-linux-amd64/

~/etcd-v3.0.12-linux-amd64# ./etcdctl ls /coreos.com/network/subnets

/coreos.com/network/subnets/172.16.68.0-24

/coreos.com/network/subnets/172.16.75.0-24


This mean that each host has these subnets each. I can see more detail. 


cd etcd-v3.0.12-linux-amd64/

~/etcd-v3.0.12-linux-amd64# ./etcdctl get /coreos.com/network/subnets/172.16.68.0-24 | jq .

{

  "PublicIP": "147.75.65.63",

  "BackendType": "vxlan",

  "BackendData": {

    "VtepMAC": "7a:ac:15:15:2b:61"

  }

}


This is configuration for the flannel. I can also see the what flannel network is assigned with "/var/run/flannel/subnet.env". Please note that this file will be used for next step, docker daemon configuration.


cat /var/run/flannel/subnet.env

FLANNEL_NETWORK=172.16.0.0/12

FLANNEL_SUBNET=172.16.68.1/24

FLANNEL_MTU=1450

FLANNEL_IPMASQ=false


3. Docker daemon configuration.


Docker does not use flannel default. It has swarm mode to make overlay network. Therefore, it is necessary to change to use this flannel as default network module. At first, I have to stop the Docker daemon on each hosts, node1 and node2.


# Node 1 and Node 2

sudo service docker stop


I will restart Docker daemon with this flannel configuration.


# Node 1 and Node 2

source /run/flannel/subnet.env
sudo ifconfig docker0 ${FLANNEL_SUBNET}
sudo dockerd --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} &


Before restart Docker daemon, there is "docker0" interface default which has "172.17.0.1" IP address. It will be changed with the network what I defined.


# Before restart with flannel configuration

ifconfig docker0

docker0   Link encap:Ethernet  HWaddr 02:42:f6:10:ac:49

          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0

          UP BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


# After restart with flannel configuration

ifconfig docker0
docker0   Link encap:Ethernet  HWaddr 02:42:f6:10:ac:49
          inet addr:172.16.75.1  Bcast:172.16.75.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


4. Create the Test container and Start it.


Now, I will create 2 container for the test. 


# At the node 1

sudo docker run -d --name test1  busybox sh -c "while true; do sleep 3600; done"


# At the node 2

ssudo docker run -d --name test2  busybox sh -c "while true; do sleep 3600; done"


Depends on the container properties, the container can be stopped after exit. "sh -c "while true; do sleep 3600; done" make this container keep alive for 1 hour. It is enough for the test.


5. Analysis container networks.


In this post, I will explain how to work in docker swarm mode. It is good to analysis the network topology of docker. At first, go to "/var/run/docker", there is the "netns" directory. There is the network configuration of the container.


# At node 1 and node 2 

cd /var/run/

ln -s docker/netns/ netns


After this symbolic link, I can see the network namespace list like below. "ip netns list" show the namespace ID.


ip netns list

faf9928b897f (id: 0)


I can see more detail information with this ID. "ip netns exec" show the same result with "docker exec". Thus I can see the same result with "docker exec test1 ip -d addr show"


# At the Node 1

ip netns exec b5380e6b336a ip -d addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default

    link/ether 02:42:ac:10:4b:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0

    veth

    inet 172.16.75.2/24 brd 172.16.75.255 scope global eth0

       valid_lft forever preferred_lft forever


# At the Node 2

ip netns exec faf9928b897f ip -d addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0

    inet 127.0.0.1/8 scope host lo

       valid_lft forever preferred_lft forever

15: eth0@if16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default

    link/ether 02:42:ac:10:44:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0

    veth

    inet 172.16.68.2/24 brd 172.16.68.255 scope global eth0

       valid_lft forever preferred_lft forever


6. Test and Troubleshooting


Now, I have know that "172.16.75.2" is container IP address on Node 1 and "172.16.68.2" is container IP address on Node 2. Flannel offers the overlay network between hosts. So, I will send ICMP (ping) from node1 to node2


ip netns exec b5380e6b336a ping 172.16.68.2

PING 172.16.68.2 (172.16.68.2) 56(84) bytes of data.

^C

--- 172.16.68.2 ping statistics ---

6 packets transmitted, 0 received, 100% packet loss, time 5040ms


Hmm. It does not work. From Docker 1.13 default iptables policy for FORWARDING is DROP,


# At Node 1 and Node 2

sudo iptables -P FORWARD ACCEPT


Wow, I can send ICMP each other.


ip netns exec b5380e6b336a ping 172.16.68.2

ip netns exec b5380e6b336a ping 172.16.68.2 -c 4

PING 172.16.68.2 (172.16.68.2) 56(84) bytes of data.

64 bytes from 172.16.68.2: icmp_seq=1 ttl=62 time=0.364 ms

64 bytes from 172.16.68.2: icmp_seq=2 ttl=62 time=0.310 ms

64 bytes from 172.16.68.2: icmp_seq=3 ttl=62 time=0.319 ms

64 bytes from 172.16.68.2: icmp_seq=4 ttl=62 time=0.308 ms


--- 172.16.68.2 ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 2998ms

rtt min/avg/max/mdev = 0.308/0.325/0.364/0.026 ms


This is the flannel.


Reference


[ 1 ] https://docs.docker.com/install/linux/docker-ce/ubuntu/

[ 2 ] https://docker-k8s-lab.readthedocs.io/en/latest/docker/docker-etcd.html

[ 3 ] https://docker-k8s-lab.readthedocs.io/en/latest/docker/docker-flannel.html

[ 4 ] https://github.com/coreos/flannel/blob/master/Documentation/configuration.md

How to use AWS AppStream 2.0?


Have you ever used "Google Docs"? In this case, there is no host like PC. AppStream make like this. I can access my application from outside, such as Internet. AppStream has some advantage and disadvantage. It is simple to access and manage. Also it is more secure. Because the user can not do other things on this host. However, It is not easy to deploy with right size, even if AWS offer auto-scaling. I need to how much use can be used at the same time. Most of this post are referenced by this.


1. Create Image


AppStream is auto-scaling system. Thus, I need customized standard image to deploy.  In this image, I can install my application. It will be deployed. Please note that I will set this instance to create image over the subnet which can communicate with Internet, however the real-instance can be located over the private subnet which can not communicate with Internet. In Images, there are 2 category, Image Registry and Image Builder. At the first, I will select Image Builder to create my image which is installed for terminal. Launch Image Builder. 



Now, I need to select basic OS to create my image. In my case, I will choose Windows 2012 R2, which is named wit "Base-Image-Builder-06-12-2018". Please note this image can be different by the AWS Region.



Insert the image name and select the type for CPU and Memory. These parameters can not changed after first creation. Thus, I need another images when I need other size of instance.


Select the network which the instance attach to. Please note that this is the network only for image creation. When the real-system is deployed, I can define the network. I will touch at the next time. In this case, I need to download terminal tools from Internet. Thus, this instance will be located over the subnet which can communicate with Internet.


The subnet should be routed with NAT gateway. AppStream does not assign EIP. Thus, It is not possible to download from Internet, if the instance is located over the sunbet with Internet gatway.



Review and Launch.



2. Connect Image


Now, I need to install my application on the launched image. After status change from Pending to Running, I can connect this image.


After connect, I can see the screen like below. I need to select user to login. At this time, I will select "Administrator" at the first.



Now, I can see the windows which is login with "Administrator" account. Open the CMD and Run "ipconfig" to see the network interface information. There are 2 interface. "11.8.48.79" is interface which is one of VPC subnet network. "198.19.168.187" is the interface which offer the display for users. "198.19.168.187" interface is controlled by AWS managed. Most of traffic is pass through the "11.8.48.79" interface. I can download some files from this interface.



On the desktop, there is firefox. Open this and write "https://www.putty.org/". In my case, I will download "Putty" for the sample application.



After download the file, (Default, the downloaded file will be located in documents directory), Install this application.



Please remember the installation path for the next step. In this case, the putty is installed under "C:\Programs". After installation, close all of windows. In the desktop, I can see the "Image Assistant". This application help me to register my application for the AWS AppStream.



AppStream 2.0 Image Assistant application should be run. Follow the step by this application.




3. AppStream 2.0 Image Assistant.


I need to register my application for AppStream 2.0. Click "Add App", Find out the running file. 



"App Launch Setting" menu is opened. In this instruction, there are more information about this. "Launch Parameters" and "Working Directory" are depend on my application. In this case, I will leave blank.. Just click "Save"



Click "Next"



This is important step. In this part, I can customize my application. I need to re-login with Template User. In this mode, I can define my application how to work. Click "Switch User"



Select "Template User"



After login, I can change OS configuration and Application settings. In my case, I will register sample session information. "my-sample" session information is updated over my application.



Also, I can run this application with what I want to do. I open SSH to my sample host.



I have done all of things. In the desktop, there is Images Assistant is located. Run it. And back to main with Administrator account.



Select "Administrator" and login again.



After login, I can see "Save settings" button activated. Click this button and click "Next"



Now, I have to verify if this application work correctly. I will switch user with "user" account.



Select "Test User"




After login, I can run "Putty" again. And I can confirm that "my-sample" session in configuration is remained.



Run "Images Assistant" in the desktop, and go back to main with "Administrator" account.



Select "Administrator" again.



Now, I am ready to finish. Launch.



After complete to launch, click continue.



Fill with image name.



Review and Create Image.



The viewer will be disconnected. And the building image will be started.



It will take about 10~20 minutes. And then, I can see the my image on AWS console.


4. Snapshotting Image. 


During the time, I can see the AWS console to check the status. In the "Image Registry", there is "image" which is creating. 



In "Image Builder", my based image has the status "Snapshotting". Please note that I can not do any action in this "Snapshotting" status.



I can expect that "Snapshotted image" is registered in Image Registry.


5. Delete Image in "Image Builder" (Optional)


There is no relationship between image in registry and image in builder. So, I can delete and remove this image in the builder. If you have change to make another type of image include configuration, I will remain this image. However, this is not necessary in this post. I also show the relationship between them.



After the status is "Stopped", I can delete this image.


6. Create fleet.


I have a image which I want to deploy. I need to define the network to deploy. The fleet has this kinds of role. Create Fleet.



Insert Name for this fleet.



I can see my image which has been created. Select the image and Next.



From here, network and security, capacity for scaling are defined. Select type of CPU and RAM for this instance. This is not changeable. If I want to change, I need to create another fleet. In fleet type, there are 2 modes, "On-Demand" and "Always-on". I want to save my money, so I will select "On-Demand"



Maximum session duration means "User can stay during this time once". Disconnect timeout means "After session finish, this instance can not re-assign to other user until this time spent". Minimum and Maximum capacity define the number of con-current session. AppStream offer auto-scaling, however, it take 10~20 minutes. It is too long, therefore, I need to define with proper number. In Scaling detail, this is the parameters to scale-out.



In here, the nework and security group is defined. I can locate AppStream instance into the subnet which does not communicate with Internet. In image builder step, I located at the subnet which communicate with Internet.



Review and Create.



Now I have a fleet.



7. Create Stack and Connect with Fleet


Stack has the role to define "User Pattern". Create Stack



Insert Name



I can define if I use Home Folders for each sessions. In my case, I do not want that the user remain their files on the instance. Because this instance will be shared with others. Default, it is enabled. However, I disable the option.



I can also user behavior such as "Copy and Pasts" usages. Just define what you want.



Review and Create.



After creation of stack, I need to associate fleet. In Actions, there is "Associate Fleet".


Select the fleet which is created before,



And confirm the stack details. If you want to remove fleet, you have to dis-associate this relationship at first.



8. Create User Pool.


In workspace, I need AD system. Fortunately AppStream offer this feature through AWS console. Create User.


Insert information for user. The Email address should be correct. The access link, account and temporary password are sent to this email address.



After creation of user, I need to associate with stack. I associate with the stack already created. 



Select the stack.



Look at the details, I will resend welcom email which is include access link.



I will received this email.



9. Accessing and Login the AppStream.


Click the Link which is include in email. New windows is opened like below.



After first login, I need to change my password.



Re-login and I can see like below. I registered the putty application only. Therefore, Putty Icon is appeared.



I can see the my application opened.



This is the AWS AppStream, I hope this post help you!


10. Troubleshooting


10-1. Remote User.


In the AWS console, I can not delete the user. It is only possible with API. I will use awscli command.


aws appstream delete-user --user-name xxxxxxx@xxxxxxx --authentication-type USERPOOL


10-2. Delete S3 bucket


AppStream can save Home folders and Application configuration in S3 bucket. This bucket will be created automatically. When I delete this S3 bucket, I can not make success. Because there are some limitation to protect S3 bucket. So I have to change this part at the first to remove.



After clear in Bucket Policy, I can remote this bucket.


Reference


[ 1 ] https://docs.aws.amazon.com/appstream2/latest/developerguide/tutorial-image-builder.html

[ 2 ] https://d1.awsstatic.com/product-marketing/AppStream2.0/Amazon%20AppStream%202.0%20Getting%20Started%20Guide%20April%202018.pdf

[ 3 ] https://docs.aws.amazon.com/appstream2/latest/developerguide/managing-network.html

[ 4 ] https://docs.aws.amazon.com/cli/latest/reference/appstream/delete-user.html

+ Recent posts