1.下载Linux.x64_11gR2的安装包,并上传到虚拟机
链接: https://pan.baidu.com/s/1IDCwWsK26RRuOxyOs39ELg 提取码: 3km6
2.修改主机HostName为 : oracledb
hostnamectl set-hostname oracledb echo "127.0.0.1 oracledb" >>/etc/hosts
3.关闭selinux
// 使用sed -i 指令直接修改读取到的 /etc/selinux/config文件中的字符串 也就是将SELINUX=enforcing的值修改为disable sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config // #临时关闭selinux setenforce 0 // 关闭firewalld 防火墙 systemctl stop firewalld.service
4.yum安装需要的环境配置
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
5.安装完成检查依赖是否安装成功
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"
6.创建宿主机使用oracle所需的操作系统组和用户
groupadd oinstall groupadd dba groupadd oper useradd -g oinstall -G dba oracle
7.需要oracle用户密码
passwd oracle
8.修改内核信息
// vi /etc/sysctl.conf 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
9.修改认证模块
// vi /etc/security/limits.conf oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536
10.修改登录配置文件
// vi /etc/pam.d/login session required /lib64/security/pam_limits.so session required pam_limits.so
11.修改用户登录时运行的环境变量设置
// 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
12.让配置文件生效
source /etc/profile
13.禁用使用Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)
[always]
说明启用了cat /sys/kernel/mm/transparent_hugepage/enabled
[never]
echo never > /sys/kernel/mm/transparent_hugepage/enabled
14.创建orale数据库安装目录(可自定义安装目录,注意后边关于路径的配置都要一并进行修改)
mkdir -p /usr/local/oracle/ chown -R oracle:oinstall /usr/local/oracle/ chmod -R 775 /usr/local/oracle/
15.配置oracle用户环境变量
// vi /home/oracle/.bash_profile umask 022 export ORACLE_HOSTNAME=oracledb export ORACLE_BASE=/usr/local/oracle/ora 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"
16.重启一下系统
reboot
17.将上传的两个oracle的文件解压缩 (我上传的目录是: /home/io/ 下)
cd /home/io unzip linux.x64_11gR2_database_1of2.zip -d /home/io unzip linux.x64_11gR2_database_2of2.zip -d /home/io // 解压后会出现一个 database的文件夹 mkdir -p /home/io/etc cp /home/io/database/response/* /home/io/etc/ chmod 777 /home/io/etc/*.rsp
// vi /home/io/etc/db_install.rsp oracle.install.option=INSTALL_DB_SWONLY ORACLE_HOSTNAME=oracledb UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/usr/local/oracle/ora/inventory SELECTED_LANGUAGES=en,zh_CN ORACLE_HOME=/usr/local/oracle/ora/product/11.2.0/db_1 ORACLE_BASE=/usr/local/oracle/ora oracle.install.db.InstallEdition=EE oracle.install.db.isCustomInstall=true oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=oinstall oracle.install.db.config.starterdb.type=GENERAL_PURPOSE oracle.install.db.config.starterdb.globalDBName=orcl oracle.install.db.config.starterdb.SID=orcl oracle.install.db.config.starterdb.memoryLimit=512 oracle.install.db.config.starterdb.password.ALL=oracle DECLINE_SECURITY_UPDATES=true
1.切换成oracle用户,并执行安装程序
su - oracle cd /home/io/database // 执行安装指令 配置文件是/home/io/etc/ 下的配置文件 ./runInstaller -silent -responseFile /home/io/etc/db_install.rsp -ignorePrereq //安装期间可以使用tail命令监看oracle的安装日志 (这个安装过程会有点慢,耐心等待...) tail -f /usr/local/oracle/ora/inventory/logs/installActions2021-08-04_02-56-30PM.log
2.使用root用户执行一下指令
su - root sh /usr/local/oracle/ora/inventory/orainstRoot.sh sh /usr/local/oracle/ora/product/11.2.0/db_1/root.sh
3.修改并完善oracle用户环境变量 (主要是路径的修改是对安装前环境准备的第15步的调整,至于在上一步能不能直接使用这个文件我也不是很清楚,估计是可以,我是按照自己的安装进行记录的)
su - oracle vi ~/.bash_profile umask 022 export ORACLE_HOSTNAME=oracledb export ORACLE_BASE=/usr/local/oracle/ora export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 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" export TNS_ADMIN=$ORACLE_HOME/network/admin export PATH=.:${PATH}:$HOME/bin:$ORACLE_HOME/bin export PATH=${PATH}:/usr/bin:/bin:/usr/local/bin export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/lib export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib export LIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib export ORACLE_OWNER=oracle export SPFILE_PATH=$ORACLE_HOME/dbs export ORA_NLS10=$ORACLE_HOME/nls/data
4.配置监听程序
su - oracle // 切换oracle用户,并进入对应路径的bin目录下 [oracle@oracledb bin]$ pwd /usr/local/oracle/ora/product/11.2.0/db_1/bin // 开启监听: 执行之前拷贝的配置文件,/home/io/etc/ 路径下的文件 [oracle@oracle bin]$ ./netca /silent /responseFile /home/io/etc/netca.rsp
5.查看监听端口
netstat -tnpl | grep 1521
1.编辑应答文件 vi /home/io/ect/dbca.rsp 修改对应的参数
su - oracle vi /home/io/ect/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 =/usr/local/oracle/ora/oradata RECOVERYAREADESTINATION=/usr/local/oracle/ora/fast_recovery_area CHARACTERSET = "AL32UTF8" TOTALMEMORY = "1638"
2.执行静默建库
su - oracle //执行静默创建数据库,注意路径细节 $ORACLE_HOME/bin/dbca -silent -responseFile /home/io/ect/dbca.rsp
3.查看进程
ps -ef | grep ora_ | grep -v grep
4.监听状态
lsnrctl status
ps: 如果监听出现问题请查看以下这个教程:
监听显示异常点击
5.数据库安装成功,开始登录数据库
su - oracle sqlplus / as sysdba
su - oracle // 进入系统管理用户 sqlplus / as sysdba // 启动实例 startup; // 查询数据库实例信息 select status from v$instance;
1.输入以上指令,发现都报错!
2.更具提示信息进行修改
// 将形如/usr/local/oracle/ora/admin/orcl/pfile/init.ora.742021164145的文件 拷贝到 /usr/local/oracle/ora/product/11.2.0/db_1/dbs/路径下 并改名 cp /usr/local/oracle/ora/admin/orcl/pfile/init.ora.742021164145 /usr/local/oracle/ora/product/11.2.0/db_1/dbs/initORCL.ora
3.ORA-01102: cannot mount database in EXCLUSIVE mode错误
ORA-01102:异常点击
4.重新启动后:查看数据库版本信息
select * from v$version;
1.激活scott用户
alter user scott account unlock; alter user scott identified by tiger; select username,account_status from dba_users;
2.设置oracle开机启动
vi /usr/local/oracle/ora/product/11.2.0/db_1/bin/dbstart ORACLE_HOME_LISTNER=$ORACLE_HOME vi /usr/local/oracle/ora/product/11.2.0/db_1/bin/dbshut ORACLE_HOME_LISTNER=$ORACLE_HOME vi /etc/oratab orcl:/data/app/oracle/product/11.2.0:Y
3.新建文件/etc/rc.d/init.d/oracle
vi /etc/rc.d/init.d/oracle // 文件中添加以下内容 # processname: oracle . /etc/rc.d/init.d/functions LOCKFILE=/var/lock/subsys/oracle ORACLE_HOME=/usr/local/oracle/ora/product/11.2.0/db_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
4.给/etc/init.d/oracle
添加执行权限
chmod +x /etc/init.d/oracle
5.开机启动oracle
systemctl enable oracle 或 chkconfig oracle on
6.给启动文件加权限
cd /usr/local/oracle/ora/product/11.2.0/db_1/bin/ chmod 6751 oracle cd /var/tmp chown -R oracle:oinstall .oracle
7.防火墙配置放开oracle的端口 (默认oracle是 1521端口)
firewall-cmd --zone=public --add-port=1521/tcp --permanent firewall-cmd --reload