oracle环境搭建脚本整理

oracle视频

https://www.bilibili.com/video/av17436350/?p=18

1.准备文件

bash_profile db_install.rsp hj.sh  oracle.sh profile  oracle2.sh

inux.x64_11gR2_database_2of2.zip  linux.x64_11gR2_database_1of2.zip logs #放在/root/下

2.编写基础环境配置脚本  注意如果没有光盘 请注释掉 cdrom的挂载不然可能无法启动

vi  /root/hj.sh

#!/bin/bash
# Optimize the system after installation
PASSWD=123456
NETIP=192.168.1.63
NETGATWAY=192.168.1.1
PROTOBOOT=none
HOSTNAME=zsl.cn
DNS1=8.8.8.8
NTPSERVER=ntp1.aliyun.com
YUMREPO=http://mirrors.aliyun.com/repo/Centos-7.repo
EPELREPO=http://mirrors.aliyun.com/repo/epel-7.repo
SSH_PORT=10024
eth0=ens33

# in case of some bad behaviours
CHATTR=chenhao
# Open the port for iptabeles input or maybe stop iptables
PORTS=80,22,21,8088
# record the system user,ip addresse,shell command and detail
HISTDIR=/usr/etc/.history
 
# the welcome info
cat << EOF
+------------------------------------------------------------------+
|     **********  Welcome to CentOS 7.x System init  **********    |
+------------------------------------------------------------------+
EOF
[ `whoami` != "root" ] && echo "please use root" && exit 1
function format() {
    echo -e "\033[32m Success!!!\033[0m\n"
    echo "#########################################################"
}
 
###change the root passwd
echo "set root passwd"
echo $PASSWD | passwd root --stdin &> /dev/null
format
 
###change network setting
# sed -i "s/\$releasever/${RHEL_Ver}/g" --替换写法
cat > /etc/sysconfig/network-scripts/ifcfg-$eth0 << EOF
TYPE=Ethernet
BOOTPROTO=none
NAME=$eth0
DEVICE=$eth0
ONBOOT=yes
IPADDR=$NETIP
PREFIX=24
GATEWAY=$NETGATWAY
DNS1=8.8.8.8
EOF
systemctl restart network
format


 
###change the hostname
echo "set hostname"
hostname $HOSTNAME && echo "$HOSTNAME" > /etc/hostname
format
 
###change the dns
echo "set DNS"
echo "" > /etc/resolv.conf    
echo "nameserver $DNS1" > /etc/resolv.conf
#echo "nameserver $DNS2" >> /etc/resolv.conf
ping -c 3 www.baidu.com &> /dev/null || echo "Network is unreachable" || exit 3
format
 
###diable selinux
echo "disable selinux"
[ `getenforce` != "Disabled" ] && setenforce 0 &> /dev/null && sed -i s/"^SELINUX=.*$"/"SELINUX=disabled"/g /etc/sysconfig/selinux
format
echo "/dev/cdrom /mnt iso9660 defaults 0 0" >> /etc/fstab
mount -a
###update yum repo
echo "set yum mirrors"
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo $YUMREPO &> /dev/null
curl -o /etc/yum.repos.d/epel.repo $EPELREPO &> /dev/null
yum clean all &> /dev/null && yum makecache &> /dev/null
format
 
###install the basic command
yum install vim wget openssl-devel ntpdate make gcc-c++  ncurses-devel net-snmp sysstat lrzsz zip unzip tree net-tools lftp -y
#yum -y groupinstall "Development Tools" "Server Platform Development" &> /dev/null
format
 

###character set
echo "set LANG"
#sed -i s/"^LANG=.*$"/"LANG=zh_CN.UTF-8"/ /etc/locale.conf
#source /etc/locale.conf
 
###update timezone
echo "set ntptime"
rm /etc/localtime
ln -vs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install ntpdate -y
ntpdate $NTPSERVER &> /dev/null
echo "*/5 * * * * /usr/sbin/ntpdate $NTPSERVER  &>/dev/null" >> /etc/crontab
hwclock -w
format
  
###show the system info
echo "Set login message."
echo "This is Product Server" > /etc/issue
format
 
###iptables setting
echo "set iptables"
systemctl stop firewalld &&  systemctl disable firewalld

format
iptables -F
#iptables -A INPUT -p tcp -m multiport --dports $SSH_PORT,$PORTS -j ACCEPT
#iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#iptables -A INPUT -i lo -j ACCEPT
#iptables -A OUTPUT -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -P INPUT DROP
#iptables -P FORWARD DROP
#iptables -P OUTPUT ACCEPT
#service iptables save &> /dev/null
 
# reboot the system after setting
reboot
View Code

3.编写oracle安装环境和数据库脚本

#!/bin/bash
#Usage:Log on as the superuser('root'),and then execute the command:#./1preusers.sh

yum -y install binutils* compat-libcap1* compat-libstdc++* gcc* gcc-c++* glibc* glibc-devel* ksh* libaio* libaio-devel* libgcc* libstdc++* libstdc++-devel* libXi* libXtst* make* sysstat* elfutils* unixODBC*

groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
echo "oracle" | passwd --stdin oracle
/bin/cp -rf /root/profile /etc/profile
/bin/cp -rf /root/bash_profile /home/oracle/.bash_profile
source /etc/profile
chown oracle:oinstall /home/oracle/.bash_profile

hostnamectl set-hostname zsl.cn
cat >/etc/hosts << EOF
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.63 zsl zsl.cn
EOF


echo "The Groups and users has been created"
echo "oracle hj has been set successfully"

cat >/etc/sysctl.conf << EOF
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
io-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
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
EOF
sysctl -p

cat >/etc/security/limits.conf << EOF
# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
oracle           soft    nproc           2047
oracle           hard    nproc           16384
oracle           soft    nofile          1024
oracle           hard    nofile          65536
oracle           soft    stack           10240
# End of file
EOF

cat >/etc/pam.d/login << EOF
#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth       substack     system-auth
auth       include      postlogin
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
session    optional     pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    include      postlogin
-session   optional     pam_ck_connector.so
session  required   /lib64/security/pam_limits.so
session  required   pam_limits.so
EOF



mkdir -p /u01/app/oracle/product/11.2.0
mkdir /u01/app/oracle/oradata
mkdir /u01/app/oracle/inventory
mkdir /u01/app/oracle/fast_recovery_area
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01/app/oracle
mv /root/linux.x64_11gR2_database_2of2.zip /tmp/ && mv /root/linux.x64_11gR2_database_1of2.zip /tmp/
cd /tmp/
unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip
cp /tmp/database/response/db_install.rsp /tmp/database/response/db_install.rsp.bak

/bin/cp -rf /root/db_install.rsp /tmp/database/response/db_install.rsp
/bin/cp -rf /root/oracle2.sh /home/oracle/oracle2.sh
chown oracle:oinstall /home/oracle/oracle2.sh
chmod a+x /home/oracle/oracle2.sh
su - oracle -s /bin/bash /root/oracle2.sh

 

4.编写oracle用户下运行脚本

vi /root/oracle2.sh

source /home/oracle/.bash_profile
cd /tmp/database/
./runInstaller -silent -ignorePrereq -ignoreSysPrereqs -responseFile /tmp/database/response/db_install.rsp

 

5.按照提示在root下运行

/u01/app/oracle/inventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/root.sh

6.开启监听数据库端口在oracle用户下执行

su - oracle
source /home/oracle/.bash_profile
export DISPLAY=local_host:0.0
netca -silent -responseFile /tmp/database/response/netca.rsp

$ll $ORACLE_HOME/network/admin/*.ora
$lsnrctl status
netstat -tnulp | grep 1521
[oracle@zsl ~]$ sqlplus / as sysdba #测试登录成功

 

posted @ 2018-12-02 08:46  夜辰雪扬  阅读(137)  评论(0)    收藏  举报