文章目录
- 环境安装文件准备
- 添加用户
- 操作系统环境配置
- 解压
- 安装
- 问题解决
- 创建用户远程连接
为了熟悉rman备份操作,参照大神的博客在centos中安装了一套oracle11g,将安装步骤记录如下
环境安装文件准备
这里准备一台centos7.8 虚拟机 配置ip 192.168.18.100 主机名:oracle100
下载oralce linux 安装包(需要网盘地址请留言) 包含两个部分,下载完成后上传到 centos 虚拟机中备用。
添加用户
groupadd oinstall
groupadd dba
groupadd asmadmin
groupadd asmdba
useradd -g oinstall -G dba,asmdba oracle -d /home/oracle
操作系统环境配置
安装 pdksh
wget http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm
rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm
安装环境依赖
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
检验依赖是否安装完整
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"
内核配置优化
vi /etc/sysctl.conf
fs.aio-max-nr=1048576
fs.file-max=6815744
kernel.shmall=2097152
kernel.shmmni=4096
kernel.shmmax = 2147483648
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
kernel.shmmax为内存的一半,比如内存为4G,则kernel.shmmax=210241024*1024=2147483648
使配置生效
sysctl -p
配置oracle用户权限
vi /etc/security/limits.conf
增加如下内容
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
vi /etc/pam.d/login
增加如下内容
session required /lib64/security/pam_limits.so
session required pam_limits.so
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
创建目录
创建 oracle 的安装备份目录,注意如果是root用户创建的 最后要修改 目录所有者为oracle:oinstall,否则安装时提示没有权限或找不到文件
mkdir -p /db/app/oracle/product/11
mkdir /db/app/oracle/oradata
mkdir /db/app/oracle/inventory
mkdir /db/app/oracle/fast_recovery_area
chown -R oracle:oinstall /db/app/oracle
chmod -R 775 /db/app/oracle
mkdir -p /u01/app/oracle/inventory
chown -R oracle:oinstall /u01/app/oracle/inventory
配置oralce用户环境变量
切换到 oracle 用户
su oracle
用户目录下 编辑文件.bash_profile 增加如下内容
vi .bash_profile
注意目录信息等 配置 要结合自己的实际
umask 022
export ORACLE_HOSTNAME=oracle100
export ORACLE_BASE=/db/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11/
export ORACLE_SID=ORCL
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
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"
编辑 home/oracle/.bashrc 也增加上述内容
解压
解压安装包,分别解压两个部分的压缩包,最终会解压到一个 database 目录。复制这个目录到 /db 目录如下,更改目录所有者为
total 0
drwxr-xr-x 3 oracle oinstall 20 Jun 9 03:06 app
drwxr-xr-x 8 oracle oinstall 128 Aug 21 2009 database
drwxr-xr-x 2 oracle oinstall 61 Jun 9 04:00 etc
[oracle@oracle100 db]$ pwd
/db
chown -R oracle:oinstall /db/app
chown -R oracle:oinstall /db/database
chown -R oracle:oinstall /db/etc
创建 /db/etc 目录 并 复制 /db/database/response/ 下的文件到 /db/etc
mkdir /db/etc/
cp /db/database/response/* /db/etc/
编辑 /db/etc/db_install.rsp 增加如下内容
vi /db/etc/db_install.rsp
#-----------------add-----------------
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracle100
ORACLE_HOME=/db/app/oracle/product/11
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=dba
安装
执行安装程序
使用oralce 用户,执行 /db/etc/db_install.rsp 安装oracle,如果提示文件没有权限那么通过chmod 为文件增加 执行权限
[oracle@oracle100 database]$ ./runInstaller -silent -ignorePrereq -responseFile /db/etc/db_install.rsp
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB. Actual 6827 MB Passed
Checking swap space: must be greater than 150 MB. Actual 2047 MB Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2021-06-09_03-49-04AM. Please wait ...[oracle@oracle100 database]$ You can find the log of this install session at:
/u01/app/oracle/inventory/logs/installActions2021-06-09_03-49-04AM.log
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/u01/app/oracle/inventory/orainstRoot.sh
/db/app/oracle/product/11/root.sh
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.
根据日志提示 使用root用户 执行如下命令 ,完成安装
Changing groupname of /u01/app/oracle/inventory to oinstall.
The execution of the script is complete.
[root@oracle100 ~]# /db/app/oracle/product/11/root.sh
Check /db/app/oracle/product/11/install/root_oracle100_2021-06-09_03-53-21.log for the output of root script
[root@oracle100 ~]#
可以查看 输出的 日志文件内容 判定执行结果
配置监听
oralce 用户 执行如下命令 配置监听 ,配置后可以看到 oralce 监听 1521 端口
[oracle@oracle100 database]$ netca /silent /responsefile /db/etc/netca.rsp
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /db/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/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
oracle@oracle100 database]$ 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 13052/tnslsnr
[oracle@oracle100 database]$
创建数据库
编辑/db/etc/dbca.rsp 增加如下内容
vi /db/etc/dbca.rsp
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/db/app/oracle/oradata
RECOVERYAREADESTINATION=/db/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "3277"
执行如下命令创建数据库,这里所有密码都填oracle
[oracle@oracle100 etc]$ dbca -silent -responseFile /db/etc/dbca.rsp
Enter SYS user password:
Enter SYSTEM user password:
Copying database files
1% complete
Creating and starting Oracle instance
40% complete
Completing Database Creation
85% complete
查看进程
[oracle@oracle100 etc]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 09-JUN-2021 04:03:27
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 09-JUN-2021 03:57:00
Uptime 0 days 0 hr. 6 min. 27 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /db/app/oracle/product/11/network/admin/listener.ora
Listener Log File /db/app/oracle/diag/tnslsnr/oracle100/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle100)(PORT=1521)))
Services Summary...
Service "orcl11g.us.oracle.com" has 1 instance(s).
Instance "orcl11g", status READY, has 1 handler(s) for this service...
Service "orcl11gXDB.us.oracle.com" has 1 instance(s).
Instance "orcl11g", status READY, has 1 handler(s) for this service...
The command completed successfully
问题解决
could not open parameter 错误
sqlplus conn / as sysdba 成功登录
执行 startup 命令 报错
could not open parameter file '/db/app/oracle/product/11/dbs/initORCL.ora'
只需复制 /initORCL.ora 到指定目录如下:
[root@oracle100 oracle]# cp /db/app/oracle/admin/orcl11g/pfile/init.ora.5920214210 /db/app/oracle/product/11/dbs/initORCL.ora
[root@oracle100 dbs]# chown oracle:oinstall initORCL.ora
[root@oracle100 dbs]# ll
total 28
-rw-rw---- 1 oracle oinstall 1544 Jun 9 04:01 hc_DBUA0.dat
-rw-rw---- 1 oracle oinstall 1544 Jun 9 04:02 hc_orcl11g.dat
-rw-r--r-- 1 oracle oinstall 2851 May 15 2009 init.ora
-rw-r----- 1 oracle oinstall 1805 Jun 9 04:16 initORCL.ora
-rw-r----- 1 oracle oinstall 24 Jun 9 04:01 lkORCL11G
-rw-r----- 1 oracle oinstall 1536 Jun 9 04:02 orapworcl11g
-rw-r----- 1 oracle oinstall 2560 Jun 9 04:02 spfileorcl11g.ora
MEMORY_TARGET not supported on this system
再次执行 startup 报错:EMORY_TARGET not supported on this system
使用root用户执行如下命令:
mount -t tmpfs shmfs -o size=7g /dev/shm
再次执行 startup 可以正常启动
SQL> startup
ORACLE instance started.
cannot mount database in EXCLUSIVE mode
执行sql 报错:cannot mount database in EXCLUSIVE mode
先关闭数据库
ORA-01102: cannot mount database in EXCLUSIVE mode
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
执行如下命令 fuser -u lk +数据库名(每个人可能不一样)
[root@oracle100 dbs]# fuser -u lkORCL11G
/db/app/oracle/product/11/dbs/lkORCL11G: 13517(oracle) 13521(oracle) 13523(oracle) 13527(oracle) 13529(oracle) 13531(oracle) 13533(oracle) 13535(oracle) 13537(oracle) 13539(oracle) 13541(oracle) 13572(oracle) 13589(oracle) 13603(oracle) 13605(oracle) 13640(oracle)
[root@oracle100 dbs]# fuser -k lkORCL11G
/db/app/oracle/product/11/dbs/lkORCL11G: 13517 13521 13523 13527 13529 13531 13533 13535 13537 13539 13541 13572 13589 13603 13605 13640
[root@oracle100 dbs]#
如果 提示 fuser 命令不存在则需要通过yum 进行安装
[root@oracle100 dbs]# yum install -y psmisc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* epel: mirror.earthlink.iq
* extras: mirrors.nju.edu.cn
* updates: mirrors.nju.edu.cn
处理完成后再次启动数据库 执行查询sql 可以查询数据了
SQL> startup
ORACLE instance started.
Total System Global Area 1169149952 bytes
Fixed Size 2212736 bytes
Variable Size 704646272 bytes
Database Buffers 452984832 bytes
Redo Buffers 9306112 bytes
Database mounted.
Database opened.
SQL> select * from dual;
DU
--
X
创建用户远程连接
创建用户并赋权登录建表
SQL> create user zxm identified by zxm;
SQL> grant create session,create table,dba to zxm;
Grant succeeded.
SQL> connect zxm/zxm
Connected.
SQL> create table test (name varchar(10));
Table created
SQL> insert into test values('zhangsan');
1 row created.
SQL> select * from test
2 ;
NAME
--------------------
zhangsan
使用dbever 连接工具,这种工具比plsql配置简单很多,方便易用。建立oracle连接,如下:
使用dbever时需要配置驱动,把oraclejava驱动jar上传。