Oracle RAC 12CR2
oracle rac常用软件配置
screen常用命令
- 创建screen会话
screen -S lnmp
- 重新连接SSH
screen -r lnmp
- 查看对应会话的session id
screen -ls
- 异常退出,提示状态为Attached,重连
screen -D -r lnmp
在screen配置文件/etc/screenrc最后添加下面一行:
logfile /tmp/screenlog_%t.log
%t是指window窗口的名称,对应screen的-t参数。所以我们启动screen的时候要指定窗口的名称,例如:
screen -L -t window1 -dmS test
意思是启动test会话,test会话的窗口名称为window1。屏幕日志记录在/tmp/screenlog_window1.log
。如果启动的时候不加-L参数,在screen session下按ctrl+a H,日志也会记录在/tmp/screenlog_window1.log
。
sshd超时设置
[root@sjglcbr16 ~]# vi /etc/ssh/sshd_config
[root@sjglcbr16 ~]# vi /etc/profile
[root@sjglcbr16 ~]# source /etc/profile
[root@sjglcbr16 ~]# systemctl restart sshd
[root@sjglcbr16 ~]# echo $TMOUT
iscsi storage设置
- database:
yum -y install targetcli
targetcli
/backstores/block create disk1 /dev/sdb
/iscsi> create
targetcli /iscsi/iqn.2019-10xxxx/tpg1/lun1 create /backstores/block/disk1
targetcli /iscsi/iqn.20...xxx/tpg1/acls create iqn.2019-10xxx.xxx
存储端使用acl(访问控制列表)控制客户端连接,客户端使用默认配置,无需更改
- client:
yum -y install iscsi-initiator-utils
cat /etc/iscsi/initiatorname.iscsi
iscsiadm -m discovery -t st -p 10.139.7.66
iscsiadm -m node -l
lsblk
tree /var/lib/iscsi
mkfs.xfs /dev/sdb
mount /dev/sdb /mnt/share
iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.sjglcbr15.x8664:sn.a8acc93c3cb3 -u //卸载
iscsiadm -m session -P 3 | grep Attached //验证
iscsiadm -m node -o delete -T iqn.2019-01.com.example:node21 //删配置
dnf配置
yum install python3
yum install dnf
strace + dnf xxx xxx
查看命令执行具体细节
环境检查
lsb_release -a
uname -a
查看路由表
-
查看:
ip route show|column -t
-
添加默认:
ip route add default via 10.254.10.254 dev enp129s0f0
查看已安装桌面环境
ps -A | egrep -i "gnome|kde|mate|cinnamon|lx|xfce|jwm"
修改主机名
hostnamectl set-hostname node1
防火墙与SELINUX
vim /etc/selinux/config
SELINUX=disabled
systemctl stop firewalld
chkconfig firewalld off
reboot
yum包准备
# Centos7.x
yum install binutils compat-libcapl compat-libstdc++-33 compat-libstdc++-33.i686 gcc gcc-c++ glibc glibc.i686 glibc-devel glibc-devel.i686 ksh libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel libstdc++-devel.i686 libaio libaio.i686 libaio-devel libaio-devel.i686 libXext libXext.i686 libXtst libXtst.i686 libX11 libX11.i686 libXau
libXau.i686 libxcb libxcb.i686 libXi libXi.i686 make sysstat unixODBC unixODBC-devel
yum install unzip vim tree screen net-tools readline rlwrap
readline和rlwrap方便在sql和rman中上下翻命令,装好后建议在用户环境变量中添加别名方便使用:
cat << EOF >> /home/oracle/.bash_profile
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
EOF
- 如果系统为Oracle Linux7.8版本,则使用以下命令安装包
yum install oracle-rdbms-server-12cR1-preinstall
- el7.x通用epel源
yum install epel-release
or
rpm -ivh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-13.noarch.rpm
DNS解析
可使用bind或dnsmasq,以下使用dnsmasq配置
yum install dnsmasq
vim /etc/dnsmasq.conf
addn-hosts=/etc/racdns
vim /etc/racdns
#for scan
192.168.100.115 scan scan.orcl.rac
192.168.100.116 scan scan.orcl.rac
192.168.100.117 scan scan.orcl.rac
vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 127.0.0.1
search orcl.rac
nameserver 8.8.8.8
为防止/etc/resolve.conf
在系统重启时被修改,执行下面命令:
chattr +i /etc/resolv.conf
vim /etc/hosts
#for node1
192.168.100.111 node1 node1.orcl.rac
192.168.101.111 node1-priv node1-priv.orcl.rac
192.168.100.112 node1-vip node1-vip.orcl.rac
#for node2
192.168.100.113 node2 node2.orcl.rac
192.168.101.113 node2-priv node2-priv.orcl.rac
192.168.100.114 node2-vip node2-vip.orcl.rac
#for scan
#192.168.100.115 scan scan.orcl.com
systemctl enable dnsmasq
systemctl start dnsmasq
如果使用bind,则配置文件说明如下
vim xiaogan.cn.zone
修改如下:配置信息;#注释信息
1 $TTL 1D
#设置有效地址解析记录的默认缓存时间,默认为1天也就是1D。
2 xiaogan.cn. IN SOA dns.xiaogan.cn. root.xiaogan.cn. (
#起始授权记录SOA 定义了域的全局参数,进行整个域管理设置,一个区域文件只允许存在唯一的SOA记录
#原来的@表示当前的域xiaogan.cn.,为方便大家记忆,我们这里,直接写成xiaogan.cn.
#设置SOA记录为:dns.xuegod.cn.
#在此配置文件中写域名时,都把根. 也要写上。
#域管理邮箱root.xuegod.cn.0由于@有其他含义,所以用“.”代替@。
3 0 ; serial
#更新序列号,用于标示数据库的变换,可以在10位以内,如果存在辅助DNS区域,建议每次更新完数据库,手动加1.
4 1D ; refresh
#刷新时间,从域名服务器更新该地址数据库文件的间隔时间,默认为1天
5 1H ; retry
#重试延时,从域名服务器更新地址数据库失败以后,等待多长时间,默认为为1小时
6 1W ; expire
#到期,失效时间,超过该时间仍无法更新地址数据库,则不再尝试,默认为一周
7 3H ) ; minimum
#设置无效地址解析记录(该数据库中不存在的地址)默认缓存时间。设置无效记录,最少缓存时间为3小时
8 xiaogan.cn. NS dns.xiaogan.cn.
#域名服务器记录,指定该域名xiaogan.cn由dns.xiaogan.cn进行分析,每个区在区根处至少包含一个NS记录.
9 dns.xiaogan.cn. A 192.168.31.1
#把FQDN(完全合格域名标识)映射到IP地址
#即把 dns.xiaogan.cn 映射到 192.168.64.1 位置
10 www.xiaogan.cn. A 192.168.31.1
#同上
11 www2.xiaogan.cn. CNAME www.xiaogan.cn.
#定义别名 www.xiaogan.cn 的别名为 www2.xiaogan.cn
添加与修改配置文件
- 添加用户和权限
- 修改密码
- 创建所需文件夹及授权
- 修改系统文件配置
注意以下内容需要在node2节点进行3处修改:grid(
ORACLE_SID
)和Oracle(ORACLE_SID
),ORACLE_HOSTNAME
groupadd -g 54321 oinstall
groupadd -g 54328 asmadmin
groupadd -g 54325 asmdba
groupadd -g 54329 asmoper
groupadd -g 54322 dba
groupadd -g 54323 oper
useradd -u 54322 -g oinstall -G dba,asmadmin,asmdba,asmoper -d /home/grid -s /bin/bash -c "grid Infrastructure Owner" grid
echo "grid" | passwd --stdin grid
echo 'export PS1="`/bin/hostname -s`-> "'>> /home/grid/.bash_profile
echo "export TMP=/tmp">> /home/grid/.bash_profile
echo 'export TMPDIR=$TMP'>>/home/grid/.bash_profile
echo "export ORACLE_SID=+ASM1">> /home/grid/.bash_profile
echo "export ORACLE_BASE=/u01/app/grid">> /home/grid/.bash_profile
echo "export ORACLE_HOME=/u01/app/12.2.01/grid">> /home/grid/.bash_profile
echo "export ORACLE_TERM=xterm">> /home/grid/.bash_profile
echo "export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'" >> /home/grid/.bash_profile
echo 'export TNS_ADMIN=$ORACLE_HOME/network/admin' >> /home/grid/.bash_profile
echo 'export PATH=/usr/sbin:$PATH'>> /home/grid/.bash_profile
echo 'export PATH=$ORACLE_HOME/bin:$PATH'>> /home/grid/.bash_profile
echo 'export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib '>> /home/grid/.bash_profile
echo 'export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib '>> /home/grid/.bash_profile
echo "export EDITOR=vi" >> /home/grid/.bash_profile
echo "export LANG=en_US" >> /home/grid/.bash_profile
echo "export NLS_LANG=american_america.AL32UTF8" >> /home/grid/.bash_profile
echo "umask 022">> /home/grid/.bash_profile
useradd -u 54321 -g oinstall -G dba,oper,asmdba -d /home/oracle -s /bin/bash -c "Oracle Software Owner" oracle
echo "oracle" | passwd --stdin oracle
echo 'export PS1="`/bin/hostname -s`-> "'>> /home/oracle/.bash_profile
echo "export TMP=/tmp">> /home/oracle/.bash_profile
echo 'export TMPDIR=$TMP'>>/home/oracle/.bash_profile
echo "export ORACLE_HOSTNAME=node1.orcl.rac">> /home/oracle/.bash_profile
echo "export ORACLE_SID=devdb1">> /home/oracle/.bash_profile
echo "export ORACLE_BASE=/u01/app/oracle">> /home/oracle/.bash_profile
echo 'export ORACLE_HOME=$ORACLE_BASE/product/12.2.01/db_1'>> /home/oracle/.bash_profile
echo "export ORACLE_UNQNAME=devdb">> /home/oracle/.bash_profile
echo 'export TNS_ADMIN=$ORACLE_HOME/network/admin' >> /home/oracle/.bash_profile
echo "export ORACLE_TERM=xterm">> /home/oracle/.bash_profile
echo 'export PATH=/usr/sbin:$PATH'>> /home/oracle/.bash_profile
echo 'export PATH=$ORACLE_HOME/bin:$PATH'>> /home/oracle/.bash_profile
echo 'export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib '>> /home/oracle/.bash_profile
echo 'export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib '>> /home/oracle/.bash_profile
echo "export EDITOR=vi" >> /home/oracle/.bash_profile
echo "export LANG=en_US" >> /home/oracle/.bash_profile
echo "export NLS_LANG=american_america.AL32UTF8" >> /home/oracle/.bash_profile
echo "export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss'" >> /home/oracle/.bash_profile
echo "umask 022">> /home/oracle/.bash_profile
mkdir -p /u01/app/grid
mkdir -p /u01/app/12.2.01/grid
mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01
chown -R grid:oinstall /u01/app/grid
chown -R grid:oinstall /u01/app/12.2.01
chmod -R 775 /u01
cp /etc/security/limits.conf /etc/security/limits.conf.bak
echo "oracle soft nproc 2047" >>/etc/security/limits.conf
echo "oracle hard nproc 16384" >>/etc/security/limits.conf
echo "oracle soft nofile 1024" >>/etc/security/limits.conf
echo "oracle hard nofile 65536" >>/etc/security/limits.conf
echo "oracle soft stack 10240" >>/etc/security/limits.conf
echo "oracle hard stack 10240" >>/etc/security/limits.conf
echo "grid soft nproc 2047" >>/etc/security/limits.conf
echo "grid hard nproc 16384" >>/etc/security/limits.conf
echo "grid soft nofile 1024" >>/etc/security/limits.conf
echo "grid hard nofile 65536" >>/etc/security/limits.conf
echo "grid soft stack 10240" >>/etc/security/limits.conf
echo "grid hard stack 10240" >>/etc/security/limits.conf
echo "oracle soft memlock 3145728" >>/etc/security/limits.conf
echo "oracle hard memlock 3145728" >>/etc/security/limits.conf
cp /etc/pam.d/login /etc/pam.d/login.bak
echo "session required /lib/security/pam_limits.so" >>/etc/pam.d/login
echo "session required pam_limits.so" >>/etc/pam.d/login
cp /etc/profile /etc/profile.bak
echo 'if [ $USER = "oracle" ]||[ $USER = "grid" ]; then' >> /etc/profile
echo 'if [ $SHELL = "/bin/ksh" ]; then' >> /etc/profile
echo 'ulimit -p 16384' >> /etc/profile
echo 'ulimit -n 65536' >> /etc/profile
echo 'else' >> /etc/profile
echo 'ulimit -u 16384 -n 65536' >> /etc/profile
echo 'fi' >> /etc/profile
echo 'fi' >> /etc/profile
cp /etc/sysctl.conf /etc/sysctl.conf.bak
echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
echo "fs.file-max = 6815744" >> /etc/sysctl.conf
echo "kernel.shmall = 67108864" >> /etc/sysctl.conf
echo "kernel.shmmax = 274877906944" >> /etc/sysctl.conf
echo "kernel.shmmni = 4096" >> /etc/sysctl.conf
echo "kernel.sem = 250 32000 100 128" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 9000 65500" >> /etc/sysctl.conf
echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.rmem_max = 4194304" >> /etc/sysctl.conf
echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.wmem_max = 1048586" >> /etc/sysctl.conf
echo "net.ipv4.tcp_wmem = 262144 262144 262144" >> /etc/sysctl.conf
echo "net.ipv4.tcp_rmem = 4194304 4194304 4194304" >> /etc/sysctl.conf
sysctl -p
or
ipcs -l
数值说明
shmmax:8G*1024*1024*1024=8589934592
shmall:(shmmax) / 4096
根据实际情况配置swap分区
free -g
dd if=/dev/zero of=/tmp/swap bs=1MB count=8192
(8G)
or
dd if=/dev/zero of=/tmp/swap bs=1G count=64
(64G)
mkswap /tmp/swap
swapon /tmp/swap
修改启动自动挂载配置文件fstab
vim /etc/fstab
tmpfs /dev/shm tmpfs defaults,size=8192M 0 0
/tmp/swap swap swap defaults 0 0
mount -o remount /dev/shm
shm建议8G,swap建议16G,若超过建议标准可根据实际情况按需配置
umount说明
fuser命令,确认有哪些进程在占用该 [目录/文件]
[root@localhost /]# fuser -mv /data1/img
/data1/img: 1757c(mysql)
上面查看发现是pid为1757的mysql用户起的进程在占用该目录。
-m,--mount show all processes using the named filesystems or block device
-v,--verbose verbose output
-c 包含File的文件系统中关于任何打开的文件的报告
-u 为进程号后圆括号中的本地进程提供登录名
配ssh互信,双节点双用户执行
- node1 and node2
- userid =
oracle
andgrid
env|grep ORA
cd /home/[$userid]
mkdir .ssh && chmod 700 .ssh
ssh-keygen -t rsa
ssh-keygen -t dsa
- 以下在其一节点执行即可
cat ~/.ssh/id_rsa.pub >> ./.ssh/authorized_keys
cat ~/.ssh/id_dsa.pub >> ./.ssh/authorized_keys
ssh node2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh node2 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys node2:~/.ssh/authorized_keys
ASM磁盘规划,使用最低要求
ASM磁盘名称 | 磁盘组名称 | 大小 | 用途 | 备注 |
/dev/asm-diskc
/dev/asm-diskd /dev/asm-diske /dev/asm-diskf /dev/asm-diskg |
OCR | 10G | OCR+VOTINGDISK | 最少1.4G(组high冗余),也可以组其它冗余方式,但要相应的调整MGMT磁盘组大小。 |
/dev/asm_diski /dev/asm_diskh | MGMT | 120G | MGMT | 最少37.6G normal冗余:75.5 Ghigh冗余:113.4G flex冗余:75.5G |
/dev/asm_diskj /dev/asm-diskk | DATA | 60G | 存储数据库数据文件 | |
/dev/asm_diskl /dev/asm-diskm | FRA | 50G | 快速恢复区 |
- 以下可直接生成所需文件,注意修改盘符
for i in c d e f g h i;
do
echo "KERNEL==\"sd*\",ENV{DEVTYPE}==\"disk\",SUBSYSTEM==\"block\",PROGRAM==\"/usr/lib/udev/scsi_id -g -u -d \$devnode\",RESULT==\"`/usr/lib/udev/scsi_id -g -u /dev/sd$i`\",RUN+=\"/bin/sh -c 'mknod /dev/asm-disk$i b \$major \$minor; chown grid:asmadmin /dev/asm-disk$i; chmod 0660 /dev/asm-disk$i'\"" >> /etc/udev/rules.d/99-oracle-asmdevices.rules;
done
cat /etc/udev/rules.d/99-oracle-asmdevices.rules
/sbin/udevadm trigger --type=devices --action=change
/sbin/udevadm control --reload
ls -l /dev/asm-disk*
- 磁盘必须fdisk 或者parted 分区,但是不用创建文件系统,不用mkfs格式化
- 如果后续安装中出现candidate disk无法show出,可以
dd if=/dev/zero of=/dev/sd*1
来初始化磁盘。 - 如果被用于ASM的磁盘以前曾经被使用,现在使用时提示是备用无法使用时,可以清空磁盘头
dd if=/dev/zero of=/dev/sd*1 bs=512 count=10
图形化安装
上传安装介质到节点操作系统上,包括gird,database
oracle集群软件:linuxx64_12201_grid_home.zip
oracle database:linuxx64_12201_database.zip
- 在已上传软件的node上执行
su – grid
cd /soft
- 建议解压到grid_home目录,方便后续操作
unzip linuxx64_12201_grid_home.zip -d /u01/app/12.2.01/grid
- 检查先决条件
/u01/app/12.2.01/grid/runcluvfy.sh stage -pre crsinst -n node1,node2 -fixup -verbose
- 检查全部通过后执行
/u01/app/12.2.01/grid/gridSetup.sh
- 关于图形化安装过程可参考《KunLun 开放架构小型机 数据库最佳实践(Oracle RAC 12c R2) 03.pdf》和《FusionCube DB 3.1 数据库最佳实践 03 (Oracle RAC 12c R2).pdf》
- 如果需要两个节点上都卸载root.sh,可以通过下面的命令卸载
/u01/app/11.2.0/grid/crs/install/rootcrs.pl -deconfig -force
grid图形化安装完成后检查CRS状态
crs_stat -t
或
crsctl status res -t
也可
[root@dbn01 ~]# /u01/app/12.2.01/grid/bin/crsctl status res -t
创建ASM磁盘组
[grid@node1 ]$ asmca
选择diskgroup,分别创建[dgsystem],[dgrecover]
磁盘组
- database客户端安装注意,请检查下oracle 和grid 用户的属组情况,正确的是:
[root@node1 scripts]# groups oracle
oracle : oinstall dba asmdba oper
[root@node1 scripts]# groups grid
grid : oinstall dba asmadmin asmdba asmoper
1、如果 oracle 用户不属于 oper 和asmdba组,后续安装会报错。
请用下列命令添加:
usermod -a -G oper oracle
usermod -a -G asmdba oracle
su - oracle
cd /soft/database
./runInstaller
2、图形化完成后进行建库操作
[oracle@node1 ]$ dbca
3、关于图形化安装过程可参考《KunLun 开放架构小型机 数据库最佳实践(Oracle RAC 12c R2) 03.pdf》和《FusionCube DB 3.1 数据库最佳实践 03 (Oracle RAC 12c R2).pdf》
关于数据库优化
1、使用grid查看磁盘组状态
语法结构:
$srvctl status diskgroup -diskgroup <dg_name> [-all] [-verbose]
示例:
$srvctl status diskgroup -diskgroup datadg -detail
2、关闭DRM
- 查看DRM默认值
SQL>
SELECT x.ksppinm as name,
y.ksppstvl as value,
y.ksppstdf as isdefault,
x.ksppdesc describ
FROM SYS.x$ksppi x, SYS.x$ksppcv y
WHERE x.inst_id = USERENV('Instance')
AND y.inst_id = USERENV('Instance')
AND x.indx = y.indx
AND x.ksppinm in ('_gc_policy_time', '_gc_undo_affinity');
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
ISDEFAULT
---------
DESCRIB
--------------------------------------------------------------------------------
_gc_undo_affinity
TRUE
TRUE
if TRUE, enable undo affinity
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
ISDEFAULT
---------
DESCRIB
--------------------------------------------------------------------------------
_gc_policy_time
20
TRUE
how often to make object policy decisions in minutes
- 关闭方法
-- 修改默认值为false
SQL> alter system set "_gc_undo_affinity"=FALSE scope=spfile sid='*';
SQL> alter system set "_gc_policy_time"=0 scope=spfile sid='*';
# 重启数据库实例
[oracle@rac01 ~]$ srvctl stop database -d cjcdb
[oracle@rac01 ~]$ srvctl start database -d cjcdb
[oracle@rac01 ~]$ srvctl status database -d cjcdb -v
Instance cjcdb1 is running on node rac01. Instance status: Open.
Instance cjcdb2 is running on node rac02. Instance status: Open.
-- 再次查看值状态
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
ISDEFAULT
---------
DESCRIB
--------------------------------------------------------------------------------
_gc_undo_affinity
FALSE
FALSE
if TRUE, enable undo affinity
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
ISDEFAULT
---------
DESCRIB
--------------------------------------------------------------------------------
_gc_policy_time
0
FALSE
how often to make object policy decisions in minutes
3、关闭审计
SQL> alter system set audit_trail=NONE scope=spfile sid='*';