ubuntu 16.04 搭建 oracle11g 服务器(二)-------安装 oracle11g

时间:2022-05-12 08:31:32

一 : 安装

1.下载oracle11

在官网下载oracle11,下载地址如下: 
oracle11g:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

下载到/home下,有两个压缩文件,利用如下命令解压:

sudo tar -zxvf linux.x64_11gR2_database_1of2.zip sudo tar -zxvf linux.x64_11gR2_database_2of2.zip

解压完后,在home目录下生成一个database文件夹,这就是oracle的安装目录。

2.安装jdk1.8

https://blog.csdn.net/weixin_40461281/article/details/79779319


3.更新源文件

因为ubuntu的官方源并不全,特别是安装ia32-libs包的时候没有,首先我们备份源文件,然后把以下源增加到源列表:(删除原来的所有源,然后把下面的源粘贴进去):

sudo cp /etc/apt/sources.list /etc/apt/sources.list_back

把/etc/apt/sources.list源文件的内容替换成以下源:

deb http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse deb http://extras.ubuntu.com/ubuntu trusty main deb-src http://extras.ubuntu.com/ubuntu trusty main deb http://archive.ubuntu.com/ubuntu/ raring main restricted universe multiverse #163源: deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse #阿里源: deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyuncs.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyuncs.com/ubuntu/ trusty-backports main restricted universe multiverse 

4.安装依赖包

替换完后执行一下命令进行更新:

sudo apt-get update sudo apt-get upgrade

然后安装以下依赖包,务必要逐一执行,一定每个包都安装成功,要不然可能oracle安装不成功。

sudo apt-get install bzip2 sudo apt-get install elfutils sudo apt-get install automake sudo apt-get install autotools-dev sudo apt-get install binutils sudo apt-get install expat sudo apt-get install gawk sudo apt-get install gcc sudo apt-get install gcc-multilib sudo apt-get install g++-multilib sudo apt-get install ia32-libs sudo apt-get install ksh sudo apt-get install less sudo apt-get install lesstif2 sudo apt-get install lesstif2-dev sudo apt-get install lib32z1 sudo apt-get install libaio1 sudo apt-get install libaio-dev sudo apt-get install libc6-dev sudo apt-get install libc6-dev-i386 sudo apt-get install libc6-i386 sudo apt-get install libelf-dev sudo apt-get install libltdl-dev sudo apt-get install libmotif4 sudo apt-get install libodbcinstq4-1 libodbcinstq4-1:i386 sudo apt-get install libpth-dev sudo apt-get install libpthread-stubs0 sudo apt-get install libpthread-stubs0-dev sudo apt-get install libstdc++5 sudo apt-get install lsb-cxx sudo apt-get install make sudo apt-get install openssh-server sudo apt-get install pdksh sudo apt-get install rlwrap sudo apt-get install rpm sudo apt-get install sysstat sudo apt-get install unixodbc sudo apt-get install unixodbc-dev sudo apt-get install unzip sudo apt-get install x11-utils sudo apt-get install zlibc

5.检查系统变量

sudo /sbin/sysctl -a | grep sem sudo /sbin/sysctl -a | grep shm sudo /sbin/sysctl -a | grep file-max sudo /sbin/sysctl -a | grep aio-max sudo /sbin/sysctl -a | grep ip_local_port_range sudo /sbin/sysctl -a | grep rmem_default sudo /sbin/sysctl -a | grep rmem_max sudo /sbin/sysctl -a | grep wmem_default sudo /sbin/sysctl -a | grep wmem_max 

然后根据上面命令中得到的参数值在/etc/sysctl.conf中增加对应数据,可以打开两个终端,这样方便填写:

sudo vim /etc/sysctl.conf

把sysctl.conf中的以下内容用查得的值填上


fs.aio-max-nr = 65536

fs.file-max = 242293

kernel.shmall = 18446744073692774399

kernel.shmmax = 18446744073692774399

kernel.shmmni = 4096

kernel.sem = 32000 1024000000 500 32000

net.ipv4.ip_local_port_range = 32768 60999

net.core.rmem_default = 212992

net.core.rmem_max = 212992

net.core.wmem_default = 212992

net.core.wmem_max = 212992

运行一下命令更新内核参数:

sudo sysctl -p 

6.添加对当前用户的内核限制在 /etc/security/limits.conf 文件中增加以下数据(XXX为你当前用户名)

XXX soft nproc 2047 XXX hard nproc 16384 XXX soft nofile 1024 XXX hard nofile 65536 XXX soft stack 10240

7.检查/etc/pam.d/login,增加以下行(有了就不用增加了): 
session required pam_limits.so 
检查/etc/pam.d/su,没有以下行就自己加上: 
session required pam_limits.so

8.oracle默认不支持ubuntu需要欺骗一下oracle安装程序,执行以下命令:

sudo mkdir /usr/lib64 sudo ln -s /etc /etc/rc.d sudo ln -s /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib64/ sudo ln -s /usr/bin/awk /bin/awk sudo ln -s /usr/bin/basename /bin/basename sudo ln -s /usr/bin/rpm /bin/rpm sudo ln -s /usr/lib/x86_64-linux-gnu/libc_nonshared.a /usr/lib64/ sudo ln -s /usr/lib/x86_64-linux-gnu/libpthread_nonshared.a /usr/lib64/ sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /lib64/ sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib64/ echo ‘Ubuntu Linux release 14.04′ > /etc/ubuntu-release 

最后一个命令执行不了的话,可以用以下命令执行:

sudo vim /etc/ubuntu-release

在ubuntu-release文本中增加Ubuntu Linux release 14.04,然后保存退出即可。

9.配置oracle的环境变量

sudo gedit ~/.profile 
打开.profile文件,为文件中添加以下行: 

xxx换成你目前的用户名

创建文件夹

mkdir /home/myubuntu/oracle

mkdir /home/myubuntu/oracle/oracle11g


export ORACLE_BASE=/home/myubuntu/oracle/oracle11g export ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/dbhome_1 export ORACLE_SID=orcl export ORACLE_UNQNAME=orcl export NLS_LANG=.AL32UTF8 export PATH=${PATH}:${ORACLE_HOME}/bin/:$ORACLE_HOME/lib64;


10.启动oracle安装程式开始安装

首先检查一下oracle的环境变量是否是你设定的:

echo $ORACLE_BASE echo $ORACLE_HOME echo $PATH

如果不是,重新开启一个终端,应该就可以了。或者执行以下命令:

source ~/.profile

这个命令的作用是使你设的环境变量生效。

cd /home/myubuntu/oracle/database #oracle11g解压路径

进入database文件夹,为runInstaller文件赋予可执行权限

chmod 777 runInstaller

Oracle安装界面乱码解决方法

执行:

export NLS_LANG=AMERICAN_AMERICA.UTF8 export LC_ALL=C

以上都完成后,执行 ./runInstaller 运行安装程序

第一步,去掉 I wish to .......

第二,默认

第三,选 server class

第四步,默认

第五步,Advanced install

第六步,默认

第七步,默认

第八步,将Oracle Base 选择为要安装的位置 /home/myubuntu/oracle/oracle11g

第九步,默认

第十步,默认

第十一步,全部改为orcl

第十二步,选择上面的character sets 进入界面后 选择Use Unicode(AL32UTF8),然后选择上面Sample Schemas,进入进面后将选项打钩

第十三步,默认

第十四步,默认

第十五步,默认

第十六步,选择Use the same password for all accounts ,自己设置一个密码(一般用不到)

第十七步,默认

第十八步,选择右上角 Ignore All 忽略,因为我们之前都已经装过了,识别不出来而已

第十九步,点击Finish开始安装

安装到68%时的错

ins_ctx.mk的错误提示,直接contiue跳过去 
后面还回报错: 
make file ‘/……emagent.mk’出错 
解决方法: 
另开一个终端,键入命令行:

sudo sed -i 's/^\(\s*\$(MK_EMAGENT_NMECTL)\)\s*$/\1 -lnnz11/g' $ORACLE_HOME/sysman/lib/ins_emagent.mk 

点击安装界面的retry,就可以继续了 
类似的后面还会提示四次,以下面的命令行如法炮制 ,把以下命令执行完。

sudo sed -i 's/^\(\$LD \$LD_RUNTIME\) \(\$LD_OPT\)/\1 -Wl,--no-as-needed \2/g' $ORACLE_HOME/bin/genorasdksh sudo sed -i 's/^\(\s*\)\(\$(OCRLIBS_DEFAULT)\)/\1 -Wl,--no-as-needed \2/g' $ORACLE_HOME/srvm/lib/ins_srvm.mk sudo sed -i 's/^\(TNSLSNR_LINKLINE.*\$(TNSLSNR_OFILES)\) \(\$(LINKTTLIBS)\)/\1 -Wl,--no-as-needed \2/g' $ORACLE_HOME/network/lib/env_network.mk sudo sed -i 's/^\(ORACLE_LINKLINE.*\$(ORACLE_LINKER)\) \(\$(PL_FLAGS)\)/\1 -Wl,--no-as-needed \2/g' $ORACLE_HOME/rdbms/lib/env_rdbms.mk 

最后安装完成会提示有两个sh文件需要运行:

还是另开一个终端:

sudo /home/myubuntu/oracle/oraInventory/orainstRoot.sh sudo /home/myubuntu/oracle/oracle11g/product/11.2.0/dbhome_1/root.sh 

安装完成!

三:测试

1,运行sqlplus


运行sqlplus前测试一下oracle的环境变量:

echo $ORACLE_BASE echo $ORACLE_HOME echo $PATH 

如果显示的是你配置的值,可以继续以下步骤。

2.查看数据库的监听状态 


利用一下命令查看是否正在监听,正常情况会显示很多监听信息 
这里如果没有输出,说明无监听,需要自己配置 :
lsnrctl status 

没有监听的解决办法: 
运行 netca 可以创建监听,调出图形界面设置监听 
如果没有创建库此时可以dbca 创建数据库. 
顺便运行以下代码修复 dbconsole 
emca -repos drop 
emca -repos create 
emca -config dbcontrol db 
emca start dbconsole 
到此数据库应该就可以跑起来了

如果没有监听,执行一下命令启动监听:

lsnrctl start


3.启动oracle数据库 


输入以下命令,启动sqlplus:
sqlpus / as sysdba

oracle的启动和停止命令是:

SQL>startup SQL>shutdown

startup时会显示你创建的orcl实例已经正常加载。


4..sqldeveloper连不上oracle的问题: 


如果需要远程连接oracle数据库,需要修改一下oracle的监听地址: 
修改/home/myubuntu/oracle/oracle11g/product/11.2.0/dbhome_1/network/admin/listener.ora文件内容为: 

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 自己的ip地址)(PORT = 1521))
    )
  )
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl)
      (ORACLE_HOME = /home/myubuntu/oracle/oracle11g/product/11.2.0/dbhome_1)
      (SID_NAME = orcl)
    )
  )

ADR_BASE_LISTENER = /home/myubuntu/oracle/oracle11g


/home/myubuntu/oracle/oracle11g/product/11.2.0/dbhome_1/network/admin/tnsnames.ora的内容如下: 


LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 自己的ip地址)(PORT = 1521))

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 自己的ip地址)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

修改完以上文件后,关闭监听并重启监听,数据库不用停止和启动:

lsnrctl stop lsnrctl start

这样你就可以远程连接你的oracle了。

完结。。。。。。。