Centos7.2上安装部署oracle11gR2数据库(命令行静默安装)

目录

文章目录

1. 机器准备

#一台虚拟机
hostname:myhost
ip:ip_address

2. 系统环境

[root@myhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@myhost ~]# firewall-cmd --state							 #查看防火墙的状态
running
[root@myhost ~]# firewall-cmd --list-ports                       #查看防火墙已经开放的端口
5666/tcp 10050/tcp
[root@myhost ~]# firewall-cmd --list-services                    #查看防火墙开放的服务
dhcpv6-client ssh
#假设设置oracle的服务端口为1521,允许1521/tcp端口访问 
[root@myhost ~]# firewall-cmd --zone=public --permanent --add-port=1521/tcp
success
[root@myhost ~]# firewall-cmd --reload                                       	#重新加载防火墙配置
success 
[root@myhost ~]# setenforce 0  &&    getenforce
Permissive
[root@myhost ~]# sed -i  "s/SELINUX=enforcing/SELINUX=disabled/g"  /etc/sysconfig/selinux 
[root@myhost ~]# cat /etc/sysconfig/selinux 

3. Oracle安前部署的准备工作(需要在Root用户下执行)

3.1 软件安装约定
/home/oracle/app
/home/oracle/app/etc  	#oracle数据库安装时初始化文件
/home/oracle/app/tools  #oracle数据库安装包存放目录
/home/oracle/app/oracle   #oracle数据库安装目录
/home/oracle/app/oraInventory  #oracle数据库配置文件目录
/home/oracle/app/oracle/product 
3.2 配置yum源并安装oracle数据库所需依赖包
[root@myhost ~]# yum install  epel* -y
[root@myhost ~]#  yum install -y gcc* gcc-* gcc-c++-* glibc-devel-* glibc-headers-* compat-libstdc* libstdc* elfutils-libelf-devel* libaio-devel* sysstat* unixODBC-* pdksh-* ksh* binutils 
3.3 检查是否有安装Oracle数据库
[root@myhost ~]# rpm -qa |grep oracle 
3.4 创建管理Oracle数据库的用户和组
#创建用户组oinstall
[root@myhost ~]# groupadd oinstall

#创建用户组dba
[root@myhost ~]# groupadd dba

#创建oracle用户,并加入到oinstall和dba用户组
[root@myhost ~]# useradd -g oinstall -G dba  oracle

#查看oracle用户所属主
[root@myhost ~]# groups oracle
oracle : oinstall dba

#设置用户oracle的登陆密码,如果不设置密码,后面CentOS的图形登陆界面没法登陆。
[root@myhost ~]# passwd oracle
更改用户 oracle 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@myhost ~]# id oracle
uid=1001(oracle) gid=1001(oinstall) 组=1001(oinstall),1002(dba)

链接:为啥要创建oinstall用户组及dba组

理论上oracle单实例需要3种用户组,实际只建两个oinstall和dba,后面再安装oracle数据库的时候把osoper组也设置是dba组。

  • a.oracle 清单组(一般为oinstall):

oinstall 组的成员被视为 Oracle 软件的“所有者”,拥有对 Oracle 中央清单 (oraInventory) 的写入权限。在一个 Linux 系统上首次安装 Oracle 软件时,oui 会创建 /etc/oraInst.loc 文件。该文件指定 Oracle 清单组的名称(默认为 oinstall)以及 Oracle 中央清单目录的路径。

  • b.数据库管理员(osdba,一般为 dba):

osdba 组的成员可通过操作系统身份验证使用 SQL 以 sysdba身份连接到一个 Oracle 实例。该组的成员可执行关键的数据库管理任务,如创建数据库、启动和关闭实例。该组的默认名称为dba。sysdba 系统权限甚至在数据库未打开时也允许访问数据库实例。对此权限的控制完全超出了数据库本身的范围。不要混淆 sysdba系统权限与数据库角色 DBA。DBA 角色不包括 sysdba或 sysoper系统权限。

  • c.数据库操作员组(osoper,一般为 oper):

osoper 组的成员可通过操作系统身份验证使用 SQL 以 sysoper身份连接到一个 Oracle 实例。这个可选组的成员拥有一组有限的数据库管理权限,如管理和运行备份。该组的默认名称为oper。 sysoper系统权限甚至在数据库未打开时也允许访问数据库实例。对此权限的控制完全超出了数据库本身的范围。要使用该组,选择 Advanced 安装类型来安装 Oracle 数据库软件。

3.5 创建oracle数据库软件安装目录、数据文件存放目录以及日志目录

根据自己的情况来定,注意磁盘空间即可,这里我直接把其放到oracle用户家目录下

[root@myhost local]# mkdir /home/oracle/app
[root@myhost local]# mkdir /home/oracle/app/tools
[root@myhost local]# mkdir /home/oracle/app/etc
[root@myhost local]# mkdir /home/oracle/app/oracle
[root@myhost local]# mkdir /home/oracle/app/oraInventory 
[root@myhost local]# mkdir /home/oracle/app/oracle/product
3.6 修改整个目录的权限为oracle:oinstall所有
[root@myhost local]# chown -R oracle:oinstall /home/oracle/app
[root@myhost local]# ll /home/oracle/
总用量 0
drwxr-xr-x 4 oracle oinstall 33 5月  11 14:46 app
3.7 修改操作系统核心参数
3.7.1 修改操作系统的系统标识文件 /etc/redhat-release

链接:为啥要修改操作系统的系统标识文件 /etc/redhat-release
因为Oracle默认不支持CentOS系统安装

[root@myhost ~]# cat /proc/version
Linux version 3.10.0-1127.19.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Aug 25 17:23:54 UTC 2020
[root@myhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 
[root@myhost ~]# vi /etc/redhat-release
[root@myhost ~]# cat /etc/redhat-release
#CentOS Linux release 7.2.1511 (Core) 
redhat-7
3.7.2 修改/etc/security/limits.conf文件
[root@myhost ~]# vi /etc/security/limits.conf
[root@myhost ~]# tail -5 /etc/security/limits.conf
#End of file
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
3.7.3 修改/etc/pam.d/login 文件
[root@myhost ~]# vi /etc/pam.d/login 
[root@myhost ~]# tail -2 /etc/pam.d/login 
session required /lib/security/pam_limits.so
session required pam_limits.so
3.7.4 修改/etc/sysctl.conf文件
[root@myhost ~]# vi /etc/sysctl.conf
[root@myhost ~]#  tail -11 /etc/sysctl.conf
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

#使配置生效
[root@myhost ~]# sysctl -p 
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
3.7.5 修改/etc/profile文件
[root@myhost ~]# vi /etc/profile
if [ $USER = "oracle" ]; then
 
	if [ $SHELL = "/bin/ksh" ]; 
	then
	 
		ulimit -p 16384
		 
		ulimit -n 65536
	 
	else
	 
		ulimit -u 16384 -n 65536
	 
	fi
 
fi

#使配置生效
[root@myhost ~]# source /etc/profile
3.7.6 修改/etc/hosts文件

将本机IP地址和主机名映射起来

[root@myhost ~]# hostname
myhost
[root@myhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.199.41.21  netmask 255.255.255.0  broadcast 10.199.41.255
        inet6 fe80::215:5dff:fe2c:6e04  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:2c:6e:04  txqueuelen 1000  (Ethernet)
        RX packets 20209986  bytes 1860837415 (1.7 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 29198  bytes 2430041 (2.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 5636  bytes 308232 (301.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5636  bytes 308232 (301.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@myhost ~]# hostname 
myhost

[root@myhost ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.199.41.21 myhost


[root@myhost ~]# ping -c 3 myhost
PING myhost (10.199.41.21) 56(84) bytes of data.
64 bytes from myhost (10.199.41.21): icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from myhost (10.199.41.21): icmp_seq=2 ttl=64 time=0.064 ms
^C
--- myhost ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
3.8 切换root用户到oracle登录系统(ssh远程连接工具)
[root@myhost ~]# whoami
root
[root@myhost ~]# su - oracle
[oracle@myhost ~]$ whoami
oracle
[oracle@myhost ~]$ pwd
/home/oracle
[oracle@myhost ~]$ ll
总用量 0
drwxr-xr-x 6 oracle oinstall 60 5月  12 15:05 app
3.9 在oracle用户下,修改 /home/oracle/.bash_profile 文件
export ORACLE_BASE=/home/oracle/app/oracle #oracle数据库安装目录
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/ #oracle数据库路径
export ORACLE_SID=orcl    #oracle启动数据库实例名
export ORACLE_TERM=xterm  #xterm窗口模式安装
export PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin   #添加系统环境变量
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib  #添加系统环境变量
#export LC_ALL=en_US  #防止安装过程出现乱码
#export LANG=en_US  #防止安装过程出现乱码
export LC_ALL=C
export LANG=C
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK   #设置Oracle客户端字符集
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
3.10 下载Oracle数据库安装包

[适用于 Linux x86-64 的Oracle Database 11g 第2版|中国]

在这里插入图片描述
上传安装包到指定目录下:

[root@myhost app]# su - oracle
上一次登录:三 5月 11 16:50:14 CST 2022pts/5 上
[oracle@myhost ~]$ ll
total 0
drwxr-xr-x 5 oracle oinstall 45 May 11 16:56 app
[oracle@myhost ~]$ cd app/
[oracle@myhost app]$ ll
total 0
drwxr-xr-x 3 oracle oinstall 20 May 11 14:46 oracle
drwxrwx--- 5 oracle oinstall 137 5月  11 18:03 oraInventory
drwxr-xr-x 2 oracle oinstall 86 May 11 16:49 tools
[oracle@myhost app]$ cd tools/
[oracle@myhost tools]$ rz -y
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring linux.x64_11gR2_database_2of2.zip...
  100% 1085367 KB    7980 KB/sec    00:02:16       0 Errors   

[oracle@myhost tools]$ rz -y
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring linux.x64_11gR2_database_1of2.zip...
  100% 1210223 KB    10256 KB/sec    00:01:58       0 Errors  

[oracle@myhost tools]$ ll
total 2295592
-rw-r--r-- 1 oracle oinstall 1239269270 May 11 16:45 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 oracle oinstall 1111416131 May 11 16:31 linux.x64_11gR2_database_2of2.zip
3.11 解压安装包
[oracle@myhost tools]$ unzip linux.x64_11gR2_database_1of2.zip 
[oracle@myhost tools]$ unzip linux.x64_11gR2_database_2of2.zip 

##两个安装包都是默认解压到安装包所在目录的database下面##

[oracle@myhost tools]$ ll 
total 2295592
drwxr-xr-x 8 oracle dba             120 Aug 21  2009 database
-rw-r--r-- 1 oracle oinstall 1239269270 May 11 16:45 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 oracle oinstall 1111416131 May 11 16:31 linux.x64_11gR2_database_2of2.zip
[oracle@myhost database]$ pwd
/home/oracle/app/tools/database
[oracle@myhost database]$ ll
total 24
drwxr-xr-x 12 oracle dba 4096 Aug 17  2009 doc
drwxr-xr-x  4 oracle dba 4096 Aug 15  2009 install
drwxrwxr-x  2 oracle dba   58 Aug 15  2009 response
drwxr-xr-x  2 oracle dba   33 Aug 15  2009 rpm
-rwxr-xr-x  1 oracle dba 3226 Aug 15  2009 runInstaller  ##安装脚本#
drwxrwxr-x  2 oracle dba   28 Aug 15  2009 sshsetup
drwxr-xr-x 14 oracle dba 4096 Aug 15  2009 stage
-rw-r--r--  1 oracle dba 5402 Aug 18  2009 welcome.html

4. 正式安装部署Oracle(需要在oracle用户下执行)

4.1 拷贝解压目录下的文件(先过滤掉文件中注释或者空白行内容)
[oracle@myhost tools]$ whoami
oracle
[oracle@myhost tools]$ pwd
/home/oracle/app/tools
[oracle@myhost tools]$ ll
total 2295592
drwxr-xr-x 8 oracle oinstall        120 Aug 21  2009 database
-rw-r--r-- 1 oracle oinstall 1239269270 May 12 15:25 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 oracle oinstall 1111416131 May 12 15:25 linux.x64_11gR2_database_2of2.zip

[oracle@myhost tools]$ cd database/response/
[oracle@myhost response]$ pwd
/home/oracle/app/tools/database/response
[oracle@myhost response]$ ll
total 76
-rw-rw-r-- 1 oracle oinstall 22557 Aug 15  2009 db_install.rsp
-rw-rw-r-- 1 oracle oinstall 44969 Feb 14  2009 dbca.rsp
-rwxrwxr-x 1 oracle oinstall  5740 Feb 26  2009 netca.rsp

[oracle@myhost response]$ egrep -v "^#|^$" /home/oracle/app/tools/database/response/db_install.rsp > /home/oracle/app/etc/db_install.rsp
[oracle@myhost response]$ egrep -v "^#|^$" /home/oracle/app/tools/database/response/dbca.rsp > /home/oracle/app/etc/dbca.rsp
[oracle@myhost response]$ egrep -v "^#|^$" /home/oracle/app/tools/database/response/netca.rsp > /home/oracle/app/etc/netca.rsp
[oracle@myhost response]$ cd  /home/oracle/app/etc/ 
[oracle@myhost etc]$ ll
total 12
-rw-r--r-- 1 oracle oinstall 2402 May 12 15:34 db_install.rsp
-rw-r--r-- 1 oracle oinstall  698 May 12 15:35 dbca.rsp
-rwxr-xr-x 1 oracle oinstall  416 May 12 15:35 netca.rsp
4.2 修改 /home/oracle/app/etc/db_install.rsp 文件

依次修改下面的变量的值:

oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=myhost
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0
ORACLE_BASE=/home/oracle/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true

修改之后:

oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=cfz-21
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0
ORACLE_BASE=/home/oracle/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.customComponents=oracle.server:11.2.0.1.0,oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
oracle.install.db.CLUSTER_NODES=
oracle.install.db.config.starterdb.type=
oracle.install.db.config.starterdb.globalDBName=
oracle.install.db.config.starterdb.SID=
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false
oracle.install.db.config.starterdb.dbcontrol.emailAddress=
oracle.install.db.config.starterdb.dbcontrol.SMTPServer=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
4.3 执行静默安装oracle的命令

提示:安装期间可以开启另外一个窗口使用tail命令监看oracle的安装日志

[oracle@myhost etc]$ cd /home/oracle/app/tools/database/
[oracle@myhost database]$ ll
total 24
drwxr-xr-x 12 oracle oinstall 4096 Aug 17  2009 doc
drwxr-xr-x  4 oracle oinstall 4096 Aug 15  2009 install
drwxrwxr-x  2 oracle oinstall   58 Aug 15  2009 response
drwxr-xr-x  2 oracle oinstall   33 Aug 15  2009 rpm
-rwxr-xr-x  1 oracle oinstall 3226 Aug 15  2009 runInstaller
drwxrwxr-x  2 oracle oinstall   28 Aug 15  2009 sshsetup
drwxr-xr-x 14 oracle oinstall 4096 Aug 15  2009 stage
-rw-r--r--  1 oracle oinstall 5402 Aug 18  2009 welcome.html

[oracle@myhost database]$ ./runInstaller -silent -ignorePrereq -responseFile /home/oracle/app/etc/db_install.rsp 
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 46780 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 3966 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2022-05-12_03-48-15PM. Please wait ...[oracle@myhost database]$ You can find the log of this install session at:
 /home/oracle/app/oraInventory/logs/installActions2022-05-12_03-48-15PM.log   ###安装日志的路径###
 The following configuration scripts need to be executed as the "root" user. 
 #!/bin/sh 
 #Root scripts to run

/home/oracle/app/oraInventory/orainstRoot.sh  ###root账户登录执行此脚本###
/home/oracle/app/oracle/product/11.2.0/root.sh  ###root账户登录执行此脚本###
To execute the configuration scripts:
         1. Open a terminal window 
         2. Log in as "root" 
         3. Run the scripts 
         4. Return to this window and hit "Enter" key to continue 

Successfully Setup Software.   ###等待一段时间,看到这一句就表示安装完成了###

4.4 root账户登录执行配置脚本
[root@myhost ~]# whoami
root
[root@myhost ~]# ll /home/oracle/app/oraInventory/orainstRoot.sh
-rwxrwx--- 1 oracle oinstall 1695 5月  12 15:54 /home/oracle/app/oraInventory/orainstRoot.sh
[root@cfz-21 ~]# ll /home/oracle/app/oracle/product/11.2.0/root.sh 
-rwxr-x--- 1 oracle oinstall 512 5月  12 15:50 /home/oracle/app/oracle/product/11.2.0/root.sh

[root@cfz-21 ~]# sh  /home/oracle/app/oraInventory/orainstRoot.sh
Changing permissions of /home/oracle/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /home/oracle/app/oraInventory to oinstall.
The execution of the script is complete.


[root@cfz-21 ~]# sh /home/oracle/app/oracle/product/11.2.0/root.sh
Check /home/oracle/app/oracle/product/11.2.0/install/root_cfz-21_2022-05-12_15-58-27.log for the output of root script
[root@cfz-21 ~]# cat /home/oracle/app/oracle/product/11.2.0/install/root_cfz-21_2022-05-12_15-58-27.log

Running Oracle 11g root.sh script...

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /home/oracle/app/oracle/product/11.2.0

Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
Finished product-specific root actions.

[oracle@cfz-21 database]$ cd /home/oracle/
4.5 再通过oracle命令静默配置监听
[oracle@myhost database]$ whoami
oracle
[oracle@myhost database]$ cd /home/oracle/
[oracle@myhost ~]$ 
[oracle@myhost ~]$ 
[oracle@myhost ~]$ whoami          
oracle
[oracle@myhost ~]$ pwd
/home/oracle
[oracle@myhost ~]$ which netca 
~/app/oracle/product/11.2.0/bin/netca

[oracle@myhost ~]$ /home/oracle/app/oracle/product/11.2.0/bin/netca /silent /responsefile  /home/oracle/app/etc/netca.rsp 

Parsing command line arguments:
    Parameter "silent" = true
    Parameter "responsefile" = /home/oracle/app/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
    Running Listener Control: 
      /home/oracle/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
4.6 查看监听端口
[oracle@myhost ~]$ netstat -tnulp | grep 1521
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::1521                 :::*                    LISTEN      4908/tnslsnr    
4.7 静默创建数据库
4.7.1 修改 /home/oracle/app/etc/dbca.rsp 文件

提示:TOTALMEMORY 设置为总内存的80%。

[oracle@myhost ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:           3770         207        1369           7        2193        3314
Swap:          3967           2        3965

## 3770*0.8=3016


[oracle@myhost ~]$ vi /home/oracle/app/etc/dbca.rsp 

## 修改以下变量的值:
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/home/oracle/app/oraInventory
RECOVERYAREADESTINATION=/home/oracle/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "3016"

修改后文件内容:

[oracle@myhost ~]$  cat  /home/oracle/app/etc/dbca.rsp 
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/home/oracle/app/oraInventory
RECOVERYAREADESTINATION=/home/oracle/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "3016"
TEMPLATENAME = "General_Purpose.dbc"
[createTemplateFromDB]
SOURCEDB = "myhost:1521:orcl"
SYSDBAUSERNAME = "system"
TEMPLATENAME = "My Copy TEMPLATE"
[createCloneTemplate]
SOURCEDB = "orcl"
TEMPLATENAME = "My Clone TEMPLATE"
[DELETEDATABASE]
SOURCEDB = "orcl"
[generateScripts]
TEMPLATENAME = "New Database"
GDBNAME = "orcl11.us.oracle.com"
[CONFIGUREDATABASE]
[ADDINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
NODELIST=
SYSDBAUSERNAME = "sys"
[DELETEINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
INSTANCENAME = "orcl11g"
SYSDBAUSERNAME = "sys"
4.7.2 执行静默建库的命令
[oracle@myhost ~]$ whoami
oracle
[oracle@myhost ~]$ which dbca
~/app/oracle/product/11.2.0/bin/dbca
[oracle@myhost ~]$ pwd
/home/oracle
[oracle@myhost ~]$ /home/oracle/app/oracle/product/11.2.0/bin/dbca -silent -responseFile /home/oracle/app/etc/dbca.rsp 

Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/home/oracle/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
4.8 查看oracle实例进程
[oracle@myhost ~]$ ps -ef | grep ora_ | grep -v grep
oracle     5376      1  0 16:23 ?        00:00:00 ora_pmon_orcl
oracle     5378      1  0 16:23 ?        00:00:00 ora_vktm_orcl
oracle     5382      1  0 16:23 ?        00:00:00 ora_gen0_orcl
oracle     5384      1  0 16:23 ?        00:00:00 ora_diag_orcl
oracle     5386      1  0 16:23 ?        00:00:00 ora_dbrm_orcl
oracle     5388      1  0 16:23 ?        00:00:00 ora_psp0_orcl
oracle     5390      1  0 16:23 ?        00:00:00 ora_dia0_orcl
oracle     5392      1  0 16:23 ?        00:00:00 ora_mman_orcl
oracle     5394      1  0 16:23 ?        00:00:00 ora_dbw0_orcl
oracle     5396      1  0 16:23 ?        00:00:00 ora_lgwr_orcl
oracle     5398      1  0 16:23 ?        00:00:00 ora_ckpt_orcl
oracle     5400      1  0 16:23 ?        00:00:00 ora_smon_orcl
oracle     5402      1  0 16:23 ?        00:00:00 ora_reco_orcl
oracle     5404      1  0 16:23 ?        00:00:00 ora_mmon_orcl
oracle     5406      1  0 16:23 ?        00:00:00 ora_mmnl_orcl
oracle     5408      1  0 16:23 ?        00:00:00 ora_d000_orcl
oracle     5410      1  0 16:23 ?        00:00:00 ora_s000_orcl
oracle     5420      1  0 16:23 ?        00:00:00 ora_qmnc_orcl
oracle     5435      1  0 16:23 ?        00:00:00 ora_cjq0_orcl
oracle     5437      1  0 16:24 ?        00:00:00 ora_q000_orcl
oracle     5439      1  0 16:24 ?        00:00:00 ora_q001_orcl
4.9 查看监听状态
[oracle@myhost ~]$ whoami
oracle
[oracle@myhost ~]$ which lsnrctl
~/app/oracle/product/11.2.0/bin/lsnrctl
[oracle@myhost ~]$ pwd
/home/oracle
[oracle@myhost ~]$ /home/oracle/app/oracle/product/11.2.0/bin/lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 12-MAY-2022 16:26:19

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                12-MAY-2022 16:07:37
Uptime                    0 days 0 hr. 18 min. 42 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/myhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=myhost)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
4.10 安装sqlplus客户端连接工具(root账户登录安装)

参考之前的文章: 如何在Linux上安装Oracle客户端连接工具sqlplus

4.11 切换为oracle用户,sqlplus登录oracle数据库

[oracle@myhost ~]$ whoami
oracle
[oracle@myhost ~]$ sqlplus sys/oracle@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu May 12 16:49:51 2022

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options

SQL> 
4.11.1 查看实例状态
SQL> select status from v$instance;

STATUS
------------------------
OPEN
4.11.2 查看数据库编码
SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8
4.11.3 查看数据库版本信息
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
4.11.4 激活scott用户
 //若遇到su - oracle用户下无法解锁该用户,请用远程连接工具通过system用户进行解锁,这里不影响
SQL> alter user scott account unlock;

User altered.

//若遇到su - oracle用户下无法修改密码,请用远程连接工具通过system用户进行修改,这里不影响
SQL> alter user scott identified by tiger; 

User altered.

//查看所有用户
SQL> select username from all_users;

USERNAME
------------------------------------------------------------
SCOTT
OWBSYS_AUDIT
OWBSYS
APEX_030200
APEX_PUBLIC_USER
FLOWS_FILES
MGMT_VIEW
SYSMAN
SPATIAL_CSW_ADMIN_USR
SPATIAL_WFS_ADMIN_USR
MDDATA

USERNAME
------------------------------------------------------------
MDSYS
SI_INFORMTN_SCHEMA
ORDPLUGINS
ORDDATA
ORDSYS
OLAPSYS
ANONYMOUS
XDB
CTXSYS
EXFSYS
XS$NULL

USERNAME
------------------------------------------------------------
WMSYS
APPQOSSYS
DBSNMP
ORACLE_OCM
DIP
OUTLN
SYSTEM
SYS

30 rows selected.

5. Navicat远程连接Oracle数据库

5.1 确保Oracle数据库服务器上防火墙开放了1521端口
[root@myhost ~]# firewall-cmd --zone=public --add-port=1521/tcp --permanent
success
[root@myhost ~]# firewall-cmd --reload
success
[root@myhost ~]# firewall-cmd --list-ports
1521/tcp 1124/tcp
5.2 下载安装 oracle instantclient

想要远程连接oracle,本地不安装oracle的话是不行的,但是我们可以安装一个oracle instantclient,然后配置navicat就ok了。

链接:instantclient-basic-windows.x64-11.2.0.4.0.zip下载地址

下载解压instantclient-basic-windows.x64-11.2.0.4.0.zip,记住安装的目录。

5.3 在Navicat中配置oci.dll

打开navicat之后,选择工具–选项–环境–oci环境,将oci环境 选择为刚刚安装client目录中的oci.dll,我这里是:E:\Program Files (x86)\instantclient_11_2\oci.dll,然后就可以新建一个oracle的连接,输入用户名,密码,还有数据库名称等进行远程连接oracle数据库了。

5.4 连接测试

提示:IP为Oracle服务器的IP地址,服务名为Oracle的实例名,可忽略大小写

[oracle@myhost ~]$ sqlplus sys/oracle@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu May 12 17:08:37 2022

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options

SQL> select instance_name from v$instance;

INSTANCE_NAME
--------------------------------
orcl

我这里用刚激活的用户scott,密码为tiger,填完以上信息后点击连接测试
在这里插入图片描述

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值