荆轲刺秦王
1. 准备工作 需要下载 Oracle 11g 安装包
2.HostName修改:
hostnamectl set-hostname oracle
3. 配置hostname(本机IP映射)注意:192.168.116.129 需要换乘本地ip
vi /etc/hosts
192.168.116.129 oracle
# 测试hostname
ping -c 3 oracle
4. 切换国内 yum 源:
rm -rf /etc/yum.repos.d/*.repo #删除repo文件,或者自己备份
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache #更新缓存
5. yum 安装 unzip 软件,用来解压上传的Oracle安装文件
yum install unzip -y
6. yum 安装 vim,方便文件编辑
yum install vim -y
7. 安装依赖包 注意 不要有换行
yum -y install 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
8. 检查依赖是否安装完整性
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"
9. 关闭 selinux
vim /etc/selinux/config
设置 SELINUX=disabled
10. 刷新 selinux
setenforce 0
11. 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
12. 修改内核参数配置文件,优化OS内核参数
vim /etc/sysctl.conf
shmall、shmmax参数要根据实际内存数进行调整,不然安装会有问题,静态安装很容易忽略kernel.shmmax为最大物理内存以2G为例kernel.shmmax=2*0.72=1.44G , 1*1024*1024*1024=1073741824byte , kernel.shmall=shmmax/4K = 268435456
在最后添加以下代码 :
fs.aio-max-nr = 1048576
fs.file-max = 6815744
# shmall、shmmax参数要根据实际内存数进行调整,不然安装会有问题,静态安装很容易忽略
# 图形化安装在检测是将会提示
# 官网建议:
kernel.shmall = 268435456
# 官网建议:以字节为单位的物理内存(RAM)大小的一半,例如物理内存为8G
kernel.shmmax = 1073741824
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
修改完后执行使参数生效。
sysctl -p
13. 增加用户和组
groupadd oinstall
groupadd dba
groupadd asmadmin
groupadd asmdba
useradd -g oinstall -G dba,asmdba oracle -d /home/oracle
添加完成后 ,查看oracle用户
id oracle
初始化oracle用户的密码
passwd oracle
14. 修改 limits.conf 限制
vi /etc/security/limits.conf
在末尾添加以下代码:
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240
修改 /etc/pam.d/login
vi /etc/pam.d/login
末尾加上:
session required /lib64/security/pam_limits.so
session required pam_limits.so
修改 /etc/profile
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
使之生效:
source /etc/profile
15. 安装 oracle
创建目录
mkdir -p /db/app/oracle/product/11.2.0
mkdir /db/app/oracle/oradata
mkdir /db/app/oracle/oraInventory
mkdir /db/app/oracle/fast_recovery_area
chown -R oracle:oinstall /db/app/oracle
chmod -R 775 /db/app/oracle
创建 vi /etc/oraInst.loc :
inventory_loc=/db/app/oracle/oraInventory
inst_group=oinstall
修改权限:
chown oracle:oinstall /etc/oraInst.loc
chmod 664 /etc/oraInst.loc
配置 liunx 的 oracle 用户 环境变量 注意:需要切换用户
oracle用户登陆
su - oracle
vi .bash_profile
#ORACLE_HOSTNAME为主机名
export ORACLE_HOSTNAME=oracle
export ORACLE_BASE=/db/app/oracle
export ORACLE_SID=ORCL
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
以上配置完成后,建议重启系统 或分别执行以下命令:
source /home/oracle/.bash_profile
env
解压oracle压缩文件到 /db
Oracle11g 11.2.0.4 各个压缩包备注说明
安装单点的,就1和2一起解压,解压完叫database目录;
安装集群的,就先搞3,装完grid包后,再搞1和2;
1和2是数据库软件;
3是rac软件;
4是client客户端;
5是gateways;
6是example示例;
7是删除介质;
本次选择单点安装,解压:
unzip p13390677_112040_Linux-x86-64_1of7.zip && unzip p13390677_112040_Linux-x86-64_2of7.zip
注意:此刻我是在 oracle 用户目录下解压的 也就是: /home/oracle 目录下
解压完成后,登录Root,复制授权 (注意:这里根据自己目录 酌情变化)
su - root
mkdir /home/oracle/etc/
cp /home/oracle/database/response/* /home/oracle/etc/
chmod 777 /home/oracle/etc/*.rsp
# 登录oracle用户:
su – oracle
vi /home/oracle/etc/db_install.rsp
## 信息如下:
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/db/app/oracle/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracle
ORACLE_HOME=/db/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/db/app/oracle
oracle.install.db.InstallEdition=EE
#oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.memoryLimit=512
oracle.install.db.config.starterdb.password.ALL=oracle
DECLINE_SECURITY_UPDATES=true
16. 开始安装:
切换到 oracle 如果已经是 oracle 则不用切换:
su - oracle
cd /home/oracle/database/
./runInstaller -silent -force -responseFile /home/oracle/etc/db_install.rsp -ignorePrereq
如果想查看安装日志,就可以新打开一个窗口,执行:
tail -f /db/app/oracle/oraInventory/logs/silentInstall2024-06-17_04-42-10PM.log
注意:这个日志地址 因人而异 需要根据自己的安装提示 找到对应目录。
注意看提示内容: As a root user, execute the following script(s):
这句话意思就是说: 以 root 用户身份执行 下面这个脚本文件.
所以 新开一个 root 用户窗口,执行:
/db/app/oracle/product/11.2.0/db_1/root.sh
老样子根据提示即可看到安装日志。
17. 增加或修改oracle的环境变量:
su - oracle
vi ~/.bash_profile
export ORACLE_HOME=/db/app/oracle/product/11.2.0/db_1
export TNS_ADMIN=$ORACLE_HOME/network/admin
export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin
export PATH=${PATH}:/usr/bin:/bin:/usr/local/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export LIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
export ORACLE_OWNER=oracle
export SPFILE_PATH=$ORACLE_HOME/dbs
export ORA_NLS10=$ORACLE_HOME/nls/data
##使其生效
source ~/.bash_profile
18. 配置监听程序
cd /db/app/oracle/product/11.2.0/db_1/bin
./netca /silent /responseFile /home/oracle/etc/netca.rsp
[oracle@oracle bin]$ ./netca /silent /responseFile /home/oracle/etc/netca.rsp
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /home/oracle/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/db/app/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
启动监听: cd /db/app/oracle/product/11.2.0/db_1/bin/
lsnrctl status ###查看监听状态
[oracle@oracle bin]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 16-JAN-2021 22:32:49
Copyright (c) 1991, 2013, Oracle. All rights reserved.
TNS-01106: Listener using listener name LISTENER has already been started
[oracle@oracle bin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 16-JAN-2021 22:33:02
Copyright (c) 1991, 2013, 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.4.0 - Production
Start Date 16-JAN-2021 22:28:45
Uptime 0 days 0 hr. 4 min. 17 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /db/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /db/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
The listener supports no services
The command completed successfully
[oracle@oracle bin]$
静默dbca建库
编辑应答文件:
注意: GDBNAME 有两处
SYSPASSWORD,SYSTEMPASSWORD,CHARACTERSET,NATIONALCHARACTERSET等需要将注释 # 号 去掉。
[oracle@oracle etc]$ vim /home/oracle/etc/dbca.rsp
GDBNAME="orcl.oracle"
SID="orcl"
SYSPASSWORD="oracle"
SYSTEMPASSWORD="oracle"
CHARACTERSET="AL32UTF8"
NATIONALCHARACTERSET="UTF8"
然后执行:
$ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/etc/dbca.rsp
建库:
[oracle@oracle bin]$ cd /db/app/oracle/product/11.2.0/db_1/bin
[oracle@oracle bin]$ dbca -silent -responseFile /home/oracle/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 "/db/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
至此完成数据库实例的创建。
注意:如需删除实例:执行:
[oracle@oracle ~]$ dbca -silent -deleteDatabase -sourcedb orcl
19. 设置 oracle 开机启动
root 用户编辑 /etc/oratab
orcl:/db/app/oracle/product/11.2.0/db_1:N
修改为 orcl:/db/app/oracle/product/11.2.0/db_1:Y
注:参数为Y时可通过dbstart启动数据库
root 用户编辑 vim /etc/rc.d/rc.local
添加以下内容:
su oracle -lc "/db/app/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc "/db/app/oracle/product/11.2.0/db_1/bin/dbstart"
oracle 用户 编辑dbstart :
进入 $ORACLE_HOME/bin
将 ORACLE_HOME_LISTNER=$1 修改为 ORACLE_HOME_LISTNER=$ORACLE_HOME
分别打开两个文件找到:ORACLE_HOME_LISTNER=$1,修改为
ORACLE_HOME_LISTNER=$ORACLE_HOME,命令如下:
[oracle@oracle11g ~]$ vi $ORACLE_HOME/bin/dbstart
[oracle@oracle11g ~]$ vi $ORACLE_HOME/bin/dbshut
临时启动实例:
[oracle@oracle bin]$ pwd
/db/app/oracle/product/11.2.0/db_1/bin
# 通过dbstart 启动此实例,监听器
## ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
## Usage: ./dbstart ORACLE_HOME
[oracle@oracle bin]$ ./dbstart $ORACLE_HOME;
# oracle的进程关闭,监听器也停止;
[oracle@oracle bin]$ ./dbshut $ORACLE_HOME;
# 启动监听
[oracle@oracle bin]$ ./lsnrctl start;
# 查看监听
[oracle@oracle bin]$ ./lsnrctl status;
登录Oracle:
[oracle@oracle bin]$ pwd
/db/app/oracle/product/11.2.0/db_1/bin
[oracle@oracle bin]$ ./sqlplus /nolog
# 进入系统管理用户
SQL> conn / as sysdba
Connected to an idle instance.
# 启动oracle实例
SQL> startup;
# 启动成功
[oracle@oracle ~]$ su - oracle
Password:
Last login: Tue Jan 19 10:04:44 CST 2021 on pts/0
Last failed login: Tue Jan 19 10:05:49 CST 2021 on pts/0
There was 1 failed login attempt since the last successful login.
[oracle@oracle ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Tue Jan 19 10:06:12 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 764121088 bytes
Fixed Size 2257152 bytes
Variable Size 499126016 bytes
Database Buffers 255852544 bytes
Redo Buffers 6885376 bytes
Database mounted.
Database opened.
SQL>
20. 安装过程中出现的问题
执行 startup 时出现:
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/db/app/oracle/product/11.2.0/db_1/dbs/initORCL.ora'
切换为 root 用户,将 /db/app/oracle/admin/orcl/pfile 目录下的 init.ora…xxx 拷贝到/db/app/oracle/product/11.2.0/db_1/dbs下,并重新命名为 initORCL.ora。
2. 出现pl/sql 连接不上数据库
需要配置 /db/app/oracle/product/11.2.0/db_1/network/admin 中 listener.ora 文件,完整配置如下:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = /db/app/oracle/product/11.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ORCL)
(ORACLE_HOME = /db/app/oracle/product/11.2.0/db_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /db/app/oracle