oracle 常用脚本以及语句

一、oracle 安装10G 单机初始化环境:

#!/bin/bash

#关闭selinux
sed -i 's\SELINUX=enforcing\SELINUX=disabled\' /etc/selinux/config
setenforce 0

#关闭防火墙
service iptables stop
chkconfig iptables off

#配置/etc/hosts文件 添加
cat >> /etc/hosts<<EOF

172.16.0.191 rhel

EOF

#增大共享内存
mount -t tmpfs shmfs -o size=7g /dev/shm
echo 'shmfs /dev/shm tmpfs size=24g' >> /etc/fstab

#添加组
groupadd -g 1001 oinstall
groupadd -g 1002 dba

#添加用户

useradd -u 1003 -g oinstall -G dba oracle
echo 'oracle' | passwd --stdin oracle

#创建安装目录

mkdir -p /u01/app/oracle/product/11.2.0/dbhome_1
mkdir -p /u01/app/oraInventory

#更改目录权限

chown -R oracle:oinstall /u01/app/oraInventory/
chown -R oracle:oinstall /u01/app/oracle/
chmod -R 775 /u01

#改变内核参数
cat >> /etc/sysctl.conf<<EOF

#Kernel for Oracle 10g R2
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144

EOF

#使内核参数立即生效
sysctl -p

#添加用户资源限制
cat >> /etc/security/limits.conf<<EOF

#limits for Oracle users

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

#编辑配置文件
cat >> /etc/profile<<EOF

#this is for oracle user
if [ \$USER = "oracle" ]||[ \$USER = "grid" ]; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
EOF

#编辑登陆配置文件
cat >> /etc/pam.d/login<<EOF
#this is for oracle user
session required pam_limits.so
EOF

#为oracle用户添加环境变量
cat >> /home/oracle/.bash_profile<<EOF
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH
EOF
source /home/oracle/.bash_profile

#关闭ntpd服务

chkconfig ntpd off

service ntpd stop

mv /etc/ntp.conf /etc/ntp.conf.bak

version=`cat /etc/redhat-release | cut -d ' ' -f 7 | cut -d . -f 1`

#配置yum仓库
mount /dev/cdrom /mnt

rm -f /etc/yum.repos.d/*
if [ $version=6 ] || [ $version=7 ] ; then
cat > /etc/yum.repos.d/rhel-debuginfo.repo<<EOF
[rhel-debuginfo]
name=Red Hat Enterprise Linux \$releasever - \$basearch - Debug
baseurl=file:///mnt/
enabled=1
gpgcheck=0
EOF
fi

if [ $version=5 ] ; then
cat > /etc/yum.repos.d/rhel-debuginfo.repo<<EOF
[rhel-debuginfo]
name=Red Hat Enterprise Linux \$releasever - \$basearch - Debug
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
EOF
fi

#安装oracle所需要的包
yum clean all

case $version in
7)
echo "the linux version is 7"
;;
6)
echo "the linux version is 6"
yum -y install compat-libcap1-1.10-1 binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-devel glibc-common glibc-headers ksh libaio libaio-devel libgcc libstdc++ make sysstat unixODBC unixODBC-devel
;;
5)
echo "the linux version is 5"
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-devel glibc-common glibc-headers ksh libaio libaio-devel libgcc libstdc++ make sysstat unixODBC unixODBC-devel
;;
4)
echo "the linux version is 4"
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio-devel libaio libgcc libstdc++ libstdc++-devel make numactl pdksh sysstat unixODBC unixODBC-devel esac

二、oracle 安装11G单机初始化环境脚本:

#!/bin/bash

#关闭selinux
sed -i 's\SELINUX=enforcing\SELINUX=disabled\' /etc/selinux/config
setenforce 0

#关闭防火墙
service iptables stop
chkconfig iptables off

#配置/etc/hosts文件 添加
cat >> /etc/hosts<<EOF

172.16.0.191 rhel

EOF

#增大共享内存
mount -t tmpfs shmfs -o size=7g /dev/shm
echo 'shmfs /dev/shm tmpfs size=24g' >> /etc/fstab

#添加组
groupadd -g 1001 oinstall
groupadd -g 1002 asmdba
groupadd -g 1003 asmadmin
groupadd -g 1004 asmoper
groupadd -g 1005 dba
groupadd -g 1006 oper

#添加用户

useradd -u 1002 -g oinstall -G dba,asmdba,oper oracle
echo 'oracle' | passwd --stdin oracle

#创建安装目录

mkdir -p /u01/app/oracle/product/11.2.0/dbhome_1
mkdir -p /u01/app/oraInventory

#更改目录权限

chown -R oracle:oinstall /u01/app/oraInventory/
chown -R oracle:oinstall /u01/app/oracle/
chmod -R 775 /u01

#改变内核参数
cat >> /etc/sysctl.conf<<EOF

#Kernel for Oracle 11g R2
fs.aio-max-nr = 1048576
fs.file-max = 6815744
#kernel.shmall = 2097152
#kernel.shmmax = 4294967295
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

#limits for Oracle users
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240

#编辑配置文件
cat >> /etc/profile<<EOF

#this is for oracle user
if [ \$USER = "oracle" ]||[ \$USER = "grid" ]; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
EOF

#编辑登陆配置文件
cat >> /etc/pam.d/login<<EOF
#this is for oracle user
session required pam_limits.so
EOF

#为oracle用户添加环境变量
cat >> /home/oracle/.bash_profile<<EOF
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH
EOF
source /home/oracle/.bash_profile

#关闭ntpd服务

chkconfig ntpd off

service ntpd stop

mv /etc/ntp.conf /etc/ntp.conf.bak

version=`cat /etc/redhat-release | cut -d ' ' -f 7 | cut -d . -f 1`

#配置yum仓库
mount /dev/cdrom /mnt

rm -f /etc/yum.repos.d/*
if [ $version=6 ] || [ $version=7 ] ; then
cat > /etc/yum.repos.d/rhel-debuginfo.repo<<EOF
[rhel-debuginfo]
name=Red Hat Enterprise Linux \$releasever - \$basearch - Debug
baseurl=file:///mnt/
enabled=1
gpgcheck=0
EOF
fi

if [ $version=5 ] ; then
cat > /etc/yum.repos.d/rhel-debuginfo.repo<<EOF
[rhel-debuginfo]
name=Red Hat Enterprise Linux \$releasever - \$basearch - Debug
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
EOF
fi

#安装oracle所需要的包
yum clean all

case $version in
7)
echo "the linux version is 7"
;;
6)
echo "the linux version is 6"
yum -y install compat-libcap1-1.10-1 binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-devel glibc-common glibc-headers ksh libaio libaio-devel libgcc libstdc++ make sysstat unixODBC unixODBC-devel
;;
5)
echo "the linux version is 5"
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-devel glibc-common glibc-headers ksh libaio libaio-devel libgcc libstdc++ make sysstat unixODBC unixODBC-devel
;;
4)
echo "the linux version is 4"
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio-devel libaio libgcc libstdc++ libstdc++-devel make numactl pdksh sysstat unixODBC unixODBC-devel
esac

三、安装oracle 11g(11.2.0.4) rac 初始化脚本

#!/bin/bash

#关闭selinux
sed -i 's\SELINUX=enforcing\SELINUX=disabled\' /etc/selinux/config
setenforce 0

#关闭防火墙
service iptables stop
chkconfig iptables off

#配置/etc/hosts文件 添加
cat >> /etc/hosts<<EOF

# rac1
172.16.0.191 rac1
172.16.0.193 rac1-vip
192.168.94.11 rac1-priv
# rac2
172.16.0.192 rac2
172.16.0.194 rac2-vip
192.168.94.12 rac2-priv
# scan-ip
172.16.0.203 scan-vip

EOF

#增大共享内存
mount -t tmpfs shmfs -o size=7g /dev/shm
echo 'shmfs /dev/shm tmpfs size=7g' >> /etc/fstab

#添加组
groupadd -g 1001 oinstall
groupadd -g 1002 asmdba
groupadd -g 1003 asmadmin
groupadd -g 1004 asmoper
groupadd -g 1005 dba
groupadd -g 1006 oper

#添加用户
useradd -u 1001 -g oinstall -G asmadmin,asmdba,asmoper,dba grid
echo 'oracle' | passwd --stdin grid

useradd -u 1002 -g oinstall -G dba,asmdba,oper oracle
echo 'oracle' | passwd --stdin oracle

#创建安装目录
mkdir -p /u01/app/grid/
mkdir -p /u01/app/11.2.0/grid
mkdir -p /u01/app/oracle/product/11.2.0/dbhome_1

#更改目录权限
chown -R grid:oinstall /u01
chown -R oracle:oinstall /u01/app/oracle/
chmod -R 775 /u01

#改变内核参数
cat >> /etc/sysctl.conf<<EOF

#Kernel for Oracle 11g R2
fs.aio-max-nr = 1048576
fs.file-max = 6815744
#kernel.shmall = 2097152
#kernel.shmmax = 4294967295
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

#limits for Oracle users
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240

grid soft nproc 2047
grid hard nproc 16384
grid soft nofile 1024
grid hard nofile 65536
grid soft stack 10240
EOF

#编辑配置文件
cat >> /etc/profile<<EOF

#this is for oracle user
if [ \$USER = "oracle" ]||[ \$USER = "grid" ]; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
EOF

#编辑登陆配置文件
cat >> /etc/pam.d/login<<EOF
#this is for oracle user
session required pam_limits.so
EOF

#为grid用户添加环境变量
cat >> /home/grid/.bash_profile<<EOF
export ORACLE_BASE=/u01/app/grid
export ORACLE_SID=+ASM1
export ORACLE_HOME=/u01/app/11.2.0/grid
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
EOF
source /home/grid/.bash_profile

#为oracle用户添加环境变量
cat >> /home/oracle/.bash_profile<<EOF
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=racdb1
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$LD_LIBRARY_PATH
EOF
source /home/oracle/.bash_profile

#关闭ntpd服务

chkconfig ntpd off

service ntpd stop

mv /etc/ntp.conf /etc/ntp.conf.bak

version=`cat /etc/redhat-release | cut -d ' ' -f 7 | cut -d . -f 1`

#配置yum仓库
mount /dev/cdrom /mnt

rm -f /etc/yum.repos.d/*
if [ $version=6 ] || [ $version=7 ] ; then
cat > /etc/yum.repos.d/rhel-debuginfo.repo<<EOF
[rhel-debuginfo]
name=Red Hat Enterprise Linux \$releasever - \$basearch - Debug
baseurl=file:///mnt/
enabled=1
gpgcheck=0
EOF
fi

if [ $version=5 ] ; then
cat > /etc/yum.repos.d/rhel-debuginfo.repo<<EOF
[rhel-debuginfo]
name=Red Hat Enterprise Linux \$releasever - \$basearch - Debug
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
EOF
fi

#安装oracle所需要的包
yum clean all

case $version in
7)
echo "the linux version is 7"
;;
6)
echo "the linux version is 6"
yum -y install compat-libcap1-1.10-1 binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-devel glibc-common glibc-headers ksh libaio libaio-devel libgcc libstdc++ make sysstat unixODBC unixODBC-devel
;;
5)
echo "the linux version is 5"
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-devel glibc-common glibc-headers ksh libaio libaio-devel libgcc libstdc++ make sysstat unixODBC unixODBC-devel
;;
4)
echo "the linux version is 4"
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio-devel libaio libgcc libstdc++ libstdc++-devel make numactl pdksh sysstat unixODBC unixODBC-devel
esac

oracle 常用脚本以及语句的更多相关文章

  1. oracle常用的SQL语句

    一些常用的SQL语句: --建表 create table adolph (id number(10,0),              name varchar2(20),              ...

  2. Oracle常用性能监控语句解析

    转:http://www.cnblogs.com/preftest/archive/2010/11/14/1876856.html 1.监控等待事件select event,sum(decode(wa ...

  3. [标]ORACLE常用的一些语句记录

    --查询实际的统计信息select     num_rows,blocks,empty_blocks,avg_space,avg_row_len,sample_size, last_analyzed  ...

  4. oracle常用脚本

    自动启动oracle sqlplus -S sys/123456 as sysdba <<EOF startup quit EOF lsnrctl start lsnrctl reload

  5. oracle 常用select sql语句

    本人认为很实用的几条语句 1)select ... from ...into... 2)insert into ...select ... 3)select ...from ...left join ...

  6. Oracle 常用脚本

    ORACLE 默认用户名密码 sys/change_on_install SYSDBA 或 SYSOPER 不能以 NORMAL 登录,可作为默认的系统管理员 system/manager SYSDB ...

  7. ORACLE常用脚本示例

    create table DBO.INDEX_POLICY_TBL( ID NUMBER(10) NOT NULL PRIMARY KEY, POLICY_ID NUMBER(10,0) defaul ...

  8. Oracle常用脚本——通过RMAN配置RAC环境的分布式磁带机

    RAC的两个节点:node1,node2 RAC的两个实例:dbrac1,dbrac2 用户,密码的东西大家看看就懂了.设置成8能通道的. #!/bin/bash rman target / < ...

  9. Oracle常用语句集合

    oracle常用经典SQL查询 常用SQL查询: .查看表空间的名称及大小 )),) ts_size from dba_tablespaces t, dba_data_files d where t. ...

随机推荐

  1. 微信小程序项目总结-记账小程序(包括后端)

    一.小程序部分 这是理财系统的前端,江苏海洋大学微信小程序比赛,最后获得了一等奖 GitHub:https://github.com/GeorgeLeoo/finance 1. 项目描述 (1). 此 ...

  2. (18)ASP.NET Core 基于现有数据库创建EF模型(反向工程)

    1.简介 Entity Framework Core可通过数据库提供给应用程序的插件访问许多不同的数据库.我们可以通过使用Entity Framework Core构建执行基本数据访问的ASP.NET ...

  3. Go输入输出格式化Printf

    package main import ( "fmt" "os" ) type point struct { x, y int } func main() { ...

  4. numba,让python速度提升百倍

    python由于它动态解释性语言的特性,跑起代码来相比java.c++要慢很多,尤其在做科学计算的时候,十亿百亿级别的运算,让python的这种劣势更加凸显. 办法永远比困难多,numba就是解决py ...

  5. win server 2008搭建域环境

    0x00 简介 1.域控:win server 2008 2.域内服务器:win server 2008.win server 2003 3.域内PC:win7 x64.win7 x32.win xp ...

  6. java学习之- 线程运行状态

    标签(空格分隔): 线程运行状态 线程的运行状态: 如下是是我编写的一个图,大家可以作为参考: 1.new一个thread子类也是创建了一个线程: 2.创建完毕之后start()-----运行, 3. ...

  7. UGUI的图集处理方式-SpriteAtlas的前世今生

    最糟糕的是人们在生活中经常受到错误志向的阻碍而不自知,真到摆脱了那些阻碍时才能明白过来. —— 歌德 说到UGUI的图集初学者可能觉得没什么难度,包括我刚开始接触的时候也是,甚至你在开发的时候只需要把 ...

  8. Leetcode之深度优先搜索&回溯专题-980. 不同路径 III(Unique Paths III)

    Leetcode之深度优先搜索&回溯专题-980. 不同路径 III(Unique Paths III) 深度优先搜索的解题详细介绍,点击 在二维网格 grid 上,有 4 种类型的方格: 1 ...

  9. 82天突破1000star,项目团队梳理出软件开源必须注意的8个方面

    近期,我们在GitHub上开源了微服务任务调度框架SIA-TASK,82天,收获了1000+个star!由于这是SIA团队第一次开源项目,开源的相关工作,团队之前并没有太多的经验,因此我们特别整理了本 ...

  10. 一本通 P1486 【黑暗城堡】

    题库 :一本通 题号 :1486 题目 :黑暗城堡 link :http://ybt.ssoier.cn:8088/problem_show.php?pid=1486 思路 :这道题既然要求使加入生成 ...