虚拟机搭建CentOS 7.x下Oracle 11g RAC 集群:安装前的初始化工作(三)

曾航
2023-12-01

安装前,我们需要对两台服务器进行初始化操作,两台执行的脚本均一致,各位可以根据具体的情况增加或者删除脚本内的内容,两台都要执行哦~

1) 创建用户及文件夹

这边我们直接俩脚本搞完。

------Create users and groups-------
#!/bin/bash
groupadd -g 200 oinstall
groupadd -g 201 dba
groupadd -g 202 oper
groupadd -g 203 asmadmin
groupadd -g 204 asmoper
groupadd -g 205 asmdba
useradd  -u 200 -g oinstall -G dba,asmdba,oper oracle
useradd  -u 201 -g oinstall -G asmadmin,asmdba,asmoper,oper,dba grid
[root@rac1 /]# id oracle
uid=200(oracle) gid=200(oinstall) groups=200(oinstall),201(dba),202(oper),205(asmdba)
[root@rac1 /]# id grid
uid=201(grid) gid=200(oinstall) groups=200(oinstall),201(dba),202(oper),203(asmadmin),204(asmoper),205(asmdba)
------Create Directories------
#!/bin/bash
#1、Create 'Oracle inventory'
mkdir -p /u01/app/oraInventory
chown -R grid:oinstall /u01/app/oraInventory/
chmod -R 775 /u01/app/oraInventory/

#2、Create 'Grid Infrastructure BASE'
mkdir -p /u01/app/grid
chown -R grid:oinstall /u01/app/grid
chmod -R 775 /u01/app/grid

#3、Create 'Grid Infrastructure Home'
mkdir -p /u01/app/11.2.0.4/grid
chown -R grid:oinstall /u01/app/11.2.0.4/grid/
chmod -R 775 /u01/app/11.2.0.4/grid/

#4、Create ‘Oracle Base’
mkdir -p /u01/app/oracle
mkdir -p /u01/app/oracle/cfgtoollogs
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app/oracle

#5、Create ‘Oracle Rdbms Home’
mkdir -p /u01/app/oracle/product/11.2.0.4/db_1
chown -R oracle:oinstall /u01/app/oracle/product/11.2.0.4/db_1
chmod -R 775 /u01/app/oracle/product/11.2.0.4/db_1

创建完成之后,重置oracle及grid用户的密码

#密码均为1,这边我们测试可以这么设置哈,正式环境还是别了~
[root@rac1 /]# passwd grid 
Changing password for user grid.
New password: 
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@rac1 /]# passwd oracle
Changing password for user oracle.
New password: 
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.

检查文件夹权限

[root@rac1 u01]# ll
total 0
drwxr-xr-x 6 root   root     68 Feb 18 14:57 app
drwxrwxr-x 2 grid   oinstall  6 Feb 18 14:57 gridinstall
drwxrwxr-x 2 oracle oinstall  6 Feb 18 14:57 oracleinstall
[root@rac1 u01]# cd app/
[root@rac1 app]# ll
total 0
drwxr-xr-x 3 root   root     18 Feb 18 14:57 11.2.0.4
drwxrwxr-x 2 grid   oinstall  6 Feb 18 14:57 grid
drwxrwxr-x 4 oracle oinstall 40 Feb 18 14:57 oracle
drwxrwxr-x 2 grid   oinstall  6 Feb 18 14:57 oraInventory
[root@rac1 app]# cd 11.2.0.4/
[root@rac1 11.2.0.4]# ll
total 0
drwxrwxr-x 2 grid oinstall 6 Feb 18 14:57 grid

2)重启udev服务,更改/dev/dm-*权限。双节点均需要执行

创建更改权限脚本,重启udev服务

[root@rac1 rules.d]# cat /etc/udev/rules.d/99-asmmultipath.rules 
#!/bin/bash
KERNEL=="dm-[3-9]", OWNER="grid", GROUP="asmadmin", MODE="0660"
[root@rac1 rules.d]# systemctl restart systemd-udev-trigger.service // 重启服务
[root@rac1 rules.d]# ll /dev/dm-*
brw-rw---- 1 root disk     253, 0 Feb 18 15:06 /dev/dm-0
brw-rw---- 1 root disk     253, 1 Feb 18 15:06 /dev/dm-1
brw-rw---- 1 root disk     253, 2 Feb 18 15:06 /dev/dm-2
brw-rw---- 1 grid asmadmin 253, 3 Feb 18 15:06 /dev/dm-3
brw-rw---- 1 grid asmadmin 253, 4 Feb 18 15:06 /dev/dm-4
brw-rw---- 1 grid asmadmin 253, 5 Feb 18 15:06 /dev/dm-5
brw-rw---- 1 grid asmadmin 253, 6 Feb 18 15:06 /dev/dm-6
brw-rw---- 1 grid asmadmin 253, 7 Feb 18 15:06 /dev/dm-7
brw-rw---- 1 grid asmadmin 253, 8 Feb 18 15:06 /dev/dm-8
brw-rw---- 1 grid asmadmin 253, 9 Feb 18 15:06 /dev/dm-9

3) 修改内核参数

[root@rac1 /]# vim /etc/sysctl.conf 
......
#添加以下内容
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 2147483648
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 = 1048576
[root@rac1 /]# sysctl -p
执行生效
[root@rac1 /]# vim /etc/security/limits.conf
......
#添加以下内容
#modify for oracle
oracle  soft   nproc   16384
oracle  hard   nproc   16384
oracle  soft   nofile  1024
oracle  hard   nofile  65536
oracle  soft   stack   10240
oracle  hard   stack   32768

#modify for grid
grid    soft   nproc   16384
grid    hard   nproc   16384
grid    soft   nofile  1024
grid    hard   nofile  65536
grid    soft   stack   10240
grid    hard   stack   32768

4) 修改用户环境变量

[grid@rac1 ~]$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export EDITOR=vi
#这边的SID要求不一样,rac2这种可以直接设置为+ASM2
export ORACLE_SID=+ASM1
export ORACLE_BASE=/u01/app/grid
export ORACLE_HOME=/u01/app/11.2.0.4/grid
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export THREADS_FLAG=native
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin
umask 022
[oracle@rac1 ~]$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

export EDITOR=vi
#这边的SID要求不一样,rac2这种可以直接设置为racdb2
export ORACLE_SID=racdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:/bin:/usr/bin:/usr/sbin:/usr/local/bin
umask 022

5)创建vip

创建vip的说法众说纷纭,实际测试,即使不创建也是可以的,这边为了大家多方测试成功,也贴一下手动创建的方式,创建vip的方法也有很多种,这种相对而言很简单,只需要更改NAME、DEVICE等参数即可。

按照我们上面的规划IP地址进行操作
[root@rac1 /]#  cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33:1
[root@rac1 /]#  vim /etc/sysconfig/network-scripts/ifcfg-ens33:1
[root@rac1 network-scripts]# cat  ifcfg-ens33:1
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33:1
UUID=e79a2bb5-28d2-4a04-ba22-8bdac809a65c
DEVICE=ens33:1
ONBOOT=yes
IPADDR=192.168.8.101
PREFIX=24
GATEWAY=192.168.8.99
DNS1=223.5.5.5
DOMAIN=223.6.6.6
IPV6_PRIVACY=no
[root@rac1 network-scripts]# systemctl restart  netwo
[root@rac1 network-scripts]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.1  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::91f1:ff20:cb81:6b18  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:f1:68:f5  txqueuelen 1000  (Ethernet)
        RX packets 35371  bytes 33436712 (31.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12222  bytes 1313712 (1.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.101  netmask 255.255.255.0  broadcast 192.168.8.255
        ether 00:0c:29:f1:68:f5  txqueuelen 1000  (Ethernet)

ens34: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.1.101  netmask 255.255.255.0  broadcast 10.10.1.255
        inet6 fe80::a0c2:1fda:518c:565  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:f1:68:ff  txqueuelen 1000  (Ethernet)
        RX packets 108  bytes 9936 (9.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 25  bytes 1958 (1.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 72  bytes 6120 (5.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 6120 (5.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

双节点配置/etc/hosts

[root@rac1 /]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
#public ip
192.168.8.1  rac1
192.168.8.2  rac2

#priv ip 
10.10.1.101  rac1-priv
10.10.1.202  rac2-priv 

#vip
192.168.8.101   rac1-vip
192.168.8.202   rac2-vip

#scan 
192.168.8.100   rac-scan

6) 配置完成之后,关闭双节点防火墙、NTP服务、SElinux等。

-----关闭防火墙
[root@rac1 /]# systemctl status firewalld 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-02-18 15:40:39 CST; 19s ago
     Docs: man:firewalld(1)
 Main PID: 56578 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─56578 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Feb 18 15:40:39 rac1 systemd[1]: Starting firewalld - dynamic firewall daemon...
Feb 18 15:40:39 rac1 systemd[1]: Started firewalld - dynamic firewall daemon.
[root@rac1 /]# systemctl stop firewalld 
[root@rac1 /]# systemctl disable firewalld 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

-----关闭Selinux
[root@rac1 /]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

[root@rac1 /]# getenforce 
Disabled

-----关闭NTP服务[默认应该是不开启的,我这边之前做了一些配置所以开了]
[root@rac1 /]# systemctl status  ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-02-18 15:43:52 CST; 25s ago
 Main PID: 57001 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─57001 /usr/sbin/ntpd -u ntp:ntp -g

Feb 18 15:43:52 rac1 ntpd[57001]: Listen normally on 6 lo ::1 UDP 123
Feb 18 15:43:52 rac1 ntpd[57001]: Listen normally on 7 ens33 fe80::91f1:ff20:cb81:6b18 UDP 123
Feb 18 15:43:52 rac1 ntpd[57001]: Listen normally on 8 ens34 fe80::a0c2:1fda:518c:565 UDP 123
Feb 18 15:43:52 rac1 ntpd[57001]: Listening on routing socket on fd #25 for interface updates
Feb 18 15:43:57 rac1 ntpd[57001]: 0.0.0.0 c016 06 restart
Feb 18 15:43:57 rac1 ntpd[57001]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Feb 18 15:43:57 rac1 ntpd[57001]: 0.0.0.0 c011 01 freq_not_set
Feb 18 15:44:03 rac1 ntpd[57001]: 0.0.0.0 c61c 0c clock_step -7.322648 s
Feb 18 15:43:55 rac1 ntpd[57001]: 0.0.0.0 c614 04 freq_mode
Feb 18 15:43:58 rac1 ntpd[57001]: 0.0.0.0 c618 08 no_sys_peer
[root@rac1 /]# systemctl stop  ntpd
[root@rac1 /]# systemctl disable  ntpd
Removed symlink /etc/systemd/system/multi-user.target.wants/ntpd.service.
[root@rac1 /]# mv /etc/ntp.conf /etc/ntp.confbak //这一步肯定要执行哈,不然后期检查会出错。

至此,我们初始化工作已经完成了。

转载时,各位小伙伴记得注明出处哦~~关注一下博主吧

 类似资料: