Oracle数据库部署
dd if=/dev/zero of=/swap bs=1024 count=16384000
mkswap /swap
chmod 600 /swap
swapon /swap
echo "/swap swap swap defaults 0 0">>/etc/fstab #设置成自动挂载
hostnamectl set-hostname database-1
echo "127.0.0.1 database-1" >>/etc/hosts
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel
rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel | grep "not installed"
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba oracle
#cat /etc/sysctl.conf
net.core.somaxconn=1024
net.ipv4.tcp_max_tw_buckets=5000
net.ipv4.tcp_max_syn_backlog=1024
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
sysctl -p
# cat /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
在/etc/pam.d/login文件中,添加下面内容
session required /lib64/security/pam_limits.so
session required pam_limits.so
/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
echo never > /sys/kernel/mm/transparent_hugepage/enabled
mkdir -p /data/app/
chown -R oracle:oinstall /data/app/
chmod -R 775 /data/app/
# cat /home/oracle/.bash_profile
umask 022
export ORACLE_HOSTNAME="database-1"
export ORACLE_BASE=/data/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=ORCL
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
服务器 reboot
mkdir /data/database
cd /data/database
wget --http-user=xxxx --http-password=yyyy --no-check-certificate https://dl.jintdev.com/p13390677_112040_Linux-x86-64_1of7.zip
wget --http-user=xxxx --http-password=yyyy --no-check-certificate https://dl.jintdev.com/p13390677_112040_Linux-x86-64_2of7.zip
unzip -q p13390677_112040_Linux-x86-64_1of7.zip -d /data/
unzip -q p13390677_112040_Linux-x86-64_2of7.zip -d /data/
mkdir -p /data/etc
cp /data/database/response/* /data/etc/
wget -P /data/etc https://v.vimll.com:9999/download/oracle/db_install.rsp
# vim /data/etc/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME="database-1"
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
su - oracle
cd /data/database
./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq
su - root
sh /data/app/oracle/inventory/orainstRoot.sh
sh /data/app/oracle/product/11.2.0/root.sh
su - oracle
netca /silent /responsefile /data/etc/netca.rsp
netstat -tnpl | grep 1521
wget -P /data/etc https://v.vimll.com:9999/download/oracle/dbca.rsp
编辑应答文件/data/etc/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"
su - oracle
mkdir /data/app/oracle/oradata
cp /data/app/oracle/product/11.2.0/assistants/dbca/templates/Seed_Database.dfb /data/app/oracle/oradata/
dbca -silent -responseFile /data/etc/dbca.rsp
ps -ef | grep ora_ | grep -v grep
lsnrctl status
cp /data/app/oracle/admin/orcl/pfile/init.ora.* /data/app/oracle/product/11.2.0/dbs/initORCL.ora
vim /data/app/oracle/product/11.2.0/dbs/initORCL.ora
processes=800
sga_target=800M
cd $ORACLE_HOME/dbs
rm lk*
ipcs -map
ipcrm -m 13
ipcrm -m 14
ipcrm -m 15
ipcs -s
ipcrm -s 16
ipcrm -s 491523
su - oracle
sqlplus / as sysdba
SQL> startup mount
SQL> alter database open;
select status from v$instance;
select * from v$version;
# cat /data/app/oracle/product/11.2.0/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = database-2)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
)
)
ADR_BASE_LISTENER = /data/app/oracle
alter user scott account unlock;
alter user scott identified by tiger;
select username,account_status from dba_users;
select username,profile from dba_users where USERNAME='SYSTEM';
select * from dba_profiles where profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';
ALTER PROFILE DEFAULT limit PASSWORD_LIFE_TIME unlimited;
alter profile default limit failed_login_attempts unlimited;
select count(*) from v$process ;
select value from v$parameter where name ='processes';
select count(*) from v$session;
select value from v$parameter where name ='sessions';
##show parameter spfile;
##create spfile from pfile;
##shutdown immediate;
##startup;
#### alter system set sessions = 800 scope = spfile;
#### alter system set processes = 800 scope = spfile;
#### alter system set sga_max_size=2048M scope=spfile;
#### alter system set sga_target=2048M scope=spfile;
##startup force pfile=/data/app/oracle/product/11.2.0/dbs/spfileORCL.ora
##shutdown immediate;
##startup;
# 查看归档参数
SQL> archivelog list;
# 设置归档路径
## 查看归档日志文件格式
show parameter log_archive_format;
##查看归档日志路径
show parameter DB_RECOVERY_FILE_DEST;
## 设置归档日志文件格式
SQL> alter system set log_archive_format='%t_%s_%r.arch' scope=spfile
## 设置归档日志文件路径
SQL> alter system set log_archive_dest_1='location=/oradata/archivelog' scope=both;
# 开启归档模式
## 前提是 必须在mount模式下开启归档模式
SQL> alter database archivelog;
## 切换日志文件
SQL> alter system switch logfile;
按时间删归档:
delete noprompt archivelog until time 'sysdate-7';
delete noprompt archivelog until time "to_date('2021-06-24 10:00:00','yyyy-mm-dd hh24:mi:ss')";
按sequence删归档:
delete noprompt archivelog until sequence 123;
delete noprompt archivelog until sequence 123 thread 1/2;
设置Oracle开机启动
vim /data/app/oracle/product/11.2.0/bin/dbstart
ORACLE_HOME_LISTNER=$ORACLE_HOME
vim /data/app/oracle/product/11.2.0/bin/dbshut
ORACLE_HOME_LISTNER=$ORACLE_HOME
vim /etc/oratab
orcl:/data/app/oracle/product/11.2.0:Y
修改rc.local,自启监听和数据库
su - oracle -lc 'lsnrctl start'
su - oracle -lc 'dbstart'
wget -P /etc/init.d/ https://v.vimll.com:9999/download/oracle/oracle
chmod +x /etc/init.d/oracle
cd /data/app/oracle/product/11.2.0/bin/
chmod 6751 oracle
cd /var/tmp
chown -R oracle:oinstall .oracle
chkconfig --add oracle
chkconfig oracle on
chkconfig --list
vim /etc/rc.d/init.d/oracle
#! /bin/bash
# oracle: Start/Stop Oracle Database 11g R2
#
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
# processname: oracle
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
if [ -f $LOCKFILE ]; then
echo $0 already running.
exit 1
fi
echo -n $"Starting Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch $LOCKFILE
;;
'stop')
if [ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo -n $"Stopping Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f $LOCKFILE
;;
'restart')
$0 stop
$0 start
;;
'status')
if [ -f $LOCKFILE ]; then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0