[toc] 阿裡雲centos安裝oracle 阿裡雲預設沒有swap分區,oracle安裝需要 創建swap分區是為了彌補物理記憶體的不足,也就是虛擬記憶體的概念,把硬碟的一部分劃分作為虛擬記憶體,但這個空間不是越大越好,硬碟的速度遠低於記憶體,設置不當反而拖慢系統的速度。 阿裡雲的主機預設沒有swap分 ...
目錄
阿裡雲centos安裝oracle
阿裡雲預設沒有swap分區,oracle安裝需要
創建swap分區是為了彌補物理記憶體的不足,也就是虛擬記憶體的概念,把硬碟的一部分劃分作為虛擬記憶體,但這個空間不是越大越好,硬碟的速度遠低於記憶體,設置不當反而拖慢系統的速度。
阿裡雲的主機預設沒有swap分區,可以使用free命令查看。
使用dd命令創建一個swap分區: dd if=/dev/zero of=/home/swap bs=1024 count=1048576 (count的值是:size(多少M)* 1024,我這裡設置的1G虛擬記憶體,也就是count=1024000)
格式化swap分區: mkswap /home/swap
把格式化後的文件分區設置為swap分區: swapon /home/swap (關閉SWAP分區命令為:[root@localhost Desktop]#swapoff /home/swap)
swap分區自動掛載:vi /etc/fstab 在文件末尾加上"/home/swap swap swap default 0 0"
安裝Oracle所需的依賴包
yum -y install gcc gcc-c++ make binutils compat-libstdc++-33 glibc glibc-devel libaio libaio-devel libgcc libstdc++ libstdc++-devel unixODBC unixODBC-devel sysstat ksh
創建用戶和組
groupadd -g 200 oinstall #添加oinstall組,組的id為200
groupadd -g 201 dba #添加dba組,組的id為201
useradd -u 440 -g oinstall -G dba oracle #添加用戶oracle,並specified它的id為440.
passwd oracle #輸入oracle用戶的密碼
id oracle #查看用戶id和所屬組。
關閉SELINUX(阿裡雲預設關閉)
vim /etc/selinux/config #編輯配置文件,關閉SELINUX
setenforce 0 #立即關閉SELINUX
開始安裝
使用“su - u oracle”切換到oracle賬號下
把下麵兩個文件上傳到CentOS7-64bits伺服器的/app/oracle目錄下(我比較喜歡把軟體安裝在/app下)
linux.x64_11gR2_database_1of2.zip和linux.x64_11gR2_database_2of2.zip
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip
在/app/oracle目錄下會出現database目錄。
vim /app/oracle/database/response/db_install.rsp
修改db_install.rsp文件
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=可以寫本機地址
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/app/oracle/oraInventory
SELECTED_LANGUAGES=zh_CN,en
ORACLE_HOME=/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/app/oracle
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=orcl
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=512
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=oracle2018
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false
oracle.install.db.config.starterdb.automatedBackup.enable=false
DECLINE_SECURITY_UPDATES=true
安裝Oracle
oracle賬號登陸,在/app/oracle/database路徑下執行開始安裝
./runInstaller -silent -responseFile /app/oracle/database/response/db_install.rsp
安裝成功之後會出現如下:
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/app/oracle/oraInventory/orainstRoot.sh
/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身份登錄CentOS7系統執行如下命令
/app/oracle/oraInventory/orainstRoot.sh
/app/oracle/product/11.2.0/db_1/root.sh
以oracle身份登錄CentOS7系統,設置環境變數
vi ~/.bash_profile
export PATH
export ORACLE_BASE=/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=orcl
export TNS_ADMIN=$ORACLE_HOME/network/admin
使用下麵命令使環境變數生效:source ~/.bash_profile
為了使sqlplus能夠訪問遠程oracle資料庫,不但要配置“TNS_ADMIN”環境變數,還需要環境變數指向的地址(我這裡是/app/oracle/product/11.2.0/db_1/network/admin/)中放入tnsnames.ora文件
下麵是我tnsnames.ora的內容,其中orcl是資料庫名字。
localoracle =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
建庫
確認並修改/app/oracle/database/response/dbca.rsp,其中修改的都是CREATEDATABASE操作的內容,其他的不動。
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
CHARACTERSET="AL32UTF8"
用oracle賬號調用下麵的命令
dbca -silent -responseFile /app/oracle/database/response/dbca.rsp
#執行結束後需要輸入2次oracle設置的密碼
驗證Oracle安裝是否成功:
su - u oracle
sqlplus "/as sysdba"
select * from tabs;
如果成功運行,表示oracle已經啟來,否則需要運行“startup”命令啟動oracle.
添加listener.ora文件
位置:/app/oracle/product/11.2.0/db_1/network/admin
文件內容
# copyright (c) 1997 by the Oracle Corporation
#
# NAME
# listener.ora
# FUNCTION
# Network Listener startup parameter file example
# NOTES
# This file contains all the parameters for listener.ora,
# and could be used to configure the listener by uncommenting
# and changing values. Multiple listeners can be configured
# in one listener.ora, so listener.ora parameters take the form
# of SID_LIST_<lsnr>, where <lsnr> is the name of the listener
# this parameter refers to. All parameters and values are
# case-insensitive.
# <lsnr>
# This parameter specifies both the name of the listener, and
# it listening address(es). Other parameters for this listener
# us this name in place of <lsnr>. When not specified,
# the name for <lsnr> defaults to "LISTENER", with the default
# address value as shown below.
#
# LISTENER =
# (ADDRESS_LIST=
# (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
# (ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
LISTENER=(DESCRIPTION_LIST=(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))
)
)
# SID_LIST_<lsnr>
# List of services the listener knows about and can connect
# clients to. There is no default. See the Net8 Administrator's
# Guide for more information.
#
# SID_LIST_LISTENER=
# (SID_LIST=
# (SID_DESC=
# #BEQUEATH CONFIG
# (GLOBAL_DBNAME=salesdb.mycompany)
# (SID_NAME=sid1)
# (ORACLE_HOME=/private/app/oracle/product/8.0.3)
# #PRESPAWN CONFIG
# (PRESPAWN_MAX=20)
# (PRESPAWN_LIST=
# (PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1))
# )
# )
# )
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcl)
(SID_NAME=orcl)
(ORACLE_HOME=/app/oracle/product/11.2.0/db_1)
(PRESPAWN_MAX=20)
(PRESPAWN_LIST=
(PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1))
)
)
)
# PASSWORDS_<lsnr>
# Specifies a password to authenticate stopping the listener.
# Both encrypted and plain-text values can be set. Encrypted passwords
# can be set and stored using lsnrctl.
# LSNRCTL> change_password
# Will prompt for old and new passwords, and use encryption both
# to match the old password and to set the new one.
# LSNRCTL> set password
# Will prompt for the new password, for authentication with
# the listener. The password must be set before running the next
# command.
# LSNRCTL> save_config
# Will save the changed password to listener.ora. These last two
# steps are not necessary if SAVE_CONFIG_ON_STOP_<lsnr> is ON.
# See below.
#
# Default: NONE
#
# PASSWORDS_LISTENER = 20A22647832FB454 # "foobar"
# SAVE_CONFIG_ON_STOP_<lsnr>
# Tells the listener to save configuration changes to listener.ora when
# it shuts down. Changed parameter values will be written to the file,
# while preserving formatting and comments.
# Default: OFF
# Values: ON/OFF
#
# SAVE_CONFIG_ON_STOP_LISTENER = ON
# USE_PLUG_AND_PLAY_<lsnr>
# Tells the listener to contact an Onames server and register itself
# and its services with Onames.
# Values: ON/OFF
# Default: OFF
#
# USE_PLUG_AND_PLAY_LISTENER = ON
# LOG_FILE_<lsnr>
# Sets the name of the listener's log file. The .log extension
# is added automatically.
# Default=<lsnr>
#
# LOG_FILE_LISTENER = lsnr
# LOG_DIRECTORY_<lsnr>
# Sets the directory for the listener's log file.
# Default: <oracle_home>/network/log
#
# LOG_DIRECTORY_LISTENER = /private/app/oracle/product/8.0.3/network/log
# TRACE_LEVEL_<lsnr>
# Specifies desired tracing level.
# Default: OFF
# Values: OFF/USER/ADMIN/SUPPORT/0-16
#
# TRACE_LEVEL_LISTENER = SUPPORT
# TRACE_FILE_<lsnr>
# Sets the name of the listener's trace file. The .trc extension
# is added automatically.
# Default: <lsnr>
#
# TRACE_FILE_LISTENER = lsnr
# TRACE_DIRECTORY_<lsnr>
# Sets the directory for the listener's trace file.
# Default: <oracle_home>/network/trace
#
# TRACE_DIRECTORY_LISTENER=/private/app/oracle/product/8.0.3/network/trace
# CONNECT_TIMEOUT_<lsnr>
# Sets the number of seconds that the listener waits to get a
# valid database query after it has been started.
# Default: 10
#
# CONNECT_TIMEOUT_LISTENER=10
使用lsnrctl start命令啟動偵聽器