zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Oracle-ASM单实例数据库安装

2023-09-14 09:01:48 时间

oracle enterprise linux 6.4+oracle 11.2.0.4 单实例+ASM 部署手册
一、 主机准备
ip:192.168.100.100
主机名: oracle 11g
目录: /u01
磁盘: 35G 本地磁盘一个, 另外再分块 16G 磁盘


1.1 检查主机名和 IP 地址的映射: hostname -i
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=ora11g
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.100 ora11g


1.2 规划磁盘分区  --划分为一个扩展分区,在扩展分区下面划分6个逻辑分区
/dev/sda 35G 格式化后挂载到/ 安装操作系统和 ORACLE 软件
/dev/sdb 16G, 分成 6 个区, 不需格式化, 给 ASM 使用
[root@ora11g ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe5fb8fdf.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe5fb8fdf
Device Boot Start End Blocks Id System
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e P
artition number (1-4): 1
First cylinder (1-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088):
Using default value 2088
Command (m for help): p
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe5fb8fdf

 

Device BootStartEndBlocksIdSystem
/dev/sdb11208816771828+5Extended
Command (m for help):
Command (m for help): n
Command action
l logical (5 or over)
pprimary partition (1-4)


l F
irst cylinder (1-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088): +3G
Command (m for help): p
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe5fb8fdf

 

 

Device BootStartEndBlocksIdSystem
/dev/sdb11208816771828+5Extended
/dev/sdb513933156709+83Linux
/dev/sdb6394786315674183Linux
/dev/sdb77871179315674183Linux
/dev/sdb811801572315674183Linux
/dev/sdb9157318342104483+83Linux
/dev/sdb10183520882040223+83Linux


Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@ora11g ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe5fb8fdf

 

 

Device BootStartEndBlocksIdSystem
/dev/sdb11208816771828+5Extended
/dev/sdb513933156709+83Linux
/dev/sdb6394786315674183Linux
/dev/sdb77871179315674183Linux
/dev/sdb811801572315674183Linux
/dev/sdb9157318342104483+83Linux
/dev/sdb10183520882040223+83Linux
[root@ora11g ~]# reboot


二. 配置本地 YUM
1.挂载光驱
mkdir -p /media/cdrom /src
mount -o loop -t iso9660 /dev/sr0 /media/cdrom


2. 配置文件, 将/etc/yum.repos.d/下现存文件都删除或重命名.bak,然后新建一个 local.repo
文件, 并添加相应内容:
[local]
name=oracle-local
baseurl=file:///media/cdrom/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle

 

3.安装缺少的包
yum install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-common
glibc-devel gcc gcc-c++ libaio-devel libaio libgcc libstdc++ libstdc++-devel make sysstat
unixODBC unixODBC-devel ksh compat-libcap1

三. 安装 VNC(如果是自己虚拟机忽略这一步)
1. 安装 VNC
yum install tigervnc-server -y

2. 配置用户
vim /etc/sysconfig/vncservers
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1365x768 -nolisten tcp"

3.创建密码
#vncserver
You will require a password to access your desktops.
Password:oracle
Verify: oracle
xauth: file /root/.Xauthority does not exist
New 'ora11g:1 (root)' desktop is ora11g:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/ora11g:1.log

4.启动 vncserver
service vncserver restart

5.客户端连接 VNC
LINUX: 使用 TigerVNC Viewer 连接 ip:1
Windows: 使用 Real VNC Viewer 连接

6.关闭防火墙
service iptables stop
chkconfig iptables off

四. 配置 oracle 安装环境
1.创建ORACLE用户和组用户
groupadd oinstall
groupadd dba
groupadd oper
groupadd asmadmin
groupadd asmdba
groupadd asmoper
useradd -g oinstall -G dba,asmdba,oper oracle
useradd -g oinstall -G dba,asmadmin,asmdba,asmoper grid
passwd oracle (oracle123)
passwd grid (grid123)

2.创建以下目录并授权
mkdir -p /u01/app/11.2.0/grid
mkdir -p /u01/app/grid
mkdir -p /u01/app/oracle/product/11.2.0/db_1
chown -R oracle:oinstall /u01/app
chmod -R 775 /u01/app

3. 设置 oracle、 grid 用户的环境变量
3.1 oracle 用户登陆:
vi ~/.bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.
export NLS_LANG=american_america.ZHS16GBK
export ORACLE_SID=oradb
export PATH=$PATH:$ORACLE_HOME/bin:.

3.2 grid 用户登录: vi ~/.bash_profile
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0/grid
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.
export NLS_LANG=American_america.ZHS16GBK
export PATH=$PATH:$ORACLE_HOME/bin:.
export ORACLE_SID=+ASM

4. root 用户更改系统参数(之前有配, 可省略)
4.1 vi /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152 // 可以不设
kernel.shmmax = 4398046511104 //一般设置为系统内存 75%单位是字节, 可以不设
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


/sbin/sysctl -p --这条命令在修改完参数之后记得立刻生效

4.2 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
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240

4.3 vi /etc/pam.d/login
#oracle
session required /lib64/security/pam_limits.so
session required pam_limits.so

5.上传 Oracle 安装介质到/u01/tmp 目录下并解压
mkdir -p /u01/tmp
p13390677_112040_Linux-x86-64_1of7.zip
p13390677_112040_Linux-x86-64_2of7.zip
p13390677_112040_Linux-x86-64_3of7.zip
unzip p13390677_112040_Linux-x86-64_1of7.zip
unzip p13390677_112040_Linux-x86-64_2of7.zip
unzip p13390677_112040_Linux-x86-64_3of7.zip
#chown -R grid:oinstall /u01/tmp/grid  --记得解压之后修改目录的权限

五.安装 grid 组件
1.Xmanager 软件用 grid 用户登录并安装
xhost +
su - grid
$cd /u01/tmp/grid
$./runInstaller
skip software updates--Install Oracle Grid Infrastructure Software only --english---privileged
operating system groups(asmadmin,asmdba,asmoper)--
oracle base:/u01/app/grid software location:/u01/app/11.2.0/grid---Inventory
Directory:/u01/app/oraInventory
安装时可能会缺包, 根据提示安装,另外还会报 resolv.conf 错误
yum -y install compat-libcap1
yum -y install ksh
NTP 报警处理
service ntpd stop
mv /etc/ntp.conf /etc/ntp.conf.bak
resolv.conf 报警, 主要是DNS配置问题, 不影响安装. 暂时跳过
图形界面安装, 最后 root 用户执行两个脚本, 执行脚本的屏幕输出如下:
/u01/app/oraInventory/orainstRoot.sh
/u01/app/11.2.0/grid/root.sh
安装日志目录
/u01/app/oraInventory/logs/installActions2017-01-22_02-53-39PM.log
根据上步执行的脚本输出提示, 确定单节点需要 root 用户执行下面的命令

 

/u01/app/11.2.0/grid/perl/bin/perl  -I/u01/app/11.2.0/grid/perl/lib  -I/u01/app/11.2.0/grid/crs/install /u01/app/11.2.0/grid/crs/install/roothas.pl


2.下载并安装ASMLIB(使用UDEV也可以)

2.1 oracle 官居网下载下面两个包
oracleasmlib-2.0.4-1.el6.x86_64.rpm oracleasm-support-2.1.8-1.el6.x86_64.rpm
cd /etc/yum.repos.d/

2.2 下载 redhat6.8 内核 oracleasm 包
wget http://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6 -O
/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
如果使用的是 Oracle Linux 的 uek 内核, oracleasm 已经被编译到了内核中, 如果使用的是和
Red Hat 兼容的内核, 那么需要手动安装 kmod-oracleasm 包
yum install kmod-oracleasm(oracle linux 不用装)
rpm -ivh oracleasmlib-2.0.4-1.el6.x86_64.rpm oracleasm-support-2.1.8-1.el6.x86_64.rpm

2.3 配置 asmlib 驱动
[root@11gocp yum.repos.d]# /etc/init.d/oracleasm configure
Configuring the Oracle ASM library driver.
This will configure the on-boot properties of the Oracle ASM library
driver. The following questions will determine whether the driver is
loaded on boot and what permissions it will have. The current values
will be shown in brackets ('[]'). Hitting <ENTER> without typing an
answer will keep that current value. Ctrl-C will abort.
Default user to own the driver interface []: grid
Default group to own the driver interface []: asmadmin
Start Oracle ASM library driver on boot (y/n) [n]: y
Scan for Oracle ASM disks on boot (y/n) [y]:
Writing Oracle ASM library driver configuration: done
Initializing the Oracle ASMLib driver: [ OK ]
Scanning the system for Oracle ASMLib disks: [ OK ]
[root@11gocp yum.repos.d]#

2.4 启动ASM
[root@11gocp yum.repos.d]# /etc/init.d/oracleasm start
Initializing the Oracle ASMLib driver: [ OK ]
Scanning the system for Oracle ASMLib disks: [ OK ]
[root@11gocp yum.repos.d]#

2.5 创建ASM磁盘(注意关闭selinux, cat /etc/selinux/config    SELINUX=permissive    记得重启才生效,否则创建磁盘会报错
/etc/init.d/oracleasm createdisk VOL1 /dev/sdb5
/etc/init.d/oracleasm createdisk VOL2 /dev/sdb6
/etc/init.d/oracleasm createdisk VOL3 /dev/sdb7
/etc/init.d/oracleasm createdisk VOL4 /dev/sdb8
/etc/init.d/oracleasm createdisk VOL5 /dev/sdb9
/etc/init.d/oracleasm createdisk VOL6 /dev/sdb10
[root@11gocp asm]# /etc/init.d/oracleasm listdisks
VOL1
VOL2
VOL3
VOL4
VOL5
VOL6

2.6 使用ASMCA创建ASM磁盘组
xhost +
su - grid
asmca
asm administor sys:asm123 asmsnmp:asm123
DATA--->VOL1,VOL2,VOL3,VOL4 采用外部冗余
RECDATA---->VOL5,VOL6 采用外部冗余

六. 安装ORACLE
1.解压并发装 oracle 软件
#cd /u01/tmp/

 

 

#unzipp13390677_112040_Linux-x86-64_1of7.zip;unzip
p13390677_112040_Linux-x86-64_2of7.zip
#chown -R oracle:oinstall database
vnc 软件用 oracle 用户登录
xhost +
su - oracle
$cd /u01/tmp/database/


$./runInstaller (此部选择此安装软件)
Skip software updates---Install database software only--Single instance database
installation--select languages:english
--Enterprise Edition(4.7GB)--Oracle base:/u01/app/oracle Software
Locatoin:/u01/app/oracle/product/11.2.0/db_1---
database Administrator(OSDBA):dba Database Operator(OSOPER) Group (Optional):oper
图形界面安装, 最后 root 用户执行一个脚本
#/u01/app/oracle/product/11.2.0/db_1/root.sh
安装日志
/u01/app/oraInventory/logs/installActions2017-01-23_10-59-23AM.log
2.创建数据库
vnc 软件用 oracle 用户登录
$dbca
sys 密码: oracle123
图形界面建库, Storage Type 选择 ASM, 数据放在+DATA 磁盘组, 归档放在+RDCDATA,数据库
字符集根据实际情况选择,先不要安装EM, 如果安装EM会出现 ORA-12154
3. 使用 grid 用户创建监听
Xmanager 软件用 grid 用户登录
$netca
lsnrctl start
13. 客户端测试数据库连接
ping IP 地址
tnsping IP 地址
sqlplus system/oracle@IP 地址/jyzhao
su - grid
sqlplus sys/asm123 as sysasm
sqlplus /nolog
SQL>conn / as sysasm
SQL> col name format a10;
SQL> col fgno format a20;
SQL> set line 200;
SQL> select group_number gno,name,state,type,total_mb,free_mb,required_mirror_free_mb
rmfmb,usable_file_mb ufmb from v$asm_diskgroup;
GNO NAME STATE TYPE TOTAL_MB
FREE_MB RMFMB UFMB
---------- ---------- ---------------------- ------------ ---------- ---------- ---------- ----------

 

 

1 DATAMOUNTEDEXTERN
28787028787
2 RECDATAMOUNTEDEXTERN
20242020242


30708
20472
--创建磁盘组
SQL> create diskgroup dg3 normal redundancy disk 'ORCL:VOL9','ORCL:VOL10';
1 2 3 4 5 6 D
iskgroup created.
或:
SQL> create diskgroup dg3 normal redundancy disk 'ORCL:VOL9' disk 'ORCL:VOL10';
Diskgroup created.
--添加磁盘
1 2 3 4 S
QL> alter diskgroup dg1 add disk 'ORCL:VOL9';
Diskgroup altered.
--删除磁盘
SQL> alter diskgroup dg1 drop disk VOL9;
Diskgroup altered.
alter diskgroup dg1 undrop disks;
--调整大小
ALTER DISKGROUP DG1 RESIZE DISK VOL4 SIZE 1024 M
--unmount 和 mount 磁盘组
SQL> alter diskgroup dg3 dismount;
Diskgroup altered.
SQL> select group_number gno,name,state,type,total_mb,free_mb,required_mirror_free_mb
rmfmb,usable_file_mb ufmb from v$asm_diskgroup;
GNO NAME STATE TYPE
TOTAL_MB FREE_MB RMFMB UFMB
---------- ------------------------------ ---------------------- ------------------------------ ---------- ---------- ----------
----------
1 DG1 MOUNTED NORMAL
4076 575 879 -152
2 DG2 MOUNTED NORMAL
4076 3531 139 1696
0 DG3 DISMOUNTED
SQL> alter diskgroup dg3 mount;
Diskgroup altered.
7.安装EM
[oracle@ora11g ~]$ sqlplus / as sysdba
SQL> alter user dbsnmp identified by oracle123 account unlock;
User altered.
SQL> alter user sysman identified by oracle123 account unlock;
User altered.
SQL>
备注: oracle 数据库 sys/system/dbsnmp/sysman 密码: oracle123
ASM实例用户名和密码
sys/asm123
asmsnmp/asm123
[oracle@11gocp ~]$ emca -config dbcontrol db -repos recreate
STARTED EMCA at Jan 23, 2017 1:25:25 PM
EM Configuration Assistant, Version 11.2.0.3.0 Production
Copyright (c) 2003, 2011, Oracle. All rights reserved.
Enter the following information:
Database SID: oradb
Listener port number: 1521
Listener ORACLE_HOME [ /u01/app/oracle/product/11.2.0/db_1 ]:
Password for SYS user: oracle123
Password for DBSNMP user: oracle123
Password for SYSMAN user: oracle123
Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
ASM ORACLE_HOME [ /u01/app/11.2.0/grid]:
ASM SID [ +ASM ]:
ASM port [ 1521 ]:
ASM username [ ASMSNMP ]:
ASM user password: asm123
-----------------------------------------------------------------
----------------------------------------------------------------------
WARNING : While repository is dropped the database will be put in quiesce mode.
----------------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]: y
Aug 21, 2017 12:20:32 AM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at
/u01/app/oracle/cfgtoollogs/emca/oradb/emca_2017_08_21_00_20_01.log.
Aug 21, 2017 12:20:33 AM oracle.sysman.emcp.EMReposConfig invoke
INFO: Dropping the EM repository (this may take a while) ...
Aug 21, 2017 12:24:23 AM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully dropped
Aug 21, 2017 12:24:24 AM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) ...
Aug 21, 2017 12:32:28 AM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully created
Aug 21, 2017 12:32:32 AM oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository
INFO: Uploading configuration data to EM repository (this may take a while) ...
Aug 21, 2017 12:33:46 AM oracle.sysman.emcp.EMReposConfig invoke
INFO: Uploaded configuration data successfully
Aug 21, 2017 12:33:47 AM oracle.sysman.emcp.ParamsManager getLocalListener
WARNING: Error retrieving listener for ora11g
Aug 21, 2017 12:33:49 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Securing Database Control (this may take a while) ...
Aug 21, 2017 12:34:21 AM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Database Control secured successfully.
Aug 21, 2017 12:34:21 AM oracle.sysman.emcp.util.DBControlUtil startOMS
INFO: Starting Database Control (this may take a while) ...
Aug 21, 2017 12:36:03 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: Database Control started successfully
Aug 21, 2017 12:36:03 AM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: >>>>>>>>>>> The Database Control URL is https://ora11g:1158/em <<<<<<<<<<<
Aug 21, 2017 12:36:10 AM oracle.sysman.emcp.EMDBPostConfig invoke
WARNING:
************************ WARNING ************************
Management Repository has been placed in secure mode wherein Enterprise Manager data will
be encrypted. The encryption key has been placed in the file:
/u01/app/oracle/product/11.2.0/db_1/ora11g_oradb/sysman/config/emkey.ora. Ensure this file
is backed up as the encrypted data will become unusable if this file is lost.
***********************************************************
Enterprise Manager configuration completed successfully
FINISHED EMCA at Aug 21, 2017 12:36:10 AM
EM 安装日志文件:
tailf /u01/app/oracle/cfgtoollogs/emca/oradb/emca_2017_08_21_00_20_01.log