#!/bin/bash
#writed by kangjie 2018-05-9
#########################################
#如果没有交换分区swap,则创建 #
#检查 Swap 空间
swapon -s
#创建并允许 Swap 文件
dd if=/dev/zero of=/swapfile bs=1024 count=512k
#格式化并激活 Swap 文件
mkswap /swapfile
#激活 Swap
swapon /swapfile
#以上步骤做完,再次运行命令:
#
swapon -s
#你会发现返回的信息概要:
#Filename Type Size Used Priority
#/swapfile file 524284 0 -1
#如果要机器重启的时候自动挂载 Swap ,那么还需要修改 fstab 配置。用 vim 打开 /etc/fstab 文件,在其最后添加如下一行:
# /swapfile swap swap defaults 0 0
#最后,赋予 Swap 文件适当的权限:
# chown root:root /swapfile
# chmod 0600 /swapfile
#########################################
#########################################
#install depending packages #
#########################################
yum install -y gcc* gcc-* gcc-c++-* glibc-devel-* glibc-headers-* compat-libstdc* libstdc* elfutils-libelf-devel* libaio-devel* sysstat* unixODBC-* pdksh-*
########################################
#add groups,user and create dir #
########################################
/usr/sbin/groupadd -g 501 oinstall
/usr/sbin/groupadd -g 502 dba
useradd -u 1000 -g oinstall -G dba oracle
mkdir -p /data/oracle/product/11.2.0
mkdir /data/oracle/oradata
mkdir /data/oracle/inventory
mkdir /data/oracle/fast_recovery_area
chown -R oracle:oinstall /data/oracle
chmod -R 775 /data/oracle
##############################################
#modify sysctl.conf #
##############################################
cat >> /etc/sysctl.conf <<done
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
fs.aio-max-nr = 1048576
done
sysctl -p
###############################################
#modify /etc/security/limits.conf #
###############################################
cat >> /etc/security/limits.conf << done
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
done
################################################
#modify /etc/pam.d/login #
################################################
echo "session required pam_limits.so">>/etc/pam.d/login
################################################
# setting user oracle env #
################################################
cat >> /home/oracle/.bash_profile <<done
ORACLE_BASE=/data/oracle
ORACLE_HOME=/data/oracle/product/11.2.0
ORACLE_SID=orcl
PATH=$PATH:/data/oracle/product/11.2.0/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
done
########################
vim /etc/hosts
192.168.206.135 CentOS
# 增加HOSTNAME到 /etc/hosts 文件中
192.168.206.135 iZ3unv****
#########################
unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip
cd database/response/
cp db_install.rsp db_install.rsp.bak
vim db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=CentOS
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/data/oracle/product/11.2.0
ORACLE_BASE=/data/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
##############33
#切换oracle用户 注意使用绝对路径
./runInstaller -silent -ignorePrereq -ignoreSysPrereqs -responseFile /home/pack/database/response/db_install.rsp
#切换root用户
/data/oracle/inventory/orainstRoot.sh
/data/oracle/product/11.2.0/root.sh
export DISPLAY=localhost:0.0
netca -silent -responseFile /home/pack/database/response/netca.rsp
netstat -tnulp | grep 1521
####################################
vim database/response/dbca.rsp
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/data/oracle/oradata
RECOVERYAREADESTINATION=/data/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "1638"
#建立新库,同时建立对应的实例
dbca -silent -responseFile /home/pack/database/response/dbca.rsp
########
create tablespace db_test datafile '/data/oracle/oradata/orcl/db_test.dbf' size 50m autoextend on;
select default_tablespace, temporary_tablespace, d.username from dba_users d
CREATE USER utest IDENTIFIED BY sd_123 DEFAULT TABLESPACE db_test TEMPORARY TABLESPACE temp;
GRANT CONNECT TO utest;
GRANT RESOURCE TO utest;
GRANT dba TO utest;
select * from dba_users;