|
| 1 | + |
| 2 | +## Introduction |
| 3 | + |
| 4 | +Autonomous Transaction Processing provides all of the performance of the market-leading Oracle Database in an environment that is tuned and optimized for transaction processing workloads. Oracle Autonomous Transaction Processing (or ATP) service provisions in a few minutes and requires very little manual ongoing administration. |
| 5 | + |
| 6 | + |
| 7 | +ATP provides a TLS 1.2 encrypted secure connectivity for applications. In fact, using a secure encryption wallet is the only way to connect to an ATP service instance, ensuring every connection to your database is secure, regardless how it gets routed. |
| 8 | + |
| 9 | +To **log issues**, click [here](https://github.com/oracle/learning-library/issues/new) to go to the github oracle repository issue submission form. |
| 10 | + |
| 11 | +## Objectives |
| 12 | + |
| 13 | +- Learn how to build a linux node.js application server and connect it to an Oracle ATP database service |
| 14 | + |
| 15 | +## Required Artifacts |
| 16 | + |
| 17 | +- The following lab requires an Oracle Public Cloud account. You may use your own cloud account, a cloud account that you obtained through a trial, or a training account whose details were given to you by an Oracle instructor. |
| 18 | + |
| 19 | +## Steps |
| 20 | + |
| 21 | +### **STEP 1: Create a Virtual Cloud Network** |
| 22 | + |
| 23 | +Virutal Cloud Network (VCN) is a private network that you set up in the Oracle data centers, with firewall rules and specific types of communication gateways that you can choose to use. A VCN covers a single, contiguous IPv4 CIDR block of your choice. See [Default Components that Come With Your VCN](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/overview.htm#Default). The terms virtual cloud network, VCN, and cloud network are used interchangeably in this documentation. For more information, see [VCNs and Subnets](https://docs.cloud.oracle.com/iaas/Content/Network/Tasks/managingVCNs.htm). |
| 24 | + |
| 25 | +- Login to your Oracle Cloud Infrastructure and Click on **Menu** and select **Network** and **Virtual Cloud Networks**. |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +In order to create a VCN we need to select a Compartment from the List Scope. For this lab we will be selecting **Demo** compartment. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +- After selecting **Demo** compartment click on Create Virtual Cloud Network to create VCN |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +- This will bring Create Virtual CLoud Netowrk screen where you will specify the configurations. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +- Enter the following in Create Virtual Cloud Network window |
| 42 | + |
| 43 | +**Create In Compartment**: Select the compartment, **Demo**. By default, this field displays your current compartment. |
| 44 | + |
| 45 | +**Name**: Enter a name for your cloud network. |
| 46 | + |
| 47 | +Check on **Create Virtual Cloud Network Plus Related Resources** option. By selecting this option, you will be creating a VCN with only public subnets. The dialog expands to list the items that will be created with your cloud network. |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +- Click on Create Virtual Cloud Network. |
| 52 | + |
| 53 | +A confirmation page displays the details of the cloud network that you just created. The cloud network has the following resources and characteristics (some of which are not listed in the confirmation dialog): |
| 54 | +- CIDR block range of 10.0.0.0/16 |
| 55 | +- An internet gateway |
| 56 | +- A route table with a default route rule to enable traffic to and from the internet gateway |
| 57 | +- A [default security](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securitylists.htm#Default) list |
| 58 | +- A public subnet in each availability domain |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +### **STEP 2: Provision a linux compute VM to serve as the app server** |
| 64 | + |
| 65 | +- Provision a linux compute VM to serve as the app server. |
| 66 | + |
| 67 | +- Log into your Oracle Cloud Infrastructure and click on Menu and select Compute and Instances. |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +- In order to create Compute Instance we need to select a Compartment. Select **Demo** Compartment which we created in Lab100 |
| 72 | + |
| 73 | +- Click on Create Instance |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +Enter the following to Create Linux Instance |
| 79 | + |
| 80 | +- **Name**: Enter a friendly name to identify your linux instance |
| 81 | +- **Availability Domain**: Oracle Cloud Infrastructure is hosted in Regions, which are localized geographic areas. Each Region contains three Availability Domains which are isolated and fault-tolerant data centers that can be used to ensure high availability. In the Availability Domain field, select the Availability Domain in which you want to run the instance. For example, scul:PHX-AD-1. |
| 82 | +- **Boot Volume**: Oracle-Provided OS Image |
| 83 | +- **Image Operating System**: Oracle Linux 7.5 |
| 84 | +- **Shape Type**: Virtual Machine |
| 85 | +- **Shape**: The shape of an instance determines the number of CPUs, the amount of memory, and how much local storage an instance will have. Shape types with names that start with VM are Virtual Machines, while shape types with names that start with BM are Bare Metal instances. Choose the appropriate shape for your Virtual Machine instance in the Shape field. For this lab we will be using, **VM.Standard2.1 (1 OCPU, 15GB RAM)**. |
| 86 | +- **Image Version**: Please select the latest version, 2018.09.25-0(latest) |
| 87 | +- **Boot Volume Configuration**: When you launch a virtual machine (VM) or bare metal instance based on an Oracle-provided image or custom image, a new boot volume for the instance is created in the same compartment. That boot volume is associated with that instance until you terminate the instance. When you terminate the instance, you can preserve the boot volume and its data, see Terminating an Instance. For this lab we will be using Selected image's default boot volume size: 46.6 GB only. |
| 88 | +- **SSH Keys**: If the operating system image for your instance uses SSH keys for authentication (for example, Linux instances), then you must provide an SSH public key. To choose a public key file, ensure that Choose SSH Key Files is selected, then click Browse. |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +- Choose the public key to upload (for example, id_rsa.pub), then click Open. Note: some operating systems may use a different interface for file selection. |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +If you do not have ssh key pair you can create using command line. |
| 97 | + |
| 98 | +- Open terminal for entering the commands |
| 99 | +- At the prompt, enter the following: |
| 100 | + |
| 101 | +``` |
| 102 | +ssh-keygen -t rsa -N "" -b "2048" -C "key comment" -f path/root_name |
| 103 | +``` |
| 104 | + |
| 105 | +Where |
| 106 | +- **-t rsa**: Use the RSA algorithm |
| 107 | +- **-N "passphrase"**: Passphrase to protect the use of the key (like a password). If you don't want to set a passphrase, don't enter anything between the quotes. |
| 108 | +- **-b "2048"**: Generate a 2048 bit key. |
| 109 | +- **-C "key comment": A name to identify the key. |
| 110 | +- **-f path/root_name**: The location where the key pair will be saved and the root name for the files. For example, if you give the root name as id_rsa, the name of the private key will be id_rsa and the public key will be id_rsa.pub. |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +#### For windows users: |
| 115 | + |
| 116 | +- Download and run the [PuTTY](http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html) installer. |
| 117 | + |
| 118 | +- Generate a private and public key pair: |
| 119 | + - Go to the Windows Start menu -> All Programs -> PuTTY and open PuTTYgen |
| 120 | + - Click the 'Generate' button and PuTTYgen will ask you to make some random movement with your mouse until it has enough random data to generate a secure key for you |
| 121 | + - Click the 'Save private key' button and save the resulting file somewhere safe and only accessible by you! |
| 122 | + |
| 123 | +- **Virtual Cloud Network**: In the Virtual Cloud Network field, select the Virtual Cloud Network for the instance which we created earlier in this lab. |
| 124 | +- **Subnet**: In the Subnet field, select the subnet to which to add the instance. For example, the public subnet scul:PHX-AD-1. |
| 125 | + |
| 126 | +That is all you need to enter to create Linux instance on OCI. |
| 127 | + |
| 128 | +- Click on **Create Instance** at the bottom |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | +- While the instance is being created, its state is displayed as "PROVISIONING". |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +- The status changes to "RUNNING" when the instance is fully operational. |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +- Note the public IP of the machine provisioned and ssh into this host and configure it to run node.js on ATP. |
| 143 | + |
| 144 | +### **STEP 3: Install node.js, python 2.7 and required libaio libraries** |
| 145 | + |
| 146 | +In order to install the required package on linux environment we need to ssh into our linux host machine. |
| 147 | + |
| 148 | +- Open Terminal and ssh as user opc to your host machine. |
| 149 | + |
| 150 | +Change the below command to your ssh key path. |
| 151 | + |
| 152 | +``` |
| 153 | +$ssh -i /Users/tejus/Desktop/sshkeys/id_rsa opc@ipaddress |
| 154 | +``` |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +Once you have succesfully ssh into the host machine install the packages. |
| 159 | + |
| 160 | +- Download and install node.js, python and git. We will need git to download instant client and sample app. |
| 161 | + |
| 162 | +``` |
| 163 | +$curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash - |
| 164 | +``` |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | +- Install nodejs |
| 169 | + |
| 170 | +``` |
| 171 | +sudo yum install nodejs |
| 172 | +``` |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +- Install python 2.7 if it does not already exist on your machine. |
| 178 | + |
| 179 | +#### Note: OEL 7.5 comes pre-installed with python 2.7 |
| 180 | + |
| 181 | +- You can check python version |
| 182 | + |
| 183 | +``` |
| 184 | +python --version |
| 185 | +``` |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | +- Ensure libaio is installed and up to date |
| 190 | + |
| 191 | +``` |
| 192 | +sudo yum install libaio |
| 193 | +``` |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | +- You can check your node, npm installs using |
| 198 | +``` |
| 199 | +node --version |
| 200 | +``` |
| 201 | + |
| 202 | + |
| 203 | +``` |
| 204 | +npm --version |
| 205 | +``` |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | +- Install git to your host machine. |
| 211 | + |
| 212 | +``` |
| 213 | +sudo yum install git |
| 214 | +``` |
| 215 | + |
| 216 | + |
| 217 | +### **STEP 4: Install and configure Oracle Instant Client** |
| 218 | + |
| 219 | +- Download and install Oracle Instant Client software |
| 220 | + |
| 221 | +#### Note: You can download it from OTN [here](https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html) |
| 222 | + |
| 223 | +Copy instant client from you local machine to linux host machine |
| 224 | +``` |
| 225 | +wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basic-linux.x64-19.3.0.0.0dbru.zip |
| 226 | +``` |
| 227 | + |
| 228 | +- Unzip the file and move the files to /opt/oracle/instantclient_12_2 |
| 229 | + |
| 230 | +``` |
| 231 | +mkdir instantclient_19_3_linux/ |
| 232 | +
|
| 233 | +cd instantclient_19_3_linux/ |
| 234 | +
|
| 235 | +unzip instantclient-basic-linux.x64-19.3.0.0.0dbru.zip |
| 236 | +
|
| 237 | +cd instantclient_19_3/ |
| 238 | +
|
| 239 | +sudo mkdir /opt/oracle |
| 240 | +
|
| 241 | +sudo mv /home/opc/instantclient_19_3_linux/instantclient_19_3/ /opt/oracle/instantclient_19_3/ |
| 242 | +``` |
| 243 | + |
| 244 | +### **STEP 5: Clone Node application** |
| 245 | + |
| 246 | +- Download a sample Node application in folder /home/opc |
| 247 | + |
| 248 | +``` |
| 249 | +$ wget --no-check-certificate --content-disposition https://github.com/oracle/learning-library/blob/master/workshops/autonomous-transaction-processing/scripts/500/ATPnodeapp.zip?raw=true |
| 250 | +``` |
| 251 | + |
| 252 | +- Unzip ATPnodeapp.zip |
| 253 | + |
| 254 | +``` |
| 255 | +$ mkdir ATPnodeapp && cd ATPnodeapp |
| 256 | +
|
| 257 | +$ unzip /home/opc/ATPnodeapp.zip |
| 258 | +``` |
| 259 | +Now that you have a sample application setup, lets get your database's secure wallet for connectivity |
| 260 | + |
| 261 | +### **STEP 6: Upload connection wallet and run sample app** |
| 262 | + |
| 263 | +- Upload the connection wallet and run sample app |
| 264 | + |
| 265 | +- From your local machine copy the secured wallet file to host machine. |
| 266 | +The format of the below command is |
| 267 | + |
| 268 | +scp -i **"/path_to_private_key "** **"/path_to_wallet_dbname.zip"** opc@ipaddress:/home/opc/ATPnodeapp |
| 269 | + |
| 270 | +``` |
| 271 | +scp -i ~/priv-ssh-keyfile wallet_YOURWALLET.zip opc@ipaddress:/home/opc/ATPnodeapp |
| 272 | +``` |
| 273 | + |
| 274 | +- ssh back to your host machine and unzip the wallet file |
| 275 | + |
| 276 | +``` |
| 277 | +cd /home/opc/ATPnodeapp |
| 278 | +
|
| 279 | +unzip wallet_YOURWALLET.zip -d wallet_YOURWALLET/ |
| 280 | +``` |
| 281 | + |
| 282 | +- Edit sqlnet.ora as follows |
| 283 | + |
| 284 | +``` |
| 285 | +cd /home/opc/ATPnodeapp/wallet_YOURWALLET/ |
| 286 | +
|
| 287 | +nano sqlnet.ora |
| 288 | +
|
| 289 | +WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY=$TNS_ADMIN))) |
| 290 | +SSL_SERVER_DN_MATCH=yes |
| 291 | +``` |
| 292 | + |
| 293 | +- Set LD_LIBRARY_PATH in your bash_profile as |
| 294 | + |
| 295 | +``` |
| 296 | +export LD_LIBRARY_PATH=/opt/oracle/instantclient_19_3:$LD_LIBRARY_PATH |
| 297 | +``` |
| 298 | + |
| 299 | +- Set env variables TNS_AMDIN to point to the wallet folder and edit sqlnet.ora file in wallet folder to point to the wallet. |
| 300 | + |
| 301 | +``` |
| 302 | +export TNS_ADMIN=/home/opc/ATPnodeapp/wallet_YOURWALLET/ |
| 303 | +``` |
| 304 | + |
| 305 | +- We have now set up all the required packages and settings to run our server.js. |
| 306 | + |
| 307 | +- Your sample application consists of 2 files, dbconfig.js and server.js. Set dbuser, dbpassword and connectString in dbconfig.js to point to your ATP database. |
| 308 | + |
| 309 | +- **dbuser**: admin |
| 310 | +- **dbpassword**: Admin passwrod, in our case it is 'WElcome_123#' |
| 311 | +- **connectString**: 'yourdbname_high' |
| 312 | + |
| 313 | +``` |
| 314 | +nano dbconfig.js |
| 315 | +
|
| 316 | +module.exports= { |
| 317 | +dbuser: 'admin', |
| 318 | +dbpassword: 'WElcome_123#', |
| 319 | +connectString: 'atplab_high' |
| 320 | +} |
| 321 | +``` |
| 322 | + |
| 323 | +- Run server.js |
| 324 | + |
| 325 | +``` |
| 326 | +cd /home/opc/ATPnodeapp |
| 327 | +
|
| 328 | +npm install oracledb |
| 329 | +
|
| 330 | +node server.js |
| 331 | +``` |
| 332 | + |
| 333 | + |
| 334 | + |
| 335 | + |
| 336 | +- Once the server.js is running open up another terminal and ssh into the linux machine and get into your node app folder and run app in background and test with curl. |
| 337 | + |
| 338 | +``` |
| 339 | +$ssh -i /path_to_private_key/sshkeys/id_rsa opc@ipaddress |
| 340 | +
|
| 341 | +cd /home/opc/ATPnodeapp/ |
| 342 | +
|
| 343 | +curl http://localhost:3050 |
| 344 | +``` |
| 345 | + |
| 346 | +- The application confirms connectivity to your ATP instance. |
| 347 | + |
| 348 | + |
| 349 | + |
| 350 | +You have now successfully connected your node app to Autonomous Transaction Processing database. |
| 351 | + |
| 352 | +- You are now ready to move to the next lab. |
0 commit comments