Centos史上新版最详细步骤-Linux无脑命令式oracle11g静默安装
1、 关闭selinux
1.1 sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
1.2 或者手动编辑 vi /etc/selinux/config将SELINUX=enforcing改为SELINUX=disabled
1.3 执行setenforce 0
2、 关闭防火墙firewall
2.1关闭防火墙
systemctl status firewalld.service
systemctl stop firewalld.service
3、安装依赖包
3.1 检查依赖包安装情况
rpm -q binutils compat-libcap1 vsftpd gcc gcc-c++ glibc-devel glibc elfutils-libelf-devel compat-libcap1 libaio-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel make sysstat unixODBC unixODBC-devel
3.2 使用yum源安装所需依赖包
yum -y install binutils compat-libcap1 vsftpd gcc gcc-c++ glibc-devel glibc elfutils-libelf-devel compat-libcap1 libaio-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel make sysstat unixODBC unixODBC-devel
4、修改主机名(可选)
设置主机名hostnamectl set-hostname xxxxx
xxxxx为主机名
hostnamectl set-hostname hairundb
5、修改内核参数
# vi /etc/sysctl.conf
在最后添加(注意重复参数,不能小于以下数值)
kernel.shmall = 2097152
kernel.shmmax = 1073741824
fs.aio-max-nr = 1048576
fs.file-max = 6815744
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 -p
6、修改用户限制文件
# vi /etc/security/limits.conf
在最后添加
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
保存退出
7、关联设置
# vi /etc/pam.d/login
在最后添加
session required /lib64/security/pam_limits.so
session required pam_limits.so
保存退出
8、设置系统环境变量
# vi /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
9、创建oracle系统用户
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle
检查oracle用户权限
id oracle
10、创建oracle安装目录
mkdir -p /opt/oracle/product/11r2
mkdir /opt/oracle/oradata
mkdir /opt/oracle/inventory
mkdir /opt/oracle/flash_recovery_area
11、将oracle用户加入到sudo组
# vi /etc/sudoers
在root ALL=(ALL) ALL这一行下加入
oracle ALL=(ALL) ALL
强制保存退出(:wq!)
12、修改oracle用户环境变量
# vi /home/oracle/.bash_profile
在最后添加(ORACLE_SID=XXX按实际情况修改)
export ORACLE_BASE=/opt/oracle;
export ORACLE_HOME=/opt/oracle/product/11r2;
export ORACLE_SID=ora11;
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
保存退出
使环境变量生效
# source /home/oracle/.bash_profile
查看环境变量
# env
13、修改hosts文件
# vi /etc/hosts
在最后添加
主机ip 主机名hairundb
14、root用户登录,把数据库安装包上传至/opt/oracle目录下
chown -R oracle:oinstall /opt/oracle
chmod -R 775 /opt/oracle
15、安装oracle数据库
切换至oracle用户
su - oracle
解压安装包文件(如果没有unzip命令,可以先登录root用户,使用yum源安装:yum -y install unzip)
cd /opt/oracle
unzip oracle.zip
编辑oracle数据库基准配置文件
vi /opt/oracle/database/response/db_install.rsp
输入(:set number)显示行号
修改
oracle.install.option=INSTALL_DB_SWONLY //29行 安装类型,只安装数据库软件
ORACLE_HOSTNAME=hairundb //37行 主机名称通过hostname查看
UNIX_GROUP_NAME=oinstall //42 行 安装组
INVENTORY_LOCATION=/opt/oracle/inventory //49 行INVENTORY目录
SELECTED_LANGUAGES=en,zh_CN //86 行 选择语言
ORACLE_HOME=/opt/oracle/product/11r2 //91 行oracle_home
ORACLE_BASE=/opt/oracle //96 行oracle_base
oracle.install.db.InstallEdition=EE //107 行oracle版本
oracle.install.db.DBA_GROUP=dba //154行dba用户组
oracle.install.db.OPER_GROUP=oinstall //160行oper用户组
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE //189行数据库类型,一般用途
oracle.install.db.config.starterdb.globalDBName=ora11 //194行globalDBName
oracle.install.db.config.starterdb.SID=ora11 //199行SID
oracle.install.db.config.starterdb.memoryLimit=800 //229行自动管理内存的最小内存(M)
oracle.install.db.config.starterdb.password.ALL=oracle //262行所有数据库用户使用同一个密码
DECLINE_SECURITY_UPDATES=true //400行设置安全更新
编译安装oracle
cd /opt/oracle/database/
chmod -R 750 /opt/oracle/database/
./runInstaller -silent -responseFile /opt/oracle/database/response/db_install.rsp -ignorePrereq
安装过程中新开一个root窗口,执行
/opt/oracle/inventory/orainstRoot.sh
/opt/oracle/product/11r2/root.sh
执行完成后返回oracle界面按下回车键完成安装
vi /opt/oracle/database/response/netca.rsp
修改
INSTALL_TYPE=""custom""
netca /silent /responseFile /opt/oracle/database/response/netca.rsp
检查监听文件
ll /opt/oracle/product/11r2/network/admin/
查看监听端口(root用户执行)
netstat -tnulp | grep 1521
vi /opt/oracle/database/response/dbca.rsp
修改
SID = "ora11" 、、170行 SID
SYSPASSWORD = "oracle" //212行
SYSTEMPASSWORD = "oracle" //221行
SYSMANPASSWORD = "oracle" //252行
DBSNMPPASSWORD = "oracle" 、、262行
DATAFILEDESTINATION =/opt/oracle/oradata //360行
RECOVERYAREADESTINATION=/opt/oracle/flash_recovery_area //370行
CHARACTERSET = "ZHS16GBK" //418行 字符集
GDBNAME = "ora11" //713行 全局名
cd /opt/oracle/product/11r2/bin/
dbca -silent -responseFile /opt/oracle/database/response/dbca.rsp
等待建库完成
检查实例进程
ps -ef | grep ora_ | grep -v grep
数据库实例连接测试
查看监听状态
lsnrctl status
使用sqlplus命令测试连接oracle
sqlplus / as sysdba
SQL> conn /as sysdba
登录数据库
sqlplus /nolog
SQL> conn /as sysdba
SQL> startup
16、修改Oracle数据库密码180天限制
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
SQL> select * from dba_profiles s WHERE s.profile=‘DEFAULT‘ AND resource_name=‘PASSWORD_LIFE_TIME‘;
17、修改Oracle数据库尝试登录失败次数限制(默认10次,更改为无限制)
SQL> ALTER PROFILE DEFAULT LIMIT FAILED_LOGIN_ATTEMPTS UNLIMITED;
18、修改Oracle数据库无法导出空表的问题
SQL> alter system set deferred_segment_creation=false;
以root用户登录:命令:exit
vi /etc/oratab
ora11:/data/oracle/product/11r2:N中的 N 改成 Y
vi /opt/oracle/product/11r2/bin/dbstart
注释原有的ORACLE_HOME_LISTNER行,新增一行 export ORACLE_HOME_LISTNER=$ORACLE_HOME
vi /opt/oracle/product/11r2/bin/dbshut
注释原有的ORACLE_HOME_LISTNER行,新增一行 export ORACLE_HOME_LISTNER=$ORACLE_HOME
编写自启动脚本
vi /etc/init.d/oracle
添加
#!/bin/sh
# chkconfig: 345 99 10
##其中chkconfig:345 99 10 是指脚本将为运行级3、4、5启动Oracle 10g服务,启动优先级为99,关闭优先级为10
# description: Oracle auto start-stop script.
# /etc/rc.d/init.d/oracle
# description: starts the oracle database
ORA_HOME=/opt/oracle/product/11r2
ORA_OWNER=oracle
case "$1" in
start)
echo -n "Starting Oracle Databases: "
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >> /var/log/oracle
echo "Done."
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole" >> /var/log/oracle
echo "Done."
echo ""
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole" >> /var/log/oracle
echo "Done."
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >> /var/log/oracle
echo "Done."
echo ""
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: "
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >> /var/log/oracle
echo "Done."
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole" >> /var/log/oracle
echo "Done."
echo ""
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "---------------------------------------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
*)
echo "Usage: oracle { start | stop | restart }"
exit 1
esac
exit 0
赋予执行权限
chmod 755 /etc/init.d/oracle
创建软链接
ln -s /etc/init.d/oracle /etc/rc.d/rc3.d/S10oracle
ln -s /etc/init.d/oracle /etc/rc.d/rc4.d/S10oracle
ln -s /etc/init.d/oracle /etc/rc.d/rc5.d/S10oracle
添加自启动服务
chkconfig --add oracle
chkconfig --level 345 oracle on
chkconfig --list|grep oracle
重启数据库
service oracle restart
重启服务器,测试数据库是否启动
sqlplus / as sysdba
SQL> conn /as sysdba
SQL> startup