Centos下Oracle11gR2安裝教程與自動化配置指令碼

Hui_Tong發表於2020-10-09

系統環境準備

開發元件與依賴庫安裝

安裝centos時選擇Server with GUI,右面的可以不勾選,後面統一來裝

配置本地yum源

以上包如果缺乏可配置本地yum源進行安裝

sudo mount /dev/cdrom /mnt/

[galen@localhost yum.repos.d]$ sudo vim /etc/yum.repos.d/cdrom.repo
[galen@localhost yum.repos.d]$ cat cdrom.repo 
[c7-media]
name=isofile
baseurl=file:///mnt
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[galen@localhost yum.repos.d]$ sudo mv CentOS-Base.repo CentOS-Base.repo-bak
[galen@localhost yum.repos.d]$ sudo mv CentOS-Media.repo CentOS-Media.repo-bak
[galen@localhost yum.repos.d]$ sudo mv cdrom.repo CentOS-Media.repo

配置好yum源後開始安裝依賴庫,如下

yum install glibc glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh  compat-libcap1   compat-libstdc++ elfutils-libelf-devel gcc-c++

關閉防火牆

[galen@localhost ~]$ systemctl stop firewalld.service 
[galen@localhost ~]$ systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

關閉selinux

編輯/etc/sysconfig/selinux檔案,儲存退出後執行 setenforce 0命令

vim /etc/sysconfig/selinux
SELINUX=disabled
#SELINUXTYPE=targeted   #註釋掉

建立oracle使用者、修改系統引數

創oracle建使用者和組

[root@localhost galen]# groupadd oinstall
[root@localhost galen]# groupadd dba
[root@localhost galen]# useradd -g oinstall -G dba oracle
[root@localhost galen]# passwd oracle

[root@localhost galen]# id oracle
uid=1001(oracle) gid=1001(oinstall) groups=1001(oinstall),1002(dba)

系統引數設定

官方推薦值:

fs.aio-max-nr = 1048576   
fs.file-max = 6815744    
kernel.shmall = 2097152  
kernel.shmmax = 536870912  #推薦超過一半的實體記憶體
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 

通過 /sbin/sysctl -a |grep xxx 檢視系統各引數,如果大於官方推薦值不修改,如果小於官方推薦值則修改為官方推薦值,寫入/etc/sysctl.conf檔案中,使用sysctl -p使其生效,示例如下

[root@localhost etc]# cat sysctl.conf
fs.aio-max-nr = 6815744
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@localhost etc]# vim /etc/security/limits.conf
oracle		soft		nproc		2048
oracle		hard		nproc		16384
oracle		soft		nofile		1024
oracle		hard		nofile		65536
oracle		soft		stack		10240 

新增以下內容到/etc/pam.d/login

[root@localhost ~]# vim /etc/pam.d/login
session  required   pam_limits.so

新增以下內容到/etc/profile

[root@localhost ~]# vim /etc/profile
if [[ $USER = "oracle" ]]; then
	if [[ $SHELL = "/bin/ksh" ]]; then
		ulimit -p 16384
		ulimit -n 65536
	else
		ulimit -u 16384 -n 65536
	fi
fi

儲存後執行source /etc/profile生效

配置oracle使用者環境變數,在/home/oracle/.bash_profile中加入如下內容

[root@localhost ~]# vim /home/oracle/.bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LANG="en_US.UTF-8"
export NLS_LANG=american_AMERICA.UTF8
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"

建立oracle安裝目錄

mkdir -p /u01/app/oracle/product/11.2.0/db_1
chown -R oracle:oinstall /u01/app
chmod -R 775 /u01/app

安裝oracle 11g

掛載oracle11g安裝包iso(也可以通過其他方式將oracle安裝包傳到主機),將安裝檔案複製到oracle home目錄下,修改檔案許可權給oracle使用者

[root@localhost /]# mkdir /mnt/oracle11g
[root@localhost /]# mount /dev/cdrom /mnt/oracle11g/
[root@localhost /]# cp -r /mnt/oracle11g /home/oracle/
# 複製到oracle home目錄下並修改許可權
[root@localhost oracle]# chown -R oracle:oinstall /home/oracle/oracle11g/
[root@localhost oracle]# chmod -R 775 /home/oracle/oracle11g/

接下來使用oracle使用者登入桌面

執行./runInstaller開始安裝,Centos 7安裝的時候錯誤彈框有時候會變成一條豎線,安裝無法進行下去,所以執行時執行

./runInstaller -jreLoc /etc/alternatives/jre_1.8.0

每項操作如下

[Configure Security Updates] 取消勾選 I wish to receive security updates via My Oracle Support,Next

[Installation Option] Install database software only,Next

[Grid Options] Next

[Product Languages] Next

[Enterprise Edition] Next

[Installation Location] Next

[Create Inventory] Next

[Operating System Groups] Next

[Prerequisite Checks] Next

[Summary] Finish,開始安裝oracle 11g

安裝到84%的時候可能會出現ins_ctx.mk相關的錯誤,如下

修改/u01/app/oracle/product/11.2.0/db_1/ctx/lib/ins_ctx.mk檔案

# 原始檔
ctxhx: $(CTXHXOBJ)
        $(LINK_CTXHX) $(CTXHXOBJ) $(INSO_LINK)
# 修改為
ctxhx: $(CTXHXOBJ)
        -static $(LINK_CTXHX) $(CTXHXOBJ) $(INSO_LINK) /usr/lib64/stdc.a

修改/u01/app/oracle/product/11.2.0/db_1/sysman/lib/ins_emagent.mk檔案

# 原始檔
$(SYSMANBIN)emdctl:
        $(MK_EMAGENT_NMECTL)
# 修改為
$(SYSMANBIN)emdctl:
        $(MK_EMAGENT_NMECTL) -lnnz11

retry繼續安裝到94%時,彈出

使用root使用者ssh到主機到上述目錄分別執行orainstRoot.sh與root.sh,執行root.sh時根據提示填入路徑

/u01/app/oracle/product/11.2.0/dbhome_1/bin,執行完成後到UI點選OK,安裝完成

環境配置指令碼

  1. 使用root使用者登入
  2. 確保系統iso驅動器已連線(/dev/cdrom可mount)
  3. 複製指令碼到主機並給予可執行許可權,執行指令碼完成後即可開始安裝oracle 11g

oracle 11g環境配置指令碼

#!/bin/bash

# 配置yum源為本地iso
function set_yum_media() {
    cd /etc/yum.repos.d/
    for repo_file in `ls /etc/yum.repos.d/ | grep -v Media`
    do
        new_file=$repo_file.bak
        mv $repo_file $new_file
    done
    mkdir -p /mnt/media-dir
    mount /dev/cdrom /mnt/media-dir
    sed -i -e 's/baseurl=file:\/\/\/.*/baseurl=file:\/\/\/mnt\/media-dir\//g' -e 's/enabled=0/enabled=1/g' `ls /etc/yum.repos.d/ | grep Media`
    cd -
	rm -rf /var/run/yum.pid
    yum -y update
}

function install_packages() {
    for package in glibc glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel pdksh  compat-libcap1   compat-libstdc++ elfutils-libelf-devel gcc-c++
    do
        yum -y install $package
    done
}

function create_oracle_user() {
	groupadd oinstall
	groupadd dba
	useradd -g oinstall -G dba oracle
	# 設定oracle使用者密碼為oracle
	echo oracle|passwd --stdin oracle
}

function set_system_parm() {
	sed -i '$a\fs.aio-max-nr = 1048576' /etc/sysctl.conf
	sed -i '$a\fs.file-max = 6815744' /etc/sysctl.conf
	sed -i '$a\kernel.shmall = 2097152' /etc/sysctl.conf
	sed -i '$a\kernel.shmmax = 536870912' /etc/sysctl.conf
	sed -i '$a\kernel.shmmni = 4096' /etc/sysctl.conf
	sed -i '$a\kernel.sem = 250 32000 100 128' /etc/sysctl.conf
	sed -i '$a\net.ipv4.ip_local_port_range = 9000 65500' /etc/sysctl.conf
	sed -i '$a\net.core.rmem_default = 262144' /etc/sysctl.conf
	sed -i '$a\net.core.rmem_max = 4194304' /etc/sysctl.conf
	sed -i '$a\net.core.wmem_default = 262144' /etc/sysctl.conf
	sed -i '$a\net.core.wmem_max = 1048586' /etc/sysctl.conf
	sysctl -p
}

function set_system_limit_parm() {
	sed -i '$a\oracle		soft		nproc		2048' /etc/security/limits.conf
	sed -i '$a\oracle		hard		nproc		16384' /etc/security/limits.conf
	sed -i '$a\oracle		soft		nofile		1024' /etc/security/limits.conf
	sed -i '$a\oracle		hard		nofile		65536' /etc/security/limits.conf
	sed -i '$a\oracle		soft		stack		10240' /etc/security/limits.conf
}

function set_profile_parm() {
	sed -i '$a\session  required   pam_limits.so' /etc/pam.d/login
	sed -i '$a\if [[ $USER = "oracle" ]]; then' /etc/profile
	sed -i '$a\   if [[ $SHELL = "/bin/ksh" ]]; then' /etc/profile
	sed -i '$a\       ulimit -p 16384' /etc/profile
	sed -i '$a\       ulimit -n 65536' /etc/profile
	sed -i '$a\   else' /etc/profile
	sed -i '$a\       ulimit -u 16384 -n 65536' /etc/profile
	sed -i '$a\   fi' /etc/profile
	sed -i '$a\fi' /etc/profile
	source /etc/profile
}

function set_oracle_env() {
	sed -i '$a\export ORACLE_BASE=/u01/app/oracle' /home/oracle/.bash_profile
	sed -i '$a\export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1' /home/oracle/.bash_profile
	sed -i '$a\export ORACLE_SID=orcl' /home/oracle/.bash_profile
	sed -i '$a\export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH' /home/oracle/.bash_profile
	sed -i '$a\export LANG="en_US.UTF-8"' /home/oracle/.bash_profile
	sed -i '$a\export NLS_LANG=american_AMERICA.UTF8' /home/oracle/.bash_profile
	sed -i '$a\export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"' /home/oracle/.bash_profile
	source /home/oracle/.bash_profile
}

function create_oracle_dir() {
	mkdir -p /u01/app/oracle/product/11.2.0/db_1
	chown -R oracle:oinstall /u01/app
	chmod -R 775 /u01/app
}

function disable_firewall() {
	systemctl stop firewalld.service
	systemctl disable firewalld.service
	sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
	setenforce 0
}

if [ `whoami` == "root" ]
then
	set_yum_media
	install_packages
	create_oracle_user
	echo "set system parm"
	set_system_parm
	echo "set limits"
	set_system_limit_parm
	echo "set /etc/profile"
	set_profile_parm
	echo "set oracle env"
	set_oracle_env
	echo "create oracle dir"
	create_oracle_dir
	echo "disable firwall"
	disable_firewall
fi

相關文章