redhat安装oracle并设置开机自启
1.配置/etc/hosts文件
[root@Jsls ~]# cat /etc/hosts
[root@Jsls ~]# vim /etc/hosts
192.168.15.97 Jsls
2.关闭selinux
1、临时关闭:输入命令setenforce 0,重启系统后还会开启。
2、永久关闭:输入命令vi /etc/selinux/config,将SELINUX=enforcing改为SELINUX=disabled,然后保存退出。
[root@Jsls ~]# vi /etc/selinux/config
编辑
SELINUX=enforcing改为SELINUX=disabled
3.关闭防火墙
[root@Jsls ~]# systemctl stop firewalld.service
[root@Jsls ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
4.配置/etc/sysctl.conf文件
[root@Jsls ~]# vim /etc/sysctl.conf
# 添加的配置
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
kernel.panic_on_oops = 1
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
最后应用配置
[root@Jsls ~]# sysctl -p
5.配置/etc/security/limits.conf文件
[root@Jsls ~]# vim /etc/security/limits.conf
# 添加的配置
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
6.安装rpm包
dnf install -y bc
dnf install -y binutils
dnf install -y compat-libstdc++-33
dnf install -y elfutils-libelf
dnf install -y elfutils-libelf-devel
dnf install -y fontconfig-devel
dnf install -y glibc
dnf install -y glibc-devel
dnf install -y ksh
dnf install -y libaio
dnf install -y libaio-devel
dnf install -y libXrender
dnf install -y libXrender-devel
dnf install -y libX11
dnf install -y libXau
dnf install -y libXi
dnf install -y libXtst
dnf install -y libgcc
dnf install -y librdmacm-devel
dnf install -y libstdc++
dnf install -y libstdc++-devel
dnf install -y libxcb
dnf install -y make
dnf install -y net-tools
dnf install -y nfs-utils
dnf install -y python
dnf install -y python-configshell
dnf install -y python-rtslib
dnf install -y python-six
dnf install -y targetcli
dnf install -y smartmontools
dnf install -y sysstat
dnf install -y unixODBC
dnf install -y libnsl2
dnf install -y libnsl2.i686
dnf install -y libnsl
7.创建用户和组
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper oracle
passwd oracle
设置密码redhat
这里需要输入两次密码确认
Changing password for user oracle.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
8.创建目录
mkdir -p /u01/app/oracle/product/19.3.0/dbhome_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01
9.设置环境变量
[root@Jsls ~]# su - oracle
切换到oracle用户下执行vim .bash_profile编辑.bash_profile文件添加以下内容:
[oracle@Jsls ~]$ vim .bash_profile
#---------------------------------------------
# 添加的配置 jdk路径根据实际使用的修改
ORACLE_SID=orcl;export ORACLE_SID
ORACLE_UNQNAME=orcl;export ORACLE_UNQNAME
JAVA_HOME=/usr/local/jdk1.8.0_381; export JAVA_HOME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/19.3.0/dbhome_1; export ORACLE_HOME
ORACLE_TERM=xterm; export ORACLE_TERM
NLS_DATE_FORMAT="YYYY:MM:DDHH24:MI:SS"; export NLS_DATE_FORMAT
export NLS_LANG=AMERICAN_AMERICA.UTF8
TNS_ADMIN=$ORACLE_HOME/network/admin; export TNS_ADMIN
ORA_NLS11=$ORACLE_HOME/nls/data; export ORA_NLS11
PATH=.:${JAVA_HOME}/bin:${PATH}:$HOME/bin:$ORACLE_HOME/bin:$ORA_CRS_HOME/bin
PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export CLASSPATH
THREADS_FLAG=native; export THREADS_FLAG
export TEMP=/tmp
export TMPDIR=/tmp
umask 022
执行命令生效
[oracle@Jsls ~]$ source .bash_profile
10.图形界面安装数据库软件
[oracle@Jsls ~]$ su - root
[root@Jsls ~]# chown oracle:oinstall /soft/LINUX.X64_193000_db_home.zip
[oracle@Jsls ~]$ unzip -d /u01/app/oracle/product/19.3.0/dbhome_1/ /soft/LINUX.X64_193000_db_home.zip
[oracle@Jsls ~]$ su - root
[root@Jsls ~]# yum install libXp*.i686 libXt*.i686 libXtst libnsl.so.1 libXrender-0.9.10 -y
[oracle@node01 dbhome_1]$ cd /u01/app/oracle/product/19.3.0/dbhome_1/
[oracle@node01 dbhome_1]$ export CV_ASSUME_DISTID=RHEL8.8
[oracle@node01 dbhome_1]$ ./runInstaller
`
最后两步操作,在oracle用户会弹出一个窗口 有两条命令,需要新开一个root权限用户去操作
[root@node01 ~]# /u01/app/oraInventory/orainstRoot.sh
[root@node01 ~]# /u01/app/oracle/product/19.3.0/dbhome_1/root.sh
oracle安装成功后 如下提示信息
The response file for this session can be found at:
/u01/app/oracle/product/19.3.0/dbhome_1/install/response/db_2022-11-02_10-16-41PM.rsp
You can find the log of this install session at:
/tmp/InstallActions2022-11-02_10-16-41PM/installActions2022-11-02_10-16-41PM.log
Moved the install session logs to:
/u01/app/oraInventory/logs/InstallActions2022-11-02_10-16-41PM
在oracle用户下,用oracle用户登录,不要用 su - oracle 切换用户,因为没有用
执行成功后,创建监听 netca
11.测试监听
启动监听
lsnrctl start
lsnrctl stop
lsnrctl reload
lsnrctl status
启动监听后发现监听不支持任何服务,说明没有配置成功
The listener supports no services
The command completed successfully
[root@Jsls ~]# cd /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/
编辑监听文件,添加:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1)
)
)
重连oracle
出现ora-27101报错,解决方案
sqlplus /nolog
conn / as sysdba
startup
ora-12505
监听文件配置如下:
# listener.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Jsls)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/19.3.0/dbhome_1)
)
)
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = Jsls)(PORT = 1521))
JSLS =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = Jsls)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = Jsls)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Jsls)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
12.设置Oracle开机自启监听和数据库实例
修改 $ORACLE_HOME/bin/dbstart
[oracle@Jsls ~]$ vim $ORACLE_HOME/bin/dbstart
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
修改$ORACLE_HOME/bin/dbshut
[oracle@Jsls ~]$ vim $ORACLE_HOME/bin/dbshut
将ORACLE_HOME_LISTNER=$1修改为ORACLE_HOME_LISTNER=$ORACLE_HOME
13.修改/etc/oratab文件
[oracle@Jsls ~]$ vim /etc/oratab
将页末的N改为Y:
14.输入命令dbshut和dbstart测试
[oracle@localhost ~]$dbshut
[oracle@localhost ~]$dbstart
15.建立自启动脚本
[root@localhost init.d]# vim /etc/rc.d/init.d/oracle
添加以下内容(有些值如ORACLE_HOME和ORACLE_USER等根据实际情况可以修改):
#!/bin/bash
# oracle: Start/Stop Oracle Database 11g R2
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
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
16.修改/etc/init.d/oracle服务文件权限
[root@localhost bin]# chmod 755 /etc/init.d/oracle
17.设置为开机启动
[root@seiang11g ~]# chkconfig oracle on
18.进行测试
start:
[root@localhost bin]# service oracle start
stop:
[root@localhost bin]# service oracle stop
restart:
[root@localhost bin]# service oracle restart
19.Reboot重启
[root@localhost bin]# reboot
20.测试验证,重启数据库即可。
使用DataGrip测试远程连接oracle数据库
如果正常连接,就完成了数据库实例和监听的开机自启动了。
21.其他命令
oracle重启数据库,连接测试
以oracle身份登录数据库,输入命令:su – oracle ,然后输入密码
进入Sqlplus控制台,输入命令:sqlplus /nolog
以系统管理员登录,输入命令:connect /as sysdba
如果是启动数据库,输入命令:startup
如果是关闭数据库,输入命令:shutdown immediate
退出sqlplus控制台,输入命令:exit
进入监听器控制台,输入命令:lsnrctl
启动监听器,输入命令:start
退出监听器控制台,命令:exit
oracle监听器操作
lsnrctl status #查看监听状态
lsnrctl start #启动监听器