通過Vagrant訪問Oracle 18c資料庫
版權宣告:本文為Buddy Yuan原創文章,未經允許不得轉載。原文地址: ofollow,noindex" target="_blank">http://www.dboracle.com/archivers/通過Vagrant訪問Oracle 18c資料庫.html
在上一篇文章中,我寫了 使用VAGRANT 快速安裝ORACLE DATABASE 18C 。在這篇文章中,我們將學習如何使用Vagrant訪問Oracle 18c資料庫。首先我們需要檢查VM的狀態。使用上篇文章用到的Vagrant global-status命令。
PS G:\VM DATA\vagrant-boxes\OracleDatabase\18.3.0> vagrant global-status idnameproviderstatedirectory ---------------------------------------------------------------------------------------------- b1be299oracle-18c-vagrant virtualbox running G:/VM DATA/vagrant-boxes/OracleDatabase/18.3.0 The above shows information about all known Vagrant environments on this machine. This data is cached and may not be completely up-to-date (use "vagrant global-status --prune" to prune invalid entries). To interact with any of the machines, you can go to that directory and run Vagrant, or you can use the ID directly with Vagrant commands from any directory. For example: "vagrant destroy 1a2b3c4d"
接下來我們可以開啟Virtual Box虛擬機器看一下狀態。通過上一篇文章我們的作業系統自動建立了一個叫oracle-18c-vagrant的虛擬機器。
然後我們可以使用vagrant ssh命令登陸進主機。
PS G:\VM DATA\vagrant-boxes\OracleDatabase\18.3.0> vagrant ssh Welcome to Oracle Linux Server release 7.5 (GNU/Linux 4.14.35-1818.0.9.el7uek.x86_64) The Oracle Linux End-User License Agreement can be viewed here: * /usr/share/eula/eula.en_US For additional packages, updates, documentation and community help, see: * http://yum.oracle.com/ [vagrant@oracle-18c-vagrant ~]$ sudo su - oracle Last login: Mon Oct1 23:20:44 +08 2018 [oracle@oracle-18c-vagrant ~]$
切換到Oracle使用者之後,我們就可以執行一系列的命令來玩Oracle 18c了。
[oracle@oracle-18c-vagrant ~]$ ps -ef | grep pmon oracle800410 23:20 ?00:00:00 ora_pmon_ORCLCDB oracle908189720 23:32 pts/000:00:00 grep --color=auto pmon [oracle@oracle-18c-vagrant ~]$ ps -ef | grep tns root2120 22:53 ?00:00:00 [netns] oracle424010 23:05 ?00:00:00 /opt/oracle/product/18c/dbhome_1/bin/tnslsnr LISTENER -inherit oracle908689720 23:32 pts/000:00:00 grep --color=auto tns [oracle@oracle-18c-vagrant ~]$ sqlplus / as sysdba SQL*Plus: Release 18.0.0.0.0 - Production on Mon Oct 1 23:32:26 2018 Version 18.3.0.0.0 Copyright (c) 1982, 2018, Oracle.All rights reserved. Connected to: Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production Version 18.3.0.0.0 SQL> select name,open_mode from v$database; NAMEOPEN_MODE --------- -------------------- ORCLCDBREAD WRITE SQL> show pdbs CON_ID CON_NAMEOPEN MODERESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEEDREAD ONLYNO 3 ORCLPDB1READ WRITE NO SQL> exit Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production Version 18.3.0.0.0
我們安裝VM,預設在oracle使用者的home目錄下。有個setPassword.sh的指令碼。這個指令碼是給sys,system,pdb_admin設定密碼的。
[oracle@oracle-18c-vagrant ~]$ ls -lrt total 4 -rwxr-xr-x. 1 root root 784 Oct1 23:21 setPassword.sh [oracle@oracle-18c-vagrant ~]$ more setPassword.sh #!/bin/bash # LICENSE UPL 1.0 # # Copyright (c) 1982-2018 Oracle and/or its affiliates. All rights reserved. # # Since: November, 2016 # Author: [email protected] # Description: Sets the password for sys, system and pdb_admin # # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # ORACLE_PWD=$1 ORACLE_SID="`grep $ORACLE_HOME /etc/oratab | cut -d: -f1`" ORACLE_PDB="`ls -dl $ORACLE_BASE/oradata/$ORACLE_SID/*/ | grep -v pdbseed | awk '{print $9}' | cut -d/ -f6`" ORAENV_ASK=NO source oraenv sqlplus / as sysdba << EOF ALTER USER SYS IDENTIFIED BY "$ORACLE_PWD"; ALTER USER SYSTEM IDENTIFIED BY "$ORACLE_PWD"; ALTER SESSION SET CONTAINER=$ORACLE_PDB; ALTER USER PDBADMIN IDENTIFIED BY "$ORACLE_PWD"; exit; EOF
要想從虛擬機器中退出來,輸入exit就行了。
[oracle@oracle-18c-vagrant ~]$ exit logout [vagrant@oracle-18c-vagrant ~]$ exit logout Connection to 127.0.0.1 closed.
輸入vagrant halt就關閉虛擬機器了,如果你要刪除整個虛擬機器,執行vagrant destroy命令。
PS G:\VM DATA\vagrant-boxes\OracleDatabase\18.3.0> vagrant halt ==> oracle-18c-vagrant: Attempting graceful shutdown of VM...
當然我們還能執行一些命令檢視配置情況,例如vagrant port可以檢視埠情況,vagrant ssh-config可以檢視ssh配置資訊。
PS G:\VM DATA\vagrant-boxes\OracleDatabase\18.3.0> vagrant port The forwarded ports for the machine are listed below. Please note that these values may differ from values configured in the Vagrantfile if the provider supports automatic port collision detection and resolution. 22 (guest) => 2222 (host) 1521 (guest) => 1521 (host) 5500 (guest) => 5500 (host) PS G:\VM DATA\vagrant-boxes\OracleDatabase\18.3.0> vagrant ssh-config Host oracle-18c-vagrant HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile "G:/VM DATA/vagrant-boxes/OracleDatabase/18.3.0/.vagrant/machines/oracle-18c-vagrant/virtualbox/private_key" IdentitiesOnly yes LogLevel FATAL