1 安裝centos7系統環境(2核2G40G盤)
html
使用centos7.2系統,也就是CentOS-7-x86_64-DVD-1511.iso鏡像,最小化安裝便可。linux
安裝完成後調整網絡設置IP,關閉關閉防火牆和selinux
c++
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 ##配置網路 ##重啓網絡 systemctl restart network ##安裝工具 yum isntall vim wget net-tools unzip -y ##關閉防火牆 #關閉selinux sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0 systemctl stop firewalld systemctl disable firewalld ## 設置主機名 hostnamectl set-hostname tester hostname tester vim /etc/hosts 192.168.1.5
2 下載oracle 11g
sql
官網下載,下載的包以下,上傳到機器上便可。
數據庫
linux.x64_11gR2_database_1of2.zipvim
linux.x64_11gR2_database_2of2.zipcentos
3 安裝依賴包
bash
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686 檢查依賴包是否都安裝成功 (ksh和pdksh是衝突的,選擇ksh) rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep "not installed" 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
4 建立oinstall和dba組和oracle用戶服務器
/usr/sbin/groupadd oinstall /usr/sbin/groupadd dba /usr/sbin/useradd -g oinstall -G dba oracle 設置oracle用戶密碼 passwd oracle 驗證用戶是否正確 id oracle [root@tester ~]$ id oracle uid=1000(oracle) gid=1000(oinstall) 組=1000(oinstall),1001(dba)
5 配置內核參數網絡
vim /etc/sysctl.conf fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 1073741824 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 ----------------------參數解讀----------------------- shmmax=物理內存*80%*80%,單位是字節 kernel.shmmax:表示單個共享內存段的最大值,以字節爲單位,此值通常爲物理內存的一半,不過大一點也不要緊,這裏設定的爲4GB,即「4294967295/1024/1024/1024=4G」。 kernel.shmmin:表示單個共享內存段的最小值,默認爲1byte kernel.shmall:表示整個系統範圍內可用共享內存頁的總量,單位是頁(page),在32位系統上一頁等於4kB,也就是4096字節。計算公式是:shmmax/PAGE_SIZE kernel.shmmni:表示整個系統範圍內內存段的最大數量,通常爲4096. ip_local_port_range :表示端口的範圍。在監聽器幫助客戶端進程和服務器進程創建鏈接時,會用到指定範圍內的端口。 kernel.sem :表示設置的信號量,這4個參數內容大小固定。 net.core.rmem_default :表示接收套接字緩衝區大小的缺省值(以字節爲單位)。 net.core.rmem_max :表示接收套接字緩衝區大小的最大值(以字節爲單位) net.core.wmem_default :表示發送套接字緩衝區大小的缺省值(以字節爲單位)。 net.core.wmem_max :表示發送套接字緩衝區大小的最大值(以字節爲單位)。 ------------------------------------------------------ 當即生效 sysctl -p
6 修改系統配置文件
vim /etc/security/limits.conf #在末尾添加 oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 oracle soft stack 10240 oracle hard stack 10240 在/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
7 建立oracle安裝目錄
mkdir -p /opt/app/oracle/ chmod 755 /opt/app/oracle/ chown oracle.oinstall -R /opt/app/oracle/
8 設置oracle環境變量
使用oracle帳戶 #su - oracle $ vi ~/.bash_profile #設置oracle變量 export ORACLE_BASE=/opt/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin export ORACLE_PID=ora11g export NLS_LANG=AMERICAN_AMERICA.AL32UTF8 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib 完成後執行: env | grep ORA #查看環境變量是否完成 ORACLE_BASE=/opt/app/oracle ORACLE_HOME=/opt/app/oracle/product/11.2.0/db_1
9 安裝oracle
在/opt目錄下 解壓oracle軟件 [root@tester opt]# unzip linux.x64_11gR2_database_1of2.zip [root@tester opt]# unzip linux.x64_11gR2_database_2of2.zip 解壓後獲得database目錄,其中包含response目錄,該目錄中有三個rsp文件,用來做爲靜默安裝時的應答文件的模板。 三個文件做用分別是: db_install.rsp:安裝應答 dbca.rsp:建立數據庫應答 netca.rsp:創建監聽、本地服務名等網絡設置的應答
修改靜默安裝配置文件(注意修改對應的參數,比較重要,變量,名稱,路徑等)
[oracle@tester ~]$ cat /opt/database/response/db_install.rsp |grep -v "#" |grep -v "^$" oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 oracle.install.option=INSTALL_DB_SWONLY ORACLE_HOSTNAME=tester UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/opt/app/oracle/oraInventory SELECTED_LANGUAGES=en,zh_CN ORACLE_HOME=/opt/app/oracle/product/11.2.0/db_1 ORACLE_BASE=/opt/app/oracle oracle.install.db.InstallEdition=EE oracle.install.db.isCustomInstall=false oracle.install.db.customComponents=oracle.server:11.2.0.1.0,oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0 oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=oinstall oracle.install.db.CLUSTER_NODES= oracle.install.db.config.starterdb.type=GENERAL_PURPOSE oracle.install.db.config.starterdb.globalDBName=ora11g oracle.install.db.config.starterdb.SID=ora11g oracle.install.db.config.starterdb.characterSet=AL32UTF8 oracle.install.db.config.starterdb.memoryOption=true oracle.install.db.config.starterdb.memoryLimit=1500 oracle.install.db.config.starterdb.installExampleSchemas=false oracle.install.db.config.starterdb.enableSecuritySettings=true oracle.install.db.config.starterdb.password.ALL=oracle oracle.install.db.config.starterdb.password.SYS= oracle.install.db.config.starterdb.password.SYSTEM= oracle.install.db.config.starterdb.password.SYSMAN= oracle.install.db.config.starterdb.password.DBSNMP= oracle.install.db.config.starterdb.control=DB_CONTROL oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL= oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false oracle.install.db.config.starterdb.dbcontrol.emailAddress= oracle.install.db.config.starterdb.dbcontrol.SMTPServer= oracle.install.db.config.starterdb.automatedBackup.enable=false oracle.install.db.config.starterdb.automatedBackup.osuid= oracle.install.db.config.starterdb.automatedBackup.ospwd= oracle.install.db.config.starterdb.storageType= oracle.install.db.config.starterdb.fileSystemStorage.dataLocation= oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation= oracle.install.db.config.asm.diskGroup= oracle.install.db.config.asm.ASMSNMPPassword= MYORACLESUPPORT_USERNAME= MYORACLESUPPORT_PASSWORD= SECURITY_UPDATES_VIA_MYORACLESUPPORT= DECLINE_SECURITY_UPDATES=true PROXY_HOST= PROXY_PORT= PROXY_USER= PROXY_PWD=
開始靜默安裝
[oracle@tester ~]$ /opt/database/runInstaller -silent -force -responseFile /opt/database/response/db_install.rsp Starting Oracle Universal Installer... Checking Temp space: must be greater than 120 MB. Actual 165908 MB Passed Checking swap space: must be greater than 150 MB. Actual 16383 MB Passed 。。。。。 。。。。。(省略中間警告) The following configuration scripts need to be executed as the "root" user. #!/bin/sh #Root scripts to run /opt/app/oracle/oraInventory/orainstRoot.sh /opt/app/oracle/product/11.2.0/db_1/root.sh To execute the configuration scripts: 1. Open a terminal window 2. Log in as "root" 3. Run the scripts 4. Return to this window and hit "Enter" key to continue Successfully Setup Software. 安裝完畢後會提示上述的信息,按照要求執行上述腳本 新開一個窗口 用root 執行對應腳本 /opt/app/oracle/oraInventory/orainstRoot.sh /opt/app/oracle/product/11.2.0/db_1/root.sh 而後回到原窗口按enter便可
接着配置監聽程序啓動監聽程勳
[oracle@tester bin]$ $ORACLE_HOME/bin/netca /silent /responseFile /opt/database/response/netca.rsp Parsing command line arguments: Parameter "silent" = true Parameter "responsefile" = /opt/database/response/netca.rsp Done parsing command line arguments. Oracle Net Services Configuration: Profile configuration complete. Listener "LISTENER" already exists. Oracle Net Services configuration successful. The exit code is 0 啓動監控程序 $ /opt/app/oracle/product/11.2.0/db_1/bin/lsnrctl start LISTENER
靜默dbca建庫
vim /opt/database/response/dbca.rsp GDBNAME = "ora11g.tester"78 行 全局數據庫的名字=SID+主機域名 SID="ora11g" //149行 SID CHARACTERSET="AL32UTF8" //415行 編碼 NATIONALCHARACTERSET="UTF8" //425行 編碼 執行建庫 [oracle@tester response]$ $ORACLE_HOME/bin/dbca -silent -responseFile /opt/database/response/dbca.rsp Enter SYS user password: Enter SYSTEM user password: sh: /bin/ksh: No such file or directory sh: /bin/ksh: No such file or directory Copying database files 1% complete 3% complete 11% complete 18% complete 26% complete 37% complete Creating and starting Oracle instance 40% complete 45% complete 50% complete 55% complete 56% complete 57% complete 60% complete 62% complete Completing Database Creation 66% complete 70% complete 73% complete 74% complete 85% complete 96% complete 100% complete Look at the log file "/opt/app/oracle/cfgtoollogs/dbca/ora11g/ora11g.log" for further details.
啓動數據庫(默認等一下子會自動起)
注意必定要有SID環境變量
[oracle@tester ~]$ echo $ORACLE_SID
ora11g
[oracle@tester ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Thu Mar 21 18:44:19 2019 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> start SP2-1506: START, @ or @@ command has no arguments SQL> startup ORA-01081: cannot start already-running ORACLE - shut it down first SQL>
使用show parameter;或者select table_name from dba_tables看看是否
啓動監聽:lsnrctl start
查看監聽:lsnrctl status
中止監聽:lsnrctl stop
參考文檔: https://blog.csdn.net/u010469514/article/details/73822099 https://www.cnblogs.com/it1992/p/9468124.html https://blog.csdn.net/h8178/article/details/78251198
重啓oracle及監聽器
方法1: 用root以ssh登陸到linux,打開終端輸入如下命令: cd $ORACLE_HOME #進入到oracle的安裝目錄 dbstart #重啓服務器 lsnrctl start #重啓監聽器 cd $ORACLE_HOME #進入到oracle的安裝目錄 dbstart #重啓服務器 lsnrctl start #重啓監聽器 ----------------------------------- 方法2: Sql代碼 cd $ORACLE_HOME/bin #進入到oracle的安裝目錄 ./dbstart #重啓服務器 ./lsnrctl start #重啓監聽器 ----------------------------------- 方法3: (1) 以oracle身份登陸數據庫,命令:su -oracle (2) 進入Sqlplus控制檯,命令:sqlplus /nolog (3) 以系統管理員登陸,命令:connect / as sysdba (4) 啓動數據庫,命令:startup (5) 若是是關閉數據庫,命令:shutdown immediate (6) 退出sqlplus控制檯,命令:exit (7) 進入監聽器控制檯,命令:lsnrctl (8) 啓動監聽器,命令:start (9) 退出監聽器控制檯,命令:exit 2、重啓實例: (1) 切換須要啓動的數據庫實例:export ORACLE_SID=C1 (2) 進入Sqlplus控制檯,命令:sqlplus /nolog (3) 以系統管理員登陸,命令:connect / as sysdba (4) 若是是關閉數據庫,命令:shutdown abort (5) 啓動數據庫,命令:startup (6) 退出sqlplus控制檯,命令:exit