CentOS 静默安装Oracle
Oracle 数据库安装:
- 安装前依赖验证:
rpm -q \
binutils\
compat-libstdc++-33 \
elfutils-libelf \
elfutils-libelf-devel \
expat\
gcc\
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel\
make \
pdksh \
sysstat \
unixODBC \
unixODBC-devel | grep "not installed"
pdksh 在本系统中安装了ksh,可替代pdksh
2、创建运行Oracle数据库的系统用户和用户组
创建用户:
[root@moke-1 ~]# groupadd oinstall
[root@moke-1 ~]# groupadd dba
[root@moke-1 ~]# user
useradd userdel userhelper usermod usernetctl users
[root@moke-1 ~]# useradd -g oinstall -g dba -m oracle
[root@moke-1 ~]# passwd oracle
设置密码
[root@moke-1 ~]# id oracle
uid=1000(oracle) gid=1001(dba) 组=1001(dba)
[root@moke-1 ~]# su oracle
[oracle@moke-1 root]$
user =oracle
passwd=111@1222
创建Oracle数据库安装目录
[root@moke-1 /]# mkdir -p /data/oracle#安装目录
[root@moke-1 /]# mkdir -p /data/oraInventory #数据库配置文件
[root@moke-1 /]# mkdir -p /data/database#数据库软件包解压目录
[root@moke-1 /]# cd /data/
[root@moke-1 data]# ls
database oracle oraInventory
[root@moke-1 data]# chown -R oracle:oinstall /data/oracle
[root@moke-1 data]# chown -R oracle:oinstall /data/oraInventory
[root@moke-1 data]# chown -R oracle:oinstall /data/database
[root@moke-1 data]# ls
database oracle oraInventory
[root@moke-1 data]# ll -l
总用量 12
drwxr-xr-x 2 oracle oinstall 4096 6月 22 15:18 database
drwxr-xr-x 2 oracle oinstall 4096 6月 22 15:17 oracle
drwxr-xr-x 2 oracle oinstall 4096 6月 22 15:18 oraInventory
[root@moke-1 data]# chmod -R 775 /data
[root@moke-1 data]# ll -l
总用量 12
drwxrwxr-x 2 oracle oinstall 4096 6月 22 15:18 database
drwxrwxr-x 2 oracle oinstall 4096 6月 22 15:17 oracle
drwxrwxr-x 2 oracle oinstall 4096 6月 22 15:18 oraInventory
3、修改OS系统标识
Oracle默认不支持CentOS系统安装,修改文件/etc/Redhat-release
[root@moke-1 home]# cat /proc/version
Linux version 3.10.0-327.28.3.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Aug 18 19:05:49 UTC 2016
[root@moke-1 home]#[root@moke-1 home]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@moke-1 home]#
[root@moke-1 home]# vim /etc/redhat-release
redhat-7
~
[root@moke-1 home]# cat /etc/redhat-release
redhat-7
[root@moke-1 home]#
4、关闭防火墙
5、关闭selinux(重启生效)
[root@moke-1 home]# vim /etc/selinux/config# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled #表示已关闭
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
6、修改内核参数
[root@moke-1 ~]# vim /etc/sysctl.conf# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.conf.all.accept_redirects=0#oracle database install confignet.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1fs.file-max = 6815744 #设置最大打开文件数
fs.aio-max-nr = 1048576kernel.shmall = 2097152 #共享内存的总量
kernel.shmmax = 2147483648 #最大共享内存的段大小
kernel.shmmni = 4096 #整个系统共享内存端的最大数
kernel.sem = 250 32000 100 128net.ipv4.ip_local_port_range = 9000 65500 #可使用的IPV4端口范围net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmen_max = 1048576
//使生效 sysctl -p
7、对oracle用户设置限制,提高软件运行性能(结尾增加)
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
8、配置用户环境变量
[root@moke-1 database]# vim /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functionscd /da
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi# User specific environment and startup programsPATH=$PATH:$HOME/.local/bin:$HOME/binexport PATH# oracle database profile
export ORACLE_BASE=/data/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/libexport LC_ALL=en_US
export LANG=en_US
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
环境变量开机生效
vim /etc/bashrc
# oracle profile
source /home/oracle/.bash_profile
#
source /etc/profile
9、解压安装包:
unzip linux.x64_11gR2_database_1of2.zip -d /data/database/ #解压文件1
unzip linux.x64_11gR2_database_2of2.zip -d /data/database/ #解压文件2
chown -R oracle:oinstall /data/database/database/ #分配安装文件授权Oracle
10、编辑Oracle数据库安装应答文件
vim /data/database/database/response/db_install.rsp
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=sidOracle11GR2
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=512
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=111222@qaz
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/data/oracle/oradata
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/data/oracle/fast_recovery_area
DECLINE_SECURITY_UPDATES=true
11、执行安装(进入/data/database/database/)
[oracle@moke-1 ~]$ ./runInstaller -ignorePrereq -silent -force -responseFile /data/database/database/response/db_install.rsp
12、已root用户执行脚本
cd /data/oracle/product/11.2.0/db_1/
ls
./root.sh
13、配置静默监听
[oracle@moke-1 bin]$ netca /silent /responsefile /data/database/database/response/netca.rsp
bash: netca: command not found
[oracle@moke-1 bin]$ echo $ORACLE_BASE[oracle@moke-1 bin]$ cd ~
[oracle@moke-1 ~]$ vim .bash_profile
[oracle@moke-1 ~]$ source .bash_profile
[oracle@moke-1 ~]$ echo $ORACLE_BASE
/data/oracle
[oracle@moke-1 ~]$ echo $ORACLE_HOME
/data/oracle/product/11.2.0/db_1
[oracle@moke-1 ~]$ netca /silent /responsefile /data/database/database/response/netca.rspParsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /data/database/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/data/oracle/product/11.2.0/db_1/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
14、 查看监听端口
[oracle@moke-1 oradata]$ 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 12285/tnslsnr 15、静默创建数据库
[root@moke-1 response]# vim dbca.rsp
GDBNAME = "qhzncs"
SID = "orcl"
SYSPASSWORD = "4900@qaz"
CHARACTERSET = "ZHS16GBK"
//执行静默建库
[oracle@moke-1 response]$ dbca -silent -responseFile /data/database/database/response/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
57% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
74% complete
85% complete
96% complete
100% complete
Look at the log file "/data/oracle/cfgtoollogs/dbca/qhzncs/qhzncs.log" for further details.//查看oracle实例进程
[oracle@moke-1 response]$ ps -ef | grep ora_ | grep -v grep
//查看监听状态
[oracle@moke-1 admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 08-JUL-2018 17:17:37Copyright (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 05-JUL-2018 11:26:13
Uptime 3 days 5 hr. 51 min. 26 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /data/oracle/diag/tnslsnr/moke-1/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=moke-1.novalocal)(PORT=1521)))
Services Summary...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "qhzncs" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully//登录sqlplus,查看实例状态
sqlplus / as sysdbaselect status from v$instance;//查看数据库编码
select userenv('language') from dual;
//查看数据库版本信息
select * from v$version;
//激活scott用户
alter user scott account unlock;alter user scott identified by tiger;select username,account_status from all_users;
select username,status from all_users;
sqlplus scott/tiger@QHZNCS
sqlplus scott/tiger@192.168.1.16:1521/QHZNCS
Oracle客户端安装
[root@moke-2 home]# yum install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
[root@moke-2 lib]# pwd
/usr/lib/oracle/11.2/client64/lib
mkdir -p /usr/lib/oracle/11.2/client64/lib/network/admin
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib:$LD_LIBRARY_PATH
export ORACLE_HOME=/usr/lib/oracle/11.2
export TNS_ADMIN=/usr/lib/oracle/11.2/client64/lib/network/admin
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
sqlplus scott/4900@qaz@192.168.1.16:1521/qhzncs as sysdba
export PATH=/usr/lib/oracle/11.2/client64/bin:$PATH
1 # .bash_profile
2
3 # Get the aliases and functions
4 if [ -f ~/.bashrc ]; then
5 . ~/.bashrc
6 fi
7
8 # User specific environment and startup programs
9
10 PATH=$PATH:$HOME/.local/bin:$HOME/bin
11
12 export PATH
13
14 # oracle database profile
15 export ORACLE_HOSTNAME=moke-1.novalocal
16 export ORACLE_BASE=/data/oracle
17 export ORACLE_HOME=/data/oracle/product/11.2.0/db_1
18 export ORACLE_SID=orcl
19 export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
20 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
21
22 export LC_ALL=en_US
23 export LANG=en_US
24 export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
数据库命令
记录一下,备查:1.查看所有用户:select * from dba_users;select * from all_users;select * from user_users;2.查看用户或角色系统权限(直接赋值给用户或角色的系统权限):select * from dba_sys_privs;select * from user_sys_privs;3.查看角色(只能查看登陆用户拥有的角色)所包含的权限sql>select * from role_sys_privs;4.查看用户对象权限:select * from dba_tab_privs;select * from all_tab_privs;select * from user_tab_privs;5.查看所有角色:select * from dba_roles;6.查看用户或角色所拥有的角色:select * from dba_role_privs;select * from user_role_privs;7.查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)select * from V$PWFILE_USERS比如我要查看用户 wzsb的拥有的权限:SQL> select * from dba_sys_privs where grantee='WZSB';GRANTEE PRIVILEGE ADMIN_OPTION------------------------------ ---------------------------------------- ------------WZSB CREATE TRIGGER NOWZSB UNLIMITED TABLESPACE NO比如我要查看用户 wzsb的拥有的角色:SQL> select * from dba_role_privs where grantee='WZSB';GRANTEE GRANTED_ROLE ADMIN_OPTION DEFAULT_ROLE------------------------------ ------------------------------ ------------ ------------WZSB DBA NO YES查看一个用户所有的权限及角色select privilege from dba_sys_privs where grantee='WZSB'unionselect privilege from dba_sys_privs where grantee in (select granted_role from dba_role_privs where grantee='WZSB' );
sqlplus64 scott/tiger@192.168.1.16:1521/QHZNCS
sqlplus PARA_USER/un1ware$WPM@192.168.1.16:1521/QHZNCS
sys/manager as sysdba; sqlplus64 / as sysdba@192.168.1.16:1521/QHZNCSalter system set sec_case_sensitive_logon=false;<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />sqlplus64 sys/tiger@192.168.1.16:1522/QHZNCSgrant connect,resource to PARA_USER;select username from all_users;sqlplus scott/tigersqlplus PARA_USER/un1ware$WPM@192.168.1.16:1521/QHZNCSconn PARA_USER/un1ware$WPM//激活scott用户alter user PARA_USER account unlock;commit;alter user PARA_USER identified by un1ware$WPM;sqlplus PARA_USER/Orcl123456@192.168.1.16:1521/QHZNCSalter system set sec_case_sensitive_logon=false;grant all on *.* to PARA_USER@'%' identified by 'un1ware$WPM';grant all on *.* to PARA_USER@'%' identified by 'un1ware$WPM';grant connect, resource to PARA_USER;GRANT CONNECT TO PARA_USER;ALTER USER PARA_USER DEFAULT ROLE NONE;
SQLLDR命令配置
// 从Oracle数据库服务端拷贝,文件来源于oracle完全安装版本里面的件。
[root@moke-1 rdbms]# pwd
/data1/db_ora/oracle/product/11.2.0/db_1/rdbms
[root@moke-1 mesg]# pwd
/data1/db_ora/oracle/product/11.2.0/db_1/network/mesg
#准备文件(数据库服务器操作)
scp -r rdbms root@192.168.1.15:/usr/lib/oracle/11.2/client64/lib/network
scp -r mesg root@192.168.1.15:/usr/lib/oracle/11.2/client64/lib/network
scp sqlldr root@192.168.1.15:/usr/lib/oracle/11.2/client64/lib/network
#文件导入(客户端服务器操作)
将rdbms文件导入到/usr/lib/oracle/11.2/client64
mesg文件夹导入到/usr/lib/oracle/11.2/client64/network
sqlldr 文件导入到/usr/lib/oracle/11.2/client64/bin
scp sqlldr /usr/lib/oracle/11.2/client64/bin
scp -r rdbms /usr/lib/oracle/11.2/client64
SQLLDR测试命令
sqlldr
错误处理:
[FATAL] [INS-32037] The operating system group specified for central inventory (oraInventory) ownership is invalid.
处理方法:root用户
vim /etc/oraInst.loc
inventory_loc=/mnt/sdb1/oraInventory
inst_group=oinstall
- 报错“[INS-08109]
报错“[INS-08109] Unexpected error occurred while validating inputs at state 'inventoryPage‘”
处理方法:
vim /mnt/sdb1/database/response/db_install.rsp
INVENTORY_LOCATION=/mnt/sdb1/oraInventory
- [INS-35341] User is not a member of the following chosen OS groups
usermod -g oinstall -G dba oracle
- 静默监听
netca /silent /responsefile /mnt/sdb1/database/response/netca.rsp
UnsatisfiedLinkError exception loading native library: njni11
java.lang.UnsatisfiedLinkError: /mnt/sdb1/oracle/product/11.2.0/db_1/lib/libnjni11.so: /mnt/sdb1/oracle/product/11.2.0/db_1/lib/libclntsh.so.11.1: undefined symbol: nnfyboot
解决方案:
cd $ORACLE_HOME/inventory/Scripts/ext/lib/
cp libclntsh.so.11.1 $ORACLE_HOME/lib/