[转载]以及部分总结--Linux下创建单机ASM存储的Oracle实例的过程---感谢方总
[转载]以及部分总结--Linux下创建单机ASM存储的Oracle实例的过程---感谢方总
转载一.安装Linux
- ESXi上传iso镜像至存储目录
- 创建虚拟机,并且选择主机设备的ISO启动
选择完成时编辑虚拟机设置
配置镜像文件如下:
打开控制台:
并且选择开机
点击开机并且进行安装linux
选择第一项目进行安装
Skip检查快速安装
输入机器名:
进行磁盘的设置
将SWAP分区设置的较大(50G左右)
选择现在定义源,增加部分包
Linux安装完成即可
二 . 系统参数修改以及软件安装
1. 主机准备
IP地址:
- 1.
主机名:JY-DB
- 1.
目录:/u01
- 1.
磁盘:从主机本地磁盘资源划分50G硬盘1个,从磁阵资源划分10G硬盘3个
- 1.
1.1 检查主机名和IP地址的映射:hostname -i
hostname
- 1.
vi /etc/sysconfig/network
- 1.
vi /etc/hosts
- 1.
1.2 分配/u01目录为oracle软件安装目录,lv_asm1,lv_asm2,lv_asm3为ASM磁盘
/dev/xvdb 50G 格式化后挂载到/u01目录
/dev/xvdc /dev/xvde /dev/xvdf 各10G,不用格式化,给ASM使用
pvcreate /dev/xvdc /dev/xvde /dev/xvdf
- 1.
vgcreate ora_vg /dev/xvdc /dev/xvde /dev/xvdf
- 1.
lvcreate -L 10g -n lv_asm1 ora_vg
- 1.
lvcreate -L 10g -n lv_asm2 ora_vg
- 1.
vgdisplay ora_vg
- 1.
lvcreate -l 2557 -n lv_asm3 ora_vg
- 1.
在后面创建grid用户后,创建ASM前,需要更改lv的磁盘权限
chown grid:asmadmin /dev/mapper/ora*
- 1.
1.3 配置YUM,安装依赖包
yum配置参考:javascript:void(0)
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 pdksh ksh compat-libcap1
- 1.
若之前安装系统没有安装图形,需要安装图形界面和xterm
yum groupinstall "X Window System"
- 1.
- 1.
yum install xterm
- 1.
1.4 关闭系统防火墙开机启动
service iptables stop
- 1.
chkconfig iptables off
- 1.
2. 创建ORACLE 用户和组成员
groupadd oinstall
- 1.
groupadd dba
- 1.
groupadd oper
- 1.
groupadd asmadmin
- 1.
groupadd asmdba
- 1.
groupadd asmoper
- 1.
useradd -g oinstall -G dba,asmdba,oper oracle
- 1.
useradd -g oinstall -G dba,asmadmin,asmdba,asmoper grid
- 1.
分别指定oracle、grid用户的密码
passwd oracle
- 1.
passwd grid
- 1.
3. 创建以下目录并赋予对应权限
mkdir -p /u01/app/11.2.0/grid
- 1.
mkdir -p /u01/app/grid
- 1.
mkdir -p /u01/app/oracle/product/11.2.0/db_1
- 1.
chown -R oracle:oinstall /u01/app
- 1.
chmod -R 775 /u01/app
- 1.
4. 设置oracle、grid用户的环境变量
4.1 oracle用户登陆: vi ~/.bash_profile
export ORACLE_BASE=/u01/app/oracle
- 1.
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
- 1.
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.
- 1.
export NLS_LANG=american_america.ZHS16GBK
- 1.
export ORACLE_SID=jyzhao
- 1.
export PATH=$PATH:$ORACLE_HOME/bin:.
- 1.
4.2 grid用户登录:vi ~/.bash_profile
export ORACLE_BASE=/u01/app/grid
- 1.
export ORACLE_HOME=/u01/app/11.2.0/grid
- 1.
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.
- 1.
export NLS_LANG=American_america.ZHS16GBK
- 1.
export PATH=$PATH:$ORACLE_HOME/bin:.
- 1.
export ORACLE_SID=+ASM
- 1.
5. root用户更改系统参数
5.1 vi /etc/sysctl.conf
fs.aio-max-nr = 1048576
- 1.
fs.file-max = 6815744
- 1.
kernel.shmall = 2097152
- 1.
kernel.shmmax = 4398046511104
- 1.
kernel.shmmni = 4096
- 1.
kernel.sem = 250 32000 100 128
- 1.
net.ipv4.ip_local_port_range = 9000 65500
- 1.
net.core.rmem_default = 262144
- 1.
net.core.rmem_max = 4194304
- 1.
net.core.wmem_default = 262144
- 1.
net.core.wmem_max = 1048586
- 1.
使设置立即生效: /sbin/sysctl -p
5.2 vi /etc/security/limits.conf
oracle soft nproc 2047
- 1.
oracle hard nproc 16384
- 1.
oracle soft nofile 1024
- 1.
oracle hard nofile 65536
- 1.
oracle soft stack 10240
- 1.
grid soft nproc 2047
- 1.
grid hard nproc 16384
- 1.
grid soft nofile 1024
- 1.
grid hard nofile 65536
- 1.
grid soft stack 1024
- 1.
5.3 vi /etc/pam.d/login
#oracle
- 1.
session required /lib64/security/pam_limits.so
- 1.
session required pam_limits.so
- 1.
6. 上传Oracle安装介质到/u01/tmp目录下
mkdir -p /u01/tmp
- 1.
- 1.
p13390677_112040_Linux-x86-64_1of7.zip
- 1.
p13390677_112040_Linux-x86-64_2of7.zip
- 1.
p13390677_112040_Linux-x86-64_3of7.zip
- 1.
7. 安装grid组件
#cd /u01/tmp/
- 1.
#unzip p10404530_112030_Linux-x86-64_3of7.zip
- 1.
#chown -R grid:oinstall grid
- 1.
- 1.
Xmanager软件用grid用户登录
- 1.
$cd /u01/tmp/grid
- 1.
$./runInstaller
- 1.
图形界面安装,最后root用户执行两个脚本,执行脚本的屏幕输出如下:
# /u01/app/oraInventory/orainstRoot.sh
- 1.
Changing permissions of /u01/app/oraInventory.
- 1.
Adding read,write permissions for group.
- 1.
Removing read,write,execute permissions for world.
- 1.
- 1.
Changing groupname of /u01/app/oraInventory to oinstall.
- 1.
The execution of the script is complete.
- 1.
- 1.
# /u01/app/11.2.0/grid/root.sh
- 1.
Performing root user operation for Oracle 11g
- 1.
- 1.
The following environment variables are set as:
- 1.
ORACLE_OWNER= grid
- 1.
ORACLE_HOME= /u01/app/11.2.0/grid
- 1.
- 1.
Enter the full pathname of the local bin directory: [/usr/local/bin]:
- 1.
Copying dbhome to /usr/local/bin ...
- 1.
Copying oraenv to /usr/local/bin ...
- 1.
Copying coraenv to /usr/local/bin ...
- 1.
- 1.
Creating /etc/oratab file...
- 1.
Entries will be added to the /etc/oratab file as needed by
- 1.
Database Configuration Assistant when a database is created
- 1.
Finished running generic part of root script.
- 1.
Now product-specific root actions will be performed.
- 1.
- 1.
To configure Grid Infrastructure for a Stand-Alone Server run the following command as the root user:
- 1.
/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
- 1.
- 1.
To configure Grid Infrastructure for a Cluster execute the following command:
- 1.
/u01/app/11.2.0/grid/crs/config/config.sh
- 1.
- 1.
This command launches the Grid Infrastructure Configuration Wizard. The wizard also supports silent operation, and the parameters can be passed through the response file that is available in the installation media.
- 1.
8. 根据上步执行的脚本输出提示,确定单节点需要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
- 1.
9. 使用asmca创建ASM 磁盘组
Xmanager软件用grid用户登录
$asmca
- 1.
10. 安装oralce软件
#cd /u01/tmp/
- 1.
#unzip p13390677_112040_Linux-x86-64_1of7.zip;unzip p13390677_112040_Linux-x86-64_2of7.zip
- 1.
#chown -R oracle:oinstall database
- 1.
- 1.
Xmanager软件用oracle用户登录
- 1.
$cd /u01/tmp/database/
- 1.
$./runInstaller
- 1.
- 1.
图形界面安装,最后root用户执行一个脚本
- 1.
#/u01/app/oracle/product/11.2.0/db_1/root.sh
- 1.
11. 创建数据库
Xmanager软件用oracle用户登录
$dbca
- 1.
图形界面建库,Storage Type选择ASM,+DATA1磁盘组,数据库字符集根据实际情况选择。
12. 使用grid用户创建监听
Xmanager软件用grid用户登录
$netca
- 1.
13. 客户端测试数据库连接
ping IP地址
- 1.
tnsping IP地址
- 1.
- 1.
sqlplus system/oracle@IP地址/jyzhao
- 1.
14. 由于lv的权限在重启后会变回root用户,需要添加开机启动脚本
vi /etc/rc.d/rc.local
- 1.
chown grid:asmadmin /dev/mapper/ora*
- 1.
- 1.
创建rc.local的链接文件
- 1.
- 1.
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc1.d/S999rc.local &&
- 1.
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc2.d/S999rc.local &&
- 1.
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc3.d/S999rc.local &&
- 1.
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc4.d/S999rc.local &&
- 1.
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc5.d/S999rc.local &&
- 1.
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc6.d/S999rc.local
- 1.
15. 重启测试
15.1 关闭数据库
# su - oracle
- 1.
$ sqlplus / as sysdba
- 1.
- 1.
SQL*Plus: Release 11.2.0.4.0 Production on Thu Mar 12 14:14:38 2015
- 1.
- 1.
Copyright (c) 1982, 2013, Oracle. All rights reserved.
- 1.
- 1.
Connected to:
- 1.
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
- 1.
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
- 1.
and Real Application Testing options
- 1.
- 1.
SQL> shutdown immediate
- 1.
Database closed.
- 1.
Database dismounted.
- 1.
ORACLE instance shut down.
- 1.
SQL>
- 1.
15.2 关闭has
$ su - grid
- 1.
Password:
- 1.
$ crsctl stop has
- 1.
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'jy-db'
- 1.
CRS-2673: Attempting to stop 'ora.LISTENER.lsnr' on 'jy-db'
- 1.
CRS-2673: Attempting to stop 'ora.DATA1.dg' on 'jy-db'
- 1.
CRS-2677: Stop of 'ora.LISTENER.lsnr' on 'jy-db' succeeded
- 1.
CRS-2677: Stop of 'ora.DATA1.dg' on 'jy-db' succeeded
- 1.
CRS-2679: Attempting to clean 'ora.DATA1.dg' on 'jy-db'
- 1.
CRS-2681: Clean of 'ora.DATA1.dg' on 'jy-db' succeeded
- 1.
CRS-2673: Attempting to stop 'ora.asm' on 'jy-db'
- 1.
CRS-2677: Stop of 'ora.asm' on 'jy-db' succeeded
- 1.
CRS-2673: Attempting to stop 'ora.cssd' on 'jy-db'
- 1.
CRS-2677: Stop of 'ora.cssd' on 'jy-db' succeeded
- 1.
CRS-2673: Attempting to stop 'ora.evmd' on 'jy-db'
- 1.
CRS-2677: Stop of 'ora.evmd' on 'jy-db' succeeded
- 1.
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'jy-db' has completed
- 1.
CRS-4133: Oracle High Availability Services has been stopped.
- 1.
15.3 重启主机
# sync
- 1.
# sync
- 1.
# sync
- 1.
- 1.
# shutdown -Fr now
- 1.
- 1.
Broadcast message from root@JY-DB
- 1.
- 1.
(/dev/pts/0) at 14:20 ...
- 1.
- 1.
The system is going down for reboot NOW!
- 1.
15.4主机启动后,查看crs状态
# /u01/app/11.2.0/grid/bin/crsctl stat res -t
- 1.
- 1.
--------------------------------------------------------------------------------
- 1.
NAME TARGET STATE SERVER STATE_DETAILS
- 1.
--------------------------------------------------------------------------------
- 1.
Local Resources
- 1.
--------------------------------------------------------------------------------
- 1.
ora.DATA1.dg
- 1.
ONLINE ONLINE jy-db
- 1.
ora.LISTENER.lsnr
- 1.
ONLINE ONLINE jy-db
- 1.
ora.asm
- 1.
ONLINE ONLINE jy-db Started
- 1.
ora.ons
- 1.
OFFLINE OFFLINE jy-db
- 1.
--------------------------------------------------------------------------------
- 1.
Cluster Resources
- 1.
--------------------------------------------------------------------------------
- 1.
ora.cssd
- 1.
1 ONLINE ONLINE jy-db
- 1.
ora.diskmon
- 1.
1 OFFLINE OFFLINE
- 1.
ora.evmd
- 1.
1 ONLINE ONLINE jy-db
- 1.
ora.jyzhao.db
- 1.
1 OFFLINE OFFLINE Instance Shutdown
- 1.
15.5 启动数据库
# /u01/app/11.2.0/grid/bin/srvctl start database -d jyzhao
- 1.
- 1.
# /u01/app/11.2.0/grid/bin/crsctl stat res -t
- 1.
--------------------------------------------------------------------------------
- 1.
NAME TARGET STATE SERVER STATE_DETAILS
- 1.
--------------------------------------------------------------------------------
- 1.
Local Resources
- 1.
--------------------------------------------------------------------------------
- 1.
ora.DATA1.dg
- 1.
ONLINE ONLINE jy-db
- 1.
ora.LISTENER.lsnr
- 1.
ONLINE ONLINE jy-db
- 1.
ora.asm
- 1.
ONLINE ONLINE jy-db Started
- 1.
ora.ons
- 1.
OFFLINE OFFLINE jy-db
- 1.
--------------------------------------------------------------------------------
- 1.
Cluster Resources
- 1.
--------------------------------------------------------------------------------
- 1.
ora.cssd
- 1.
1 ONLINE ONLINE jy-db
- 1.
ora.diskmon
- 1.
1 OFFLINE OFFLINE
- 1.
ora.evmd
- 1.
1 ONLINE ONLINE jy-db
- 1.
ora.jyzhao.db
- 1.
1 ONLINE ONLINE jy-db Open
- 1.
15.6 客户端测试
C:\Users\Alfred>sqlplus system/oracle@IP地址/jyzhao
- 1.
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 3月 12 14:27:12 2015
- 1.
Copyright (c) 1982, 2010, Oracle. All rights reserved.
- 1.
- 1.
连接到:
- 1.
- 1.
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
- 1.
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
- 1.
and Real Application Testing options
- 1.
- 1.
SQL>
- 1.
三. 其他注意事项
1. Shm参数的修改
Root用户修改 /etc/fstab 下的内容
[root@centos]# vi /etc/fstab
修改如下行:
tmpfs /dev/shm tmpfs defaults,size=1024M
0
0
其中,size=后面的数值不能小于memory_max_target的数值
修改完成之后 mount –o remount /dev/shm
使更改生效
2. Oracle DBCA创建过程
在进行DBCA的建库过程中需要修改内存方面的数值,内存应该在7G左右 太大的话会爆出out of memory的错误
如图:
建库完成后可以在修改memory_max_target的数值。
因为字符集的问题,可以在oracle用户输入DBCA命令之前首先使用
export LANG = en_us 将语言强制转换成英文字符,避免出现乱码
./runInstaller 以及其他GUI的命令均可以使用次命令
3. LUN映射的处理
修改虚拟机的设置,增加lun的映射
增加磁盘,选择裸设备,选择LUN设备即可
但是每一个磁盘增加玩之后都必须进行确定 再次打开才可以。
4. Linux下ASM磁盘的处理
转载 方立刚老师的文档
4.1 确定多路径服务是否安装如果未安装进行安装操作
确认multipath已经安装:
# rpm -q device-mapper-multipath
device-mapper-multipath-0.4.9-72.el6.x86_64
确认multipath服务已经自动启动
# chkconfig --list |grep multi
multipathd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
4.2 获取磁盘WWID
使用如下的命令 获取
#/bin/sh
for i in a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay;
do
echo sd$i
/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sd$i
done
4.3 配置制定磁盘别名等
# vi /etc/multipath.conf
增加内容如下 wwid如实填写
defaults {
user_friendly_names yes
}
multipaths {
multipath {
wwid 360050764008100140000000000000018
alias mpath_crs1
}
multipath {
wwid 360050764008100140000000000000019
alias mpath_crs2
}
multipath {
wwid 36005076400810014000000000000001a
alias mpath_crs3
}
multipath {
wwid 36005076400810014000000000000001b
alias mpath_crs4
}
4.4 配置asm识别
#vi /etc/udev/rules.d/12-dm-permissions.rules
配置内容为:
ENV{DM_NAME}=="mpath_crs1", NAME="asmdisk21", OWNER:="grid", GROUP:="oinstall", MODE:="660"
ENV{DM_NAME}=="mpath_crs2", NAME="asmdisk22", OWNER:="grid", GROUP:="oinstall", MODE:="660"
ENV{DM_NAME}=="mpath_crs3", NAME="asmdisk23", OWNER:="grid", GROUP:="oinstall", MODE:="660"
ENV{DM_NAME}=="mpath_crs4", NAME="asmdisk24", OWNER:="grid", GROUP:="oinstall", MODE:="660"
4.5 重启服务进行验证
重启服务:#service multipathd restart
查看结果:# ll /dev/asm*
5. Oracle内存参数的设置
5.1 修改pfile里面memory_max_target的数值并且进行启动
修改如图示中的文件:
增加memory_max_target 为标准数据进行保存
关闭数据库
Sqlplus / as sysdba
Startup pfile=’/u01/…../initora11r2.ora’
启动完成后将此文件覆盖到 oracle home目录的 dbs 目录下
使用create spfile from pfile 重新创建spfile 下次启动时自动生效
5.2 修改db_cache_size以及shared_pool_size的数值并且保存
Alter system set db_cache_size = 80g scope=spfile;
Alter system set shared_pool_size=20g scope=spfile;
修改完成后重启数据库使更改生效
6. Linux的包安装
在安装数据库时会提示缺少很多包,需要进行安装
进入RHEL6.5的ISO的package文件下下面。使用rpm –ivh packagename的方式就可以全部安装上
7. Linux下挂在NTFS磁盘并且进行数据恢复
下载一个ntfs-3g的包并且进行相应的安装操作
具体操作为:
tar –zvxf ntfs-3g…..tar
cd ntfs-3g……
./configure
make
make install
使用虚拟机配置挂在这次NTFS的磁盘
进入/dev的目录,查看新增加的磁盘
使用ntfs-3g /dev/sdf1 /mnt
进行挂载