阿里雲centos安裝oracle

阿里雲centos安裝oracle

阿里雲默認沒有swap分區,oracle安裝須要

建立swap分區是爲了彌補物理內存的不足,也就是虛擬內存的概念,把硬盤的一部分劃分做爲虛擬內存,但這個空間不是越大越好,硬盤的速度遠低於內存,設置不當反而拖慢系統的速度。c++

阿里雲的主機默認沒有swap分區,能夠使用free命令查看。sql

  1. 使用dd命令建立一個swap分區: dd if=/dev/zero of=/home/swap bs=1024 count=1048576 (count的值是:size(多少M)* 1024,我這裏設置的1G虛擬內存,也就是count=1024000)shell

  2. 格式化swap分區: mkswap /home/swap數據庫

  3. 把格式化後的文件分區設置爲swap分區: swapon /home/swap (關閉SWAP分區命令爲:[root@localhost Desktop]#swapoff /home/swap)vim

  4. swap分區自動掛載:vi /etc/fstab 在文件末尾加上"/home/swap swap swap default 0 0"centos

安裝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下)bash

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目錄。oracle

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命令啓動偵聽器

相關文章
相關標籤/搜索