1、NTP时间服务器配置,2节点,使用root用户
cd /etc/sysconfig;sed -i '/OPTIONS/ s/-u/-x -u/g' ntpd;service ntpd restart
2、hosts文件更改,2节点,使用root用户
cat >> /etc/hosts << EOF
#-----public ip-----#
x.x.x.1 testdb1-pub
x.x.x.2 testdb2-pub
#-----private ip-----#
192.168.x.1 testdb1-pri
192.168.x.2 testdb2-pri
#-----virtual ip-----#
x.x.x.3 testdb1-vip
x.x.x.4 testdb2-vip
#-----scan ip------#
x.x.x.5 testdb-scan
EOF
3、创建grid用户以及oracle用户2,节点,使用root账户
GROUP01=oinstall;GROUP02=dba;GROUP03=oper;GROUP04=asmadmin;GROUP05=asmdba;GROUP06=asmoper;GROUP07=orawh
USER01=grid;PASSWD01='xxx';USER02=oracle;PASSWD02='xxx';USER03=orawh;PASSWD03='xxx'
groupadd -g 1001 $GROUP01;groupadd -g 1002 $GROUP02;groupadd -g 1003 $GROUP03;groupadd -g 1004 $GROUP04;groupadd -g 1005 $GROUP05;groupadd -g 1006 $GROUP06;groupadd -g 1007 $GROUP07
useradd -g $GROUP01 -G $GROUP02,$GROUP04,$GROUP05,$GROUP06 -u 1001 $USER01 -d /home/${USER01};echo "${PASSWD01}" | passwd --stdin $USER01
useradd -g $GROUP01 -G $GROUP02,$GROUP03,$GROUP05 -u 1002 $USER02 -d /home/${USER02};echo "${PASSWD02}" | passwd --stdin $USER02
useradd -g $GROUP07 -G $GROUP02 -u 1003 $USER03 -d /home/${USER03};echo "${PASSWD03}" | passwd --stdin $USER03
su - grid -c 'cat >> /home/grid/.bash_profile<< EOF
echo "您好,您正在通过grid账户登录系统,此账户具有集群权限,监控已经启动,请注意操作风险!"
EOF'
su - oracle -c 'cat >> /home/oracle/.bash_profile<< EOF
echo "您好,您正在通过oracle账户登录系统,此账户具有数据库权限,监控已经启动,请注意操作风险!"
EOF'
su - orawh -c 'cat >> /home/orawh/.bash_profile<< EOF
echo "您好,您正在通过orawh账户登录系统,此账户具有数据库权限,监控已经启动,请注意操作风险!"
EOF'
USER="oracle"
cp /home/${USER}/.bash_profile /home/${USER}/.bash_profile.bak
cat << 'E'OF >> /home/${USER}/.bash_profile
IPADDR=`ifconfig bond0 | grep "inet addr" | awk '{print $2}' | awk -F ':' '{ print $2}'`
PWD=`pwd`
export PS1='${USER}|${IPADDR}|${PWD}>'
stty erase ^H
EOF
USER="grid"
cp /home/${USER}/.bash_profile /home/${USER}/.bash_profile.bak
cat << 'E'OF >> /home/${USER}/.bash_profile
IPADDR=`ifconfig bond0 | grep "inet addr" | awk '{print $2}' | awk -F ':' '{ print $2}'`
PWD=`pwd`
export PS1='${USER}|${IPADDR}|${PWD}>'
stty erase ^H
EOF
USER="orawh"
cp /home/${USER}/.bash_profile /home/${USER}/.bash_profile.bak
cat << 'E'OF >> /home/${USER}/.bash_profile
IPADDR=`ifconfig bond0 | grep "inet addr" | awk '{print $2}' | awk -F ':' '{ print $2}'`
PWD=`pwd`
export PS1='${USER}|${IPADDR}|${PWD}>'
stty erase ^H
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=tadb1
EOF
4、ASM共享磁盘设置,2节点,使用root账户
emcpadm renamepseudo -s emcpowero -t emcpowerf
cd /etc/udev/rules.d;touch 99-oracle-asmdisks.rules
scsi_id -g -u -d /dev/emcpowerx
echo 'KERNEL=="emcpower?", BUS=="*", PROGRAM=="scsi_id -g -u -d /dev/$name",RESULT=="360060160a7b03400e770b68b9bb6e511", NAME="asmdisk1_200G", OWNER="grid", GROUP="asmadmin", MODE="0660"' >> 99-oracle-asmdisks.rules
/sbin/udevadm control --reload-rules;/sbin/start_udev
5、创建/u01文件系统,2节点,使用root账户
SZ="99G";VG="appvg";LV="applv";MN="/u01";mkdir -p /u01
pvcreate /dev/emcpowera;vgcreate appvg /dev/emcpowera;lvcreate -L ${SZ} -n ${LV} ${VG}
mkfs -t ext4 /dev/${VG}/${LV}
mount -t ext4 /dev/mapper/${VG}-${LV} $MN
cp /etc/fstab /etc/fstab.bak
echo "/dev/mapper/${VG}-${LV} /u01 ext4 defaults 0 0" >> /etc/fstab
mkdir -p /u01/app/11.2.0/grid;mkdir -p /u01/app/grid;mkdir -p /u01/app/oracle
chown -R grid:oinstall /u01;chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app/grid;chmod -R 775 /u01/app/11.2.0/grid;chmod -R 775 /u01/app/oracle
6、sysctl及limit配置,2节点,使用root账户
cat >> /etc/security/limits.conf << EOF
#user "grid" limits
grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240
#user oracle limits
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOF
#修改内核参数
sed -i 's/kernel.shmmax/#kernel.shmmax/g' /etc/sysctl.conf
sed -i 's/kernel.shmall/#kernel.shmall/g' /etc/sysctl.conf
cat >> /etc/sysctl.conf << EOF
#Modified Kernel parameter
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
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
EOF
sysctl -p
#修改节点1的grid用户的环境变量
su - grid -c 'cat >> /home/grid/.bash_profile<< EOF
#user "grid" Environment variables
export ORACLE_SID=+ASM1
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0/grid
export NLS_DATE_FORMAT="yy-mm-dd HH24:MI:SS"
export PATH=\$ORACLE_HOME/bin:\$PATH
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
stty erase ^H
#user Prompt
echo ORACLE_BASE=\$ORACLE_BASE
echo ORACLE_HOME=\$ORACLE_HOME
echo ORACLE_SID=\$ORACLE_SID
EOF'
#修改节点2的grid用户的环境变量
su - grid -c 'cat >> /home/grid/.bash_profile<< EOF
#user "grid" Environment variables
export ORACLE_SID=+ASM2
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0/grid
export NLS_DATE_FORMAT="yy-mm-dd HH24:MI:SS"
export PATH=\$ORACLE_HOME/bin:\$PATH
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
stty erase ^H
#user Prompt
echo ORACLE_BASE=\$ORACLE_BASE
echo ORACLE_HOME=\$ORACLE_HOME
echo ORACLE_SID=\$ORACLE_SID
EOF'
#修改节点1的oracle用户的环境变量
su - oracle -c 'cat>> /home/oracle/.bash_profile<< EOF
#user "oracle" Environment variables
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=hisdb1
export ORACLE_TERM=xterm
export PATH=/usr/sbin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
export NLS_DATE_FORMAT="yy-mm-dd HH24:MI:SS"
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
stty erase ^H
#user Prompt
echo ORACLE_BASE=\$ORACLE_BASE
echo ORACLE_HOME=\$ORACLE_HOME
echo ORACLE_SID=\$ORACLE_SID
EOF'
#修改节点2的oracle用户的环境变量
su - oracle -c 'cat>> /home/oracle/.bash_profile<< EOF
#user "oracle" Environment variables
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export ORACLE_SID=hisdb2
export ORACLE_TERM=xterm
export PATH=/usr/sbin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
export NLS_DATE_FORMAT="yy-mm-dd HH24:MI:SS"
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
stty erase ^H
#user Prompt
echo ORACLE_BASE=\$ORACLE_BASE
echo ORACLE_HOME=\$ORACLE_HOME
echo ORACLE_SID=\$ORACLE_SID
EOF'
#安装必要的程序软件
yum -y groupinstall 'X Window System'
yum -y install unzip
#grid用户建立互信关系
#节点1
su - grid
ssh-keygen -t rsa
ssh-keygen -t dsa
cd /home/grid/.ssh
cat id_rsa.pub >> authorized_keys
cat id_dsa.pub >> authorized_keys
#节点2
su - grid
ssh-keygen -t rsa
ssh-keygen -t dsa
#节点1
scp authorized_keys grid@10.1.141.37:/home/grid/.ssh
#节点2
cd /home/grid/.ssh
cat id_rsa.pub >> authorized_keys
cat id_dsa.pub >> authorized_keys
scp authorized_keys grid@10.1.141.36:/home/grid/.ssh
#节点1和节点2
ssh hisdb1 date
ssh hisdb2 date
ssh hisdb1-pri date
ssh hisdb2-pri date
#oracle用户建立互信关系
#节点1
su - oracle
ssh-keygen -t rsa
ssh-keygen -t dsa
cd /home/oracle/.ssh
cat id_rsa.pub >> authorized_keys
cat id_dsa.pub >> authorized_keys
#节点2
su - oracle
ssh-keygen -t rsa
ssh-keygen -t dsa
#节点1
scp authorized_keys oracle@10.1.141.37:/home/oracle/.ssh
#节点2
cd /home/oracle/.ssh
cat id_rsa.pub >> authorized_keys
cat id_dsa.pub >> authorized_keys
scp authorized_keys oracle@10.1.141.36:/home/oracle/.ssh
#节点1和节点2
ssh hisdb1 date
ssh hisdb2 date
ssh hisdb1-pri date
ssh hisdb2-pri date
yum install -y libaio
yum install -y libaio-devel
yum install -y compat-libstdc++-33
yum install -y elfutils-devel
yum install -y glibc-devel
yum install -y gcc-c++
yum install -y libstdc++-devel
yum install -y sysstat
yum install -y smartmontools
yum install -y compat-libcap1
cd ./grid/rpm
yum install -y cvuqdisk-1.0.9-1.rpm
cd ./grid
./runcluvfy.sh stage -pre crsinst -n hisdb1,hisdb2 -fixup -verbose
#oracle配置
#使能空表导出
alter system set deferred_segment_creation = FALSE;
#修改数据库的游标
alter system set open_cursors=1500 scope=both;
#修改快照文件路径
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '+SYSTEM/hisdb/snapcf_hisdb.f';
创建weihu只读账户,拥有select any table/dictionary权限
create user weihu identified by thfund_weihu01;
grant connect to weihu;
grant select any table to weihu;
grant select any dictionary to weihu;
#创建thsys用户,具备dba权限
create user thsys identified by thfund_thsys01;
grant connect,resource,dba to thsys;
revoke unlimited tablespace from thsys;
#创建业务只读账户seluser
create user seluser identified by thfund_seluser2016;
grant connect to seluser;
grant select any table to seluser;
#创建netgain用户
create user netgain identified by thfund_netgain2016;
grant connect to netgain;
grant select any table to netgain;
grant select any dictionary to netgain;
#创建通用角色general_role
create role general_role;
grant alter session to general_role;
grant create cluster to general_role;
grant create database link to general_role;
grant create procedure to general_role;
grant create sequence to general_role;
grant create session to general_role;
grant create table to general_role;
grant create trigger to general_role;
grant create view to general_role;
grant create synonym to general_role;
grant debug connect session to general_role;
grant create materialized view to general_role;
#创建目录
create directory BACKUP as '/backup';
grant read,write on directory BACKUP to user;
#设置weihu、sys、system用户使用上述profile
alter user sys profile DEFAULT;
alter user seluser profile DEFAULT;
alter user netgain profile DEFAULT;
alter user system profile THFUND_PROFILE;
alter user weihu profile THFUND_PROFILE;
alter user thsys profile THFUND_PROFILE;
#数据库审计设置
alter system set audit_sys_operations=true scope=spfile;
alter system set audit_trail=db scope=spfile;
#修改DEFAUTL profile
ALTER PROFILE DEFAULT LIMIT
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_GRACE_TIME 7
FAILED_LOGIN_ATTEMPTS 10
PASSWORD_LOCK_TIME UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL;
#修改账户的密码
alter user weihu identified by thfund_weihu01;
alter user system identified by thfund_system01;
alter user thsys identified by thfund_thsys01;
alter user sys identified by thfund_sys2016;
alter user netgain identified by thfund_netgain2016;
alter user seluser identified by thfund_seluser2016;
#升级Opatch
su - root
mv /u01/app/11.2.0/grid/OPatch /u01/app/11.2.0/grid/OPatchbak
mv /u01/app/oracle/product/11.2.0/db_1/OPatch /u01/app/oracle/product/11.2.0/db_1/OPatchbak
cp /tmp/p6880880_112000_Linux-x86-64.zip /u01/app/11.2.0/grid
cd /u01/app/11.2.0/grid/
chown grid:oinstall p6880880_112000_Linux-x86-64.zip
unzip p6880880_112000_Linux-x86-64.zip
chown -R grid:oinstall OPatch
cd OPatch
./opatch version
cp /tmp/p6880880_112000_Linux-x86-64.zip /u01/app/oracle/product/11.2.0/db_1
cd /u01/app/oracle/product/11.2.0/db_1/
chown oracle:oinstall p6880880_112000_Linux-x86-64.zip
unzip p6880880_112000_Linux-x86-64.zip
chown -R oracle:oinstall OPatch
cd OPatch
./opatch version
cd /u01/app/oracle/product/11.2.0/db_1/OPatch/ocm/bin
/u01/app/oracle/product/11.2.0/db_1/OPatch/ocm/bin/emocmrsp
#升级grid db
su - oracle
$ORACLE_HOME/OPatch/opatch lsinventory -detail -oh $ORACLE_HOME
su - root
$ORACLE_HOME/OPatch/opatch auto /tmp/21523375 -ocmrf $ORACLE_HOME/OPatch/ocm/bin/ocm.rsp
su - oracle
cd $ORACLE_HOME/rdbms/admin
sqlplus /nolog
SQL> CONNECT / AS SYSDBA
SQL> STARTUP
SQL> @catbundle.sql psu apply
SQL> QUIT
cd $ORACLE_HOME/rdbms/admin
sqlplus /nolog
SQL> CONNECT / AS SYSDBA
SQL> @utlrp.sql
#升级检查
su - grid
$ORACLE_HOME/OPatch/opatch lsinv
su - oracle
sqlplus / as sysdba
set line 150
col ACTION_TIME for a30
col ACTION for a8
col NAMESPACE for a8
col VERSION for a10
col BUNDLE_SERIES for a5
col COMMENTS for a20
select * from dba_registry_history;
#修改数据文件的大小
alter database datafile '+SYSTEM/hisdb/datafile/users.259.916684405' resize 10G;
alter database datafile '+SYSTEM/hisdb/datafile/undotbs1.258.916684405' resize 10G;
alter database datafile '+SYSTEM/hisdb/datafile/sysaux.257.916684405' resize 10G;
alter database datafile '+SYSTEM/hisdb/datafile/system.256.916684403' resize 10G;
alter database datafile '+SYSTEM/hisdb/datafile/undotbs2.265.916684539' resize 10G;