github twitter email rss
通过SSH安装oracle
Aug 27, 2014
2 minutes read

上一篇说到安装ArchLinux后,现在需安装Oracle

安装之前

cd ~
pacman -S vim ssh abs unzip wget xorg-xhost
wget https://aur.archlinux.org/packages/au/aura-bin/aura-bin.tar.gz
tar -xzf aura-bin.tar.gz
cd aura-bin
makepkg
pacman -U aura-bin-x.x.x.x-x-x86_64.pkg.tar.xz

下载oracle有两种方法

-1. 一种登录oracle网站下载好保存在本地,再通过sftp等方法传至服务器
2. 用chrome导出登录后的cookie,并用wget直接通过服务器端下载,插件下载:[地址](https://chrome.google.com/webstore/detail/cookietxt-export/lopabhfecdfhgogdbojmaicoicjekelh)

wget --load-cookies cookie_txt_file  http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_1of2.zip 
http://download.oracle.com/otn/linux/oracle11g/R2/linux.x64_11gR2_database_2of2.zip

解压安装包

find . -name '*of2.zip' -exec unzip {} \;

oracle required packages

pacman -S sudo icu gawk gdb elfutils sysstat libstdc++5 jre7-openjdk libaio
aura -Akua beecrypt rpm-org
aura -A ksh

添加用户,与用户组

groupadd oinstall
groupadd dba
groupadd oper
groupadd asmadmin

useradd -g oinstall -G dba,oper,asmadmin oracle -b /oracle
passwd oracle

处理sysctl, limits.conf

cat > /etc/sysctl.d/99-sysctl.conf << EOF
fs.suid_dumpable = 1
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
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=1048586
EOF
vim /etc/security/limits.conf
oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  4096
oracle              hard    nofile  65536
oracle              soft    stack   10240

建立安装目录并设立权限

mkdir -p /oracle/inventory /oracle/recovery /oracle/product/db /oracle/tmp
chown -R oracle:dba /oracle
chmod 777 /oracle/tmp

编辑oracle用户的.bashrc

#Oracle Settings
export TMP=/tmp
export TMPDIR=/tmp
export ORACLE_HOSTNAME=oracledb.localdomain
export ORACLE_UNQNAME=xdb
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/db
export ORACLE_SID=xdb
export ORACLE_INVENTORY=/oracle/inventory
export ORACLE_BASE ORACLE_SID ORACLE_HOME
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export EDITOR=vim
export VISUAL=vim

开始安装,<machine-name>可以留空,这样就指定即在服务器本机打开X视窗安装

DISPLAY=<machine-name>:0.0; export DISPLAY

如果为通过SSH远程安装oracle,则可通过ssh的x11 forwarding功能,通过本地的X server来开启安装窗口,这里博主用的是Xming。 Xming的安装包有自带putty,如果已经有putty了可以不安装。 putty需要进行如下配置,开启x11 forwarding

Session
    Host Name 填入无端IP
    Saved Sessions 填入要保存的名称
Connection
    SSH
        X11
            Enable X11 forwarding 开启
            X display location 填入 localhost:0.0 或 127.0.0.1:0.0

运行Xming中的XLaunch将No Access Control勾上 最后将代码中的ip地址替换成运行有Xming的主机IP,并运行

使用oracle用户通过ssh连接至服务器
DISPLAY=<Local IP addr>:0.0; export DISPLAY;xhost +
cd /安装包路径
./runInstaller

图形化的安装界面略过~~ 安装后,让数据库自启 新建启动和关闭的脚本

mkdir -p ~/scripts
chown oracle.oinstall ~/scripts

~/scripts/startup.sh

#!/bin/bash

#Oracle Settings
export TMP=/oracle/tmp
export TMPDIR=/oracle/tmp
export ORACLE_HOSTNAME=oracledb.localdomain
export ORACLE_UNQNAME=xdb
export ORACLE_SID=xdb
export PATH=$ORACLE_HOME/bin:$PATH

ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES

# Start Listener
lsnrctl start

# Start Database
sqlplus / as sysdba << EOF
STARTUP;
EXIT;
EOF

~/scripts/shutdown.sh

#!/bin/bash

#Oracle Settings
export TMP=/oracle/tmp
export TMPDIR=/oracle/tmp
export ORACLE_HOSTNAME=oracledb.localdomain
export ORACLE_UNQNAME=xdb
export ORACLE_SID=xdb
export PATH=$ORACLE_HOME/bin:$PATH

ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES

# Stop Database
sqlplus / as sysdba << EOF
SHUTDOWN IMMEDIATE;
EXIT;
EOF

# Stop Listener
lsnrctl stop

脚本权限

chmod u+x /oracle/scripts/s*.sh
chown oracle.oinstall /oracle/scripts/s*.sh

建立服务 /lib/systemd/system/dbora.service

[Unit]
Description=The Oracle Database Service
After=syslog.target network.target

[Service]
Type=simple
ExecStart=/bin/su oracle -c "/oracle/scripts/startup.sh >> /oracle/scripts/startup_shutdown.log 2>&1" &
ExecStop=/bin/su oracle -c "/oracle/scripts/shutdown.sh >> /oracle/scripts/startup_shutdown.log 2>&1"

[Install]
WantedBy=multi-user.target
ln -s /lib/systemd/system/dbora.service /etc/systemd/system/dbora.service
systemctl daemon-reload
systemctl enable dbora.service

查看服务状态

systemctl status dbora.service

enjoy~!

quote from wiki.archlinux.org oracle-base


Back to posts


comments powered by Disqus