Red Hat Enterprise Linux 7.9安装Oracle 11.2.0.4单实例数据库-图文详解
一、系统配置
系统版本 | 主机名 | DB版本 | DB名 | 实例名 | Public-IP | 内存大小 |
---|---|---|---|---|---|---|
Redhat7.9 | lemon | Enterprise 11.2.0.4 | lemon | lemon | 192.168.127.80 | 8G |
1、前提配置
需提前配置好网络并上传安装包及系统镜像到
/soft
目录下
##网络配置
nmcli connection modify ens33 ipv4.addresses 192.168.127.80/24 ipv4.gateway 192.168.127.1 ipv4.method manual autoconnect yes
2、配置主机名和hosts文件
##配置主机名
hostnamectl set-hostname lemon
##配置hosts文件
cat <<EOF>>/etc/hosts
#Public IP
192.168.127.80 lemon
EOF
3、关闭防火墙和selinux
#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service
#关闭selinux
sudo sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config && sudo setenforce 0
4、配置yum源并安装依赖包
##挂载镜像
mount /soft/rhel* /mnt
##将原有的repo文件移动到新位置
mkdir -p /etc/yum.repos.d/yum_bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/yum_bak
##编辑新的repo文件
cat <<EOF>>/etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
enabled=1
EOF
##清理缓存、更新缓存、查看软件仓库列表
yum clean all
yum makecache
yum repolist all
##安装相关依赖
yum install -y bc \
binutils \
compat-libcap1 \
compat-libstdc++-33 \
gcc \
gcc-c++ \
elfutils-libelf \
elfutils-libelf-devel \
glibc \
glibc-devel \
ksh \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
libxcb \
libX11 \
libXau \
libXi \
libXtst \
libXrender \
libXrender-devel \
make \
net-tools \
nfs-utils \
smartmontools \
sysstat \
e2fsprogs \
e2fsprogs-libs \
fontconfig-devel \
expect \
unzip \
openssh-clients \
readline* \
tigervnc* \
psmisc --skip-broken
##检查哪些没安装成功
echo "bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXtst libXrender libXrender-devel make net-tools nfs-utils smartmontools sysstat e2fsprogs e2fsprogs-libs fontconfig-devel expect unzip openssh-clients psmisc" | xargs -n 1 rpm -q | grep -E "未安装|not installed" || echo "所有指定软件包已安装成功"
##单独安装rpm包,用于SQLPLUS命令行试可上下切换命令
rpm -ivh /soft/compat-libstdc++-33-3.2.3-72.el7.x86_64.rpm
5、关闭透明大页和NUMA
# 1. 修改 GRUB 配置
sed -i 's/quiet/quiet transparent_hugepage=never numa=off/' /etc/default/grub
# 2. 重新生成 GRUB 配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg
# 3. 重启后检查是否生效
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /proc/cmdline
6、配置 avahi-deamon和NOZEROCONF
##关闭
systemctl stop avahi-daemon.socket
systemctl stop avahi-daemon.service
systemctl disable avahi-daemon.service
systemctl disable avahi-daemon.socket
##关闭 NOZEROCONF
cat <<EOF >>/etc/sysconfig/network
NOZEROCONF=yes
EOF
7、配置 pam.d
cat <<EOF>>/etc/pam.d/login
session required pam_limits.so
session required /lib64/security/pam_limits.so
EOF
8、配置 /dev/shm
cp /etc/fstab /etc/fstab_bak
memTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}')
shmTotal=$(df -k /dev/shm | awk 'NR==2 {print $2}')
fstab_line=$(grep -n "/dev/shm" /etc/fstab)
if [ -z "$fstab_line" ]; then
echo "tmpfs /dev/shm tmpfs size=${memTotal}k 0 0" >> /etc/fstab
else
if [ "$shmTotal" -lt "$memTotal" ]; then
sed -i "/\/dev\/shm/d" /etc/fstab
echo "tmpfs /dev/shm tmpfs size=${memTotal}k 0 0" >> /etc/fstab
fi
systemctl daemon-reload
mount -o remount /dev/shm
fi
9、配置系统参数文件
## 网卡名称需根据实际情况需改
PublicFName=ens33
memTotal=$(grep MemTotal /proc/meminfo | cut -d ' ' -f 2)
shmall=$((memTotal / 4))
shmall=$((shmall > 2097152 ? shmall : 2097152))
shmmax=$((memTotal * 1024 - 1))
shmmax=$((shmmax < 4294967295 ? 4294967295 : shmmax))
{
echo "fs.aio-max-nr = 1048576"
echo "fs.file-max = 6815744"
echo "kernel.shmall = $shmall"
echo "kernel.shmmax = $shmmax"
echo "kernel.shmmni = 4096"
echo "kernel.sem = 250 32000 100 128"
echo "net.ipv4.ip_local_port_range = 9000 65500"
echo "net.core.rmem_default = 262144"
echo "net.core.rmem_max = 4194304"
echo "net.core.wmem_default = 262144"
echo "net.core.wmem_max = 1048576"
echo "net.ipv4.conf.$PublicFName.rp_filter = 1"
} >> /etc/sysctl.conf
sysctl -p
10、配置系统资源限制
##配置limits.conf
cat <<EOF>>/etc/security/limits.conf
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 32768
oracle soft nproc 16384
oracle hard nproc 16384
oracle hard memlock unlimited
oracle soft memlock unlimited
EOF
11、创建用户和组
/usr/sbin/groupadd -g 54321 oinstall
/usr/sbin/groupadd -g 54322 dba
/usr/sbin/groupadd -g 54323 oper
/usr/sbin/groupadd -g 54324 backupdba
/usr/sbin/groupadd -g 54325 dgdba
/usr/sbin/groupadd -g 54326 kmdba
/usr/sbin/groupadd -g 54330 racdba
/usr/sbin/useradd -u 54321 -g oinstall -G dba,oper,backupdba,dgdba,kmdba,racdba oracle
echo "oracle:oracle" | sudo chpasswd
12、创建安装目录并授权
mkdir -p /u01/app/oracle/product/11.2.0/db
mkdir -p /u01/app/oraInventory
mkdir -p /oradata
mkdir -p /archivelog
chown -R oracle:oinstall /oradata
chown -R oracle:oinstall /archivelog
chown -R oracle:oinstall /u01
chmod -R 775 /u01
13、配置用户环境变量
## 配置 root 用户
cat <<EOF>>/root/.bash_profile
alias so='su - oracle'
export PS1='[\u@\h \w]# '
EOF
## oracle用户环境变量:
cat <<EOF>>/home/oracle/.bash_profile
###################### Oracle Profile ######################
# Oracle Environment Variables
export TMP=/tmp
export TMPDIR=\$TMP
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/db
export ORACLE_HOSTNAME=lemon
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export ORACLE_SID=lemon
export ORADATA_DIR=/oradata
export ARCHIVE_DIR=/archivelog
# Update PATH for Oracle binaries
export PATH=\$ORACLE_HOME/bin:\$ORACLE_HOME/OPatch:/usr/sbin:\$PATH
# Set prompt
export PS1='[\u@\h \w]# '
# Aliases
alias sas='sqlplus / as sysdba'
alias lsnr='lsnrctl status'
#############################################################
EOF
14、关闭RemoveIPC配置
sed -i '/^#RemoveIPC/ a RemoveIPC=no' /etc/systemd/logind.conf && sudo systemctl restart systemd-logind
15、时间同步配置
## 配置 ntpdate 时间同步计划任务:
## 未安装需要手动安装ntpdate
yum install -y ntpdate
## 192.168.118.1为时间服务器IP,每天12点同步系统时间
cat <<EOF>>/var/spool/cron/root
00 00 * * * /usr/sbin/ntpdate -u 192.168.118.1 && /usr/sbin/hwclock -w
EOF
## 查看计划任务
crontab -l
## 手动执行
/usr/sbin/ntpdate -u 192.168.118.1 && /usr/sbin/hwclock -w
##配置-x参数
grep OPTIONS /etc/sysconfig/ntpd
OPTIONS="-x"
/sbin/service ntpd start
16、配置完成,重启主机
##查看selinux
cat /etc/selinux/config或者getenforce或者sestatus
cat /sys/kernel/mm/transparent_hugepage/enabled
cat /proc/cmdline
二、安装数据库软件(图形化安装)
1、安装包授权并解压安装包
chown -R oracle:oinstall /soft
su - oracle -lc "unzip -q /soft/p13390677_112040_Linux-x86-64_1of7.zip -d /soft"
su - oracle -lc "unzip -q /soft/p13390677_112040_Linux-x86-64_2of7.zip -d /soft"
2、开始安装(oracle用户下)
##先打补丁,然后直接开始安装
su - oracle
cd /soft/database
./runInstaller -jreLoc /etc/alternatives/jre_1.8.0
Linux7 安装 Oracle 11GR2 版本,oracle 软件安装过程中报错:ins_emagent.mk,
#需要修改文件 /sysman/lib/ins_emagent.mk来修复(节点一修改即可):
vi $ORACLE_HOME/sysman/lib/ins_emagent.mk
#查找MK_EMAGENT_NMECTL这一行,并在后面加上-lnnz11
#修改完成后点击Retry
Oracle软件安装成功!
2、Oracle软件打补丁
##解压并更新opatch工具
su - oracle -c "opatch version"
su - oracle -c "unzip -q -o /soft/p6880880_112000_Linux-x86-64.zip -d /u01/app/oracle/product/11.2.0/db"
su - oracle -c "opatch version"
##解压补丁包
su - oracle -c "unzip -q -o /soft/p31537677_112040_Linux-x86-64.zip -d /soft"
##执行补丁更新
su - oracle
opatch apply /soft/31537677
##查看补丁情况
opatch lsinventory
补丁安装完成!
三、创建监听
## oracle用户执行
netca
四、创建数据库
dbca
数据库创建成功!
五、数据库参数优化
## 1、优化参数
## open_cursors改成和processes一样大小
alter system set processes=3000 scope=spfile;
alter system set open_cursors=3000 scope=spfile;
alter system set db_files=5000 scope=spfile;
## 2、关闭OCM功能
exec dbms_scheduler.disable('ORACLE_OCM.MGMT_CONFIG_JOB');
exec dbms_scheduler.disable('ORACLE_OCM.MGMT_STATS_CONFIG_JOB');
## 3、关闭一些用不到的自动维护任务
exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto space advisor',operation => NULL,window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'sql tuning advisor',operation => NULL,window_name => NULL);
## 4、密码过期设置
alter profile default limit password_life_time unlimited;
alter profile default limit password_lock_time unlimited;
alter profile default limit password_grace_time unlimited;
alter profile default limit failed_login_attempts unlimited;
## 5、关闭审计
alter system set audit_trail=none scope=spfile;
## 6、开启归档,已开启则忽略
shutdown immediate;
startup mount;
alter system set log_archive_dest_1='location=/archivelog';
alter system archivelog;
alter database open;
## 7、根据需求调整redo
set line222
col MEMBER for a50
select l.group#,l.thread#,l.sequence#,l.bytes/1024/1024 M_B,lf.member from v$log l,v$logfile lf where l.group#=lf.group#;
GROUP# THREAD# SEQUENCE# M_B MEMBER
---------- ---------- ---------- ---------- --------------------------------------------------
3 1 9 200 /oradata/LEMON/onlinelog/o1_mf_3_mnf3xms5_.log
2 1 11 200 /oradata/LEMON/onlinelog/o1_mf_2_mnf3xmrk_.log
1 1 10 200 /oradata/LEMON/onlinelog/o1_mf_1_mnf3xmqh_.log
SQL> show parameter db_create
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string /oradata
db_create_online_log_dest_1 string
db_create_online_log_dest_2 string
db_create_online_log_dest_3 string
db_create_online_log_dest_4 string
db_create_online_log_dest_5 string
SQL> alter system set db_create_online_log_dest_1='/oradata/LEMON/onlinelog/';
System altered.
SQL> show parameter db_create
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string /oradata
db_create_online_log_dest_1 string /oradata/LEMON/onlinelog/
db_create_online_log_dest_2 string
db_create_online_log_dest_3 string
db_create_online_log_dest_4 string
db_create_online_log_dest_5 string
alter database add logfile thread 1 group 4 size 500M;
alter database add logfile thread 1 group 5 size 500M;
##若是想把日志都改为统一大小,需切换日志,等其状态为INACTIVE后,删除重建
## 8、客户端连接兼容性设置
cat <<EOF>>$ORACLE_HOME/network/admin/sqlnet.ora
SQLNET.ALLOWED_LOGON_VERSION_CLIENT = 8
SQLNET.ALLOWED_LOGON_VERSION_SERVER = 8
EOF
## 9、开启大页
-----------------------------------------开启大页脚本内容(直接复制执行)-------------------------------------
cat << 'EOF' > /home/oracle/hugepages_settings.sh
#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
# on Oracle Linux
#
# Note: This script does calculation for all shared memory
# segments available when the script is run, no matter it
# is an Oracle RDBMS shared memory segment or not.
#
# This script is provided by Doc ID 401749.1 from My Oracle Support
# http://support.oracle.com
# Welcome text
echo "
This script is provided by Doc ID 401749.1 from My Oracle Support
(http://support.oracle.com) where it is intended to compute values for
the recommended HugePages/HugeTLB configuration for the current shared
memory segments on Oracle Linux. Before proceeding with the execution please note following:
* For ASM instance, it needs to configure ASMM instead of AMM.
* The 'pga_aggregate_target' is outside the SGA and
you should accommodate this while calculating the overall size.
* In case you changes the DB SGA size,
as the new SGA will not fit in the previous HugePages configuration,
it had better disable the whole HugePages,
start the DB with new SGA size and run the script again.
And make sure that:
* Oracle Database instance(s) are up and running
* Oracle Database 11g Automatic Memory Management (AMM) is not setup
(See Doc ID 749851.1)
* The shared memory segments can be listed by command:
# ipcs -m
Press Enter to proceed..."
read
# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`
if [ -z "$HPG_SZ" ];then
echo "The hugepages may not be supported in the system where the script is being executed."
exit 1
fi
# Initialize the counter
NUM_PG=0
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | cut -c44-300 | awk '{print $1}' | grep "[0-9][0-9]*"`
do
MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
if [ $MIN_PG -gt 0 ]; then
NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
fi
done
RES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`
# An SGA less than 100MB does not make sense
# Bail out if that is the case
if [ $RES_BYTES -lt 100000000 ]; then
echo "***********"
echo "** ERROR **"
echo "***********"
echo "Sorry! There are not enough total of shared memory segments allocated for
HugePages configuration. HugePages can only be used for shared memory segments
that you can list by command:
# ipcs -m
of a size that can match an Oracle Database SGA. Please make sure that:
* Oracle Database instance is up and running
* Oracle Database 11g Automatic Memory Management (AMM) is not configured"
exit 1
fi
# Finish with results
case $KERN in
'2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q` ;
echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
'2.6') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'3.8') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'3.10') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'4.1') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'4.14') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'4.18') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'5.4') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'5.14') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
*) echo "Kernel version $KERN is not supported by this script (yet). Exiting." ;;
esac
# End
EOF
----------------------------------------------------------------------------------------
## 赋权限后执行脚本
chmod +x hugepages_settings.sh
sh /home/oracle/hugepages_settings.sh
## 得到以下内容:Recommended setting: vm.nr_hugepages = 1090
## 将得到的推荐值写入系统参数文件:/etc/sysctl.conf
cat <<EOF>> /etc/sysctl.conf
vm.nr_hugepages = 1090
EOF
##重新生效参数文件
sysctl -p
## 10、设置归档自动清理(root用户下执行即可)
SCRIPTSDIR=/home/oracle/scripts
mkdir -p /home/oracle/scripts/logs
{
echo '#!/bin/bash'
echo 'source ~/.bash_profile'
echo 'systime=`date +"%Y%m%d%H%M%S"`'
echo "rman target / nocatalog msglog ${SCRIPTSDIR}/logs/del_arch_\${systime}.log<<EOF"
echo 'crosscheck archivelog all;'
echo "delete noprompt archivelog until time 'sysdate-3';"
echo "delete noprompt force archivelog until time 'SYSDATE-5';"
echo 'EOF'
} >>${SCRIPTSDIR}/del_arch.sh
chmod +x ${SCRIPTSDIR}/del_arch.sh
chown oracle:oinstall ${SCRIPTSDIR}/del_arch.sh
echo "00 00 * * * ${SCRIPTSDIR}/del_arch.sh" >>/var/spool/cron/oracle
## 12、备份调整(oracle用户)
rman target /
RMAN> show all;
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
## 13、数据库开机自启动
##root用户
vi /etc/oratab
##修改为Y
lemon:/u01/app/oracle/product/11.2.0/db:Y
##oracle用户
vi $ORACLE_HOME/bin/dbstart
##ORACLE_HOME_LISTNER=$1修改为如下
ORACLE_HOME_LISTNER=$ORACLE_HOME
#rc.local中添加(root用户)
cat <<EOF>>/etc/rc.d/rc.local
su oracle -lc "/u01/app/oracle/product/11.2.0/db/bin/lsnrctl start"
su oracle -lc "/u01/app/oracle/product/11.2.0/db/bin/dbstart"
EOF
chmod +x /etc/rc.d/rc.local
## 14、重启数据库及服务器
shutdown immediate
reboot
六、连接测试
sqldeveloper工具连接数据库
创建Oracle数据库新连接:
输入连接数据库的相关信息后,点击测试,测试成功后可连接数据库:
执行SQL语句:
以上是数据库从初始安装到连接的全部内容,过程详细,一步步跟着做,你也能安装一套完整的数据库来使用!!!