服務器採用的是阿里雲,具體看下面java
[root@aliyun_test var]# cat /etc/system-releaselinux
CentOS release 6.5 (Final)c++
[root@aliyun_test var]# uname -rsql
2.6.32-431.23.3.el6.x86_64數據庫
[root@aliyun_test var]# uname -nvim
aliyun_testbash
內存:
服務器
因爲阿里雲默認是沒有swap的,因此這個須要本身建立,後面會提到如何建立session
靜默安裝前一些必要的操做oracle
#####install java
rpm -ivh jdk-7u75-linux-x64.rpm
echo "export JAVA_HOME=/usr/java/jdk1.7.0_75" >> /etc/profile.d/java.sh
echo "export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile.d/java.sh
echo "export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar" >>/etc/profile.d/java.sh
. /etc/profile.d/java.sh
######verify java
java -version
一些必須的包
yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 ksh elfutils-libelf \
elfutils-libelf-devel glibc glibc-common glibc-devel gcc gcc-c++ libaio \
libaio.i686 libaio-devel libaio-devel.i686 libgcc libstdc++ libstdc++.i686 \
libstdc++-devel libstdc++-devel.i686 make sysstat unixODBC unixODBC-devel unzip
而後是一些內核參數調整
########modify /etc/sysctl.conf
echo "fs.aio-max-nr = 1048576" >> /etc/sysctl.conf
echo "fs.file-max = 6815744" >> /etc/sysctl.conf
echo "kernel.shmmni = 4096" >> /etc/sysctl.conf
echo "kernel.sem = 250 32000 100 128" >> /etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 9000 65500" >> /etc/sysctl.conf
echo "net.core.rmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.rmem_max = 4194304" >> /etc/sysctl.conf
echo "net.core.wmem_default = 262144" >> /etc/sysctl.conf
echo "net.core.wmem_max = 1048576" >> /etc/sysctl.conf
/sbin/sysctl -p
而後是軟硬文件打開數
##############modify /etc/security/limits.conf
echo "oracle soft nproc 2047" >> /etc/security/limits.conf
echo "oracle hard nproc 16384" >> /etc/security/limits.conf
echo "oracle soft nofile 1024" >> /etc/security/limits.conf
echo "oracle hard nofile 65536" >> /etc/security/limits.conf
建立oracle用戶
#########create user oracle
/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/useradd -g oinstall -G dba oracle
passwd oracle
mkdir /u01/app -p
chown -R oracle:oinstall /u01
chmod 755 /u01/app
建立oracle清單文件
########create oraInventory
echo "inventory_loc=/u01/app/oraInventory" >> /etc/oraInst.loc
echo "inst_group=oinstall" >> /etc/oraInst.loc
chown -R oracle:oinstall /etc/oraInst.loc
chmod 755 /etc/oraInst.loc
添加登陸認證
########modify /etc/pam.d/login
#add
session required pam_limits.so
修改/etc/profile 限制其餘用戶使用
############modify /etc/profile
# add follows to the end
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
而後切換oracle用戶進行操做
#########for oracle user
su - oracle
cd /home/oracle
file1:wget http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.zip
file2:wget http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip
vim .bash_profile
export ORACLE_BASE=/u01/app
export ORACLE_SID=test
unzip linux.x64_11gR2_database_1of2.zip -d /u01/app
unzip linux.x64_11gR2_database_2of2.zip -d /u01/app
因爲是使用靜默文件安裝oracle,因此必須建立修改響應文件(具體參數說明請參考官方網站)
cp /u01/app/database/response/db_install.rsp /home/oracle
chmod 700 /home/oracle/*.rsp
####add to rsp
修改如下值
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle11g
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN,zh_TW
ORACLE_HOME=/u01/app/product/11.2.0/dbhome_1
ORACLE_BASE=/u01/app
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=false
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=test
oracle.install.db.config.starterdb.SID=test
oracle.install.db.config.starterdb.memoryLimit=512
oracle.install.db.config.starterdb.password.ALL=redhat
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
準備工做就緒後,因而進行安裝
#######silent install oracle
cd /u01/app
./database/runInstaller -silent -responseFile /home/oracle/db_install.rsp
請根據屏幕上的輸出信息進行相應的措施(因爲是阿里雲主機,swap要求沒有達到)
swap內存作以下操做:
若是交換空間不夠:針對阿里雲主機或者swap爲0的主機
dd if=/dev/zero of=/test bs=1G count=4----》若是這種方法不行,請選擇下面
mkswap -f /test
swapon /test
free -m
設置2G的swap空間
[root@aliyun_test var]# dd if=/dev/zero of=/var/test bs=1G count=2
dd: memory exhausted
[root@aliyun_test var]# dd if=/dev/zero of=/var/test bs=1024 count=2097152
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB) copied, 38.0205 s, 56.5 MB/s
[root@aliyun_test var]# du -sh /var/test
2.1G /var/test
[root@aliyun_test var]# mkswap -f /var/test
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=d3ba4921-7d5e-47ae-810b-44f2369a24c2
[root@aliyun_test var]# swapon /var/test
[root@aliyun_test var]# free -m
total used free shared buffers cached
Mem: 994 930 63 0 31 809
-/+ buffers/cache: 89 905
Swap: 2047 0 2047
安裝到出現以下叫你使用root用戶執行如下腳本
/u01/app/product/11.2.0/dbhome_1/root.sh
因而使用另外一會話終端執行
[root@aliyun_test ~]# /u01/app/product/11.2.0/dbhome_1/root.sh
Check /u01/app/product/11.2.0/dbhome_1/install/root_aliyun_test_2016-09-20_10-20-22.log for the output of root script
而後回到oracle用戶那個終端敲入enter鍵就安裝完成
而後繼續修改oracle家目錄下的環境文件以下
vim /home/oracle/.bash_profile
export ORACLE_HOME=/u01/app/product/11.2.0/dbhome_1
PATH=${ORACLE_HOME}/bin:$PATH:$HOME/bin
下一步就是配置監聽服務,具體操做以下
啓動監聽
###############modify netca.rsp
cp database/response/netca.rsp /home/oracle/
vim /home/oracle/netca.rsp
GENERAL]
RESPONSEFILE_VERSION="11.2"
CREATE_TYPE="CUSTOM"
INSTALL_TYPE=""custom" "安裝的類型("typical—典型","minimal—最小" or "custom—自定義")
LISTENER_NUMBER=1 監聽器數量
LISTENER_NAMES={"test"} 監聽器的名稱列表
LISTENER_PROTOCOLS={"TCP;1521"} 監聽器使用的通信協議列表
LISTENER_START=""test"" 監聽器啓動的名稱
而後運行:
netca /silent /responsefile /home/oracle/netca.rsp
[oracle@aliyun_test app]$ netca /silent /home/oracle/netca.rsp
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /opt/oracle/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Configuring Listener:test
Listener configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/u01/app/product/11.2.0/dbhome_1/bin/lsnrctl start test
Listener Control complete.
Listener started successfully.
Profile configuration complete.
Oracle Net Services configuration successful. The exit code is 0
監聽配置完,端口就會開啓,查看一下
[root@aliyun_test ~]# netstat -tunlp|grep 1521
tcp 0 0 0.0.0.0:1521 0.0.0.0:* LISTEN 17760/tnslsnr
/u01/app/product/11.2.0/dbhome_1/bin/tnslsnr test(這條命令啓動的)
最後建立單實例數據庫
靜默創建新庫
cp database/response/dbca.rsp /home/oracle/
vim /home/oracle/dbca.rsp
而後修改如下:
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0" //不能更改
OPERATION_TYPE = "createDatabase"
GDBNAME = "test" //全局數據庫的名字=SID+主機域名
SID= "test" //對應的實例名字
TEMPLATENAME = "General_Purpose.dbc" //建庫用的模板文件
SYSPASSWORD = "redhat" //SYS管理員密碼
SYSTEMPASSWORD = "redhat" //SYSTEM管理員密碼
DATAFILEDESTINATION = /u01/app/oradata //數據文件存放目錄
RECOVERYAREADESTINATION=/u01/app/flash_recovery_area //恢復數據存放目錄
CHARACTERSET = "AL32UTF8" //字符集,重要!!! 建庫後通常不能更改,因此建庫前要肯定清楚。(CHARACTERSET = "AL32UTF8"
NATIONALCHARACTERSET= "UTF8")
TOTALMEMORY = "380" //oracle內存
而後靜默建庫
dbca -silent -responseFile /home/oracle/dbca.rsp
如此以後數據庫建立完成,使用sqlplus命令操做,進行登陸
登陸的用戶採用的system密碼爲redhat,上述操做都有記錄
至此靜默安裝oracle完成
啓動監聽:
[oracle@oracle admin]$ lsnrctl start test
查看端口1521是否開啓
啓動數據庫:
[oracle@oracle admin]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 26 14:37:17 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 584568832 bytes
Fixed Size 2215544 bytes
Variable Size 490733960 bytes
Database Buffers 88080384 bytes
Redo Buffers 3538944 bytes
Database mounted.
Database opened.
鏈接數據庫:
[oracle@oracle admin]$ echo $ORACLE_SID
test
[oracle@oracle admin]$ sqlplus system/redhat@test
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 26 14:42:34 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-28002: the password will expire within 7 days
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>
[oracle@oracle admin]$ echo $SERVICE_NAME
oracle.test
[oracle@oracle admin]$ sqlplus system/redhat@192.168.223.138:1521/oracle.test
SQL*Plus: Release 11.2.0.1.0 Production on Wed Jul 26 14:44:02 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-28002: the password will expire within 7 days
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>