今天接到通知,下周去一个新客户那边部署新环境,问题是时间还很紧,让下周一就去,时间紧还不是大问题,问题是产品的中间件Weblogic跟数据库Oracle我都好久没玩了,没得办法,只能提前演练一下了,为了下次找起来更加方便,就把过程整理到本博客上面来,也可以方便其他童鞋的查询吧。
谁要是跟我纠结时间这么紧,哪来的时间写博客的,我跟谁急哦!方便自己,也方便大家嘛!
华丽分割线
一.查看系统配置信息
[root@web-db ~]# hostname --fqdn //查看主机名 web-db [root@web-db ~]# ifconfig eth0 //查看本机IP地址 eth0 Link encap:Ethernet HWaddr 06:F1:96:00:00:C0 inet addr:192.168.153.153 Bcast:192.168.153.255 Mask:255.255.255.0 inet6 addr: fe80::4f1:96ff:fe00:c0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1706513 errors:0 dropped:0 overruns:0 frame:0 TX packets:877952 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2565533900 (2.3 GiB) TX bytes:59768622 (56.9 MiB) [root@web-db ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.153.153 web-db [root@web-db ~]# cat /etc/redhat-release //查看RHEL发行版本 Red Hat Enterprise Linux Server release 6.3 (Santiago) [root@web-db ~]# uname -m //查看本机CPU架构 x86_64 [root@web-db ~]# free -m //查看内存跟交换分区信息 total used free shared buffers cached Mem: 7870 2876 4993 0 12 2609 -/+ buffers/cache: 254 7616 Swap: 5760 0 5760 [root@web-db ~]# df -H //查看分区挂载信息 Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 9.1G 3.6G 5.1G 41% / tmpfs 4.2G 0 4.2G 0% /dev/shm /dev/vda1 508M 33M 449M 7% /boot /dev/vdb5 30G 181M 28G 1% /u01
当然,有朋友会问:你用的是物理机还是虚拟机?
我这么有钱,想想就知道我用的是什么了,是不是?
[root@web-db ~]# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 1 Core(s) per socket: 1 CPU socket(s): 8 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 13 Stepping: 3 CPU MHz: 2393.998 BogoMIPS: 4787.99 Hypervisor vendor: KVM Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 4096K NUMA node0 CPU(s): 0-7
咦? 怎么不是物理机,我说我什么时候这么有钱的呢?用的还是KVM虚拟机。
呵呵,开个玩笑,我们继续技术交流,禁止鄙视使用虚拟机的�潘浚�
二.配置系统YUM源,安装依赖包
[root@web-db ~]# mount /dev/sr0 /media/ mount: block device /dev/sr0 is write-protected, mounting read-only [root@web-db ~]# cat /etc/yum.repos.d/rhel-source.repo [rhel6u3-core] name=rhel6u3-core baseurl=file:///media enabled=1 gpgcheck=0
[root@web-db ~]# yum clean all Loaded plugins: product-id, subscription-manager Updating certificate-based repositories. Unable to read consumer identity Cleaning repos: rhel6u3-core Cleaning up Everything
[root@web-db ~]# cat package.list //需要安装的依赖包信息列表 binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*.i686 elfutils-libelf-devel gcc gcc-c++ glibc*.i686 glibc glibc-devel glibc-devel*.i686 ksh libgcc*.i686 libgcc libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.i686 libaio libaio*.i686 libaio-devel libaio-devel*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686
[root@web-db ~]# yum install `cat package.list` -y //安装依赖包
三.修改内核参数
[root@web-db ~]# cp /etc/sysctl.conf \ /etc/sysctl.conf_20131016.bak//备份文件 [root@web-db ~]# cat /etc/sysctl.conf //在文件爱呢最后添加如下 ##==========Setting For Oracle 11G R2============## kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 fs.file-max = 6815744 fs.aio-max-nr = 1048576 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 4194304 net.core.wmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_max = 1048576
[root@web-db ~]# sysctl -p //让修改立即生效 net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key error: "net.bridge.bridge-nf-call-iptables" is an unknown key error: "net.bridge.bridge-nf-call-arptables" is an unknown key kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 fs.file-max = 6815744 fs.aio-max-nr = 1048576 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 4194304 net.core.wmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_max = 1048576
四. 创建Oracle用户以及相关权限修改
1. 创建oracle 用户组跟用户
[root@web-db ~]# groupadd oinstall [root@web-db ~]# groupadd dba [root@web-db ~]# useradd -g oinstall -G dba -m oracle [root@web-db ~]# echo oracle |passwd --stdin oracle //创建密码 Changing password for user oracle. passwd: all authentication tokens updated successfully.
2. 修改限制
[root@web-db ~]# cp /etc/security/limits.conf /etc/security/limits.conf.20131016.bak ##=============Setting For Oracle 11G R2=============## oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 oracle soft stack 10240 [root@web-db ~]# cat /etc/pam.d/login ##======Setting For Oracle 11G R2========## session required pam_limits.so [root@web-db ~]# cat /etc/profile ##===Setting For Oracle 11G R2=====## if [ $USER = "oracle" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi fi [root@web-db ~]# source /etc/profile
3. 创建oracle安装目录以及配置相关变量
创建安装oracle目录 [root@web-db ~]# mkdir -p /u01/app/oracle [root@web-db ~]# chown oracle:oinstall -R /u01/app/ [root@web-db ~]# chmod -R 755 /u01/app/ [root@web-db ~]# su - oracle [oracle@web-db ~]$ cp ~/.bash_profile ~/.bash_profile.20131016.bak [oracle@web-db ~]$ cat ~/.bash_profile ##====Setting For Oracle11g R2=====## ORACLE_BASE=/u01/app/oracle ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 ORACLE_SID=clouddb export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH=$ORACLE_HOME/bin:$PATH export PATH [oracle@web-db ~]$ source ~/.bash_profile
五.开始安装Oracle软件
[oracle@web-db oracle_install]$ ll total 2295600 -rwxr--r--. 1 oracle oinstall 1239269270 Oct 16 17:03 linux.x64_11gR2_database_1of2.zip -rwxr--r--. 1 oracle oinstall 1111416131 Oct 16 17:05 linux.x64_11gR2_database_2of2.zip [oracle@web-db oracle_install]$ unzip linux.x64_11gR2_database_1of2.zip [oracle@web-db oracle_install]$ unzip linux.x64_11gR2_database_2of2.zip [oracle@web-db oracle_install]$ cd database/ [oracle@web-db database]$ ls doc install response rpm runInstaller sshsetup stage welcome.html [oracle@web-db database]$ exit //回到root用户 [root@web-db ~]# xhost + //如果没有安装图形化,可以[root@web-db ~]# yum groupinstall "Desktop" "X Window System" -y
使用oracle用户开始安装
[oracle@web-db database]$ export DISPLAY=192.168.153.153:0.0 [oracle@web-db database]$ ./runInstaller Starting Oracle Universal Installer... Checking Temp space: must be greater than 120 MB. Actual 1728 MB Passed Checking swap space: must be greater than 150 MB. Actual 5760 MB Passed Checking monitor: must be configured to display at least 256 colors. Actual 16777216 Passed Preparing to launch Oracle Universal Installer from /tmp/OraInstall2013-10-17_11-14-21AM. Please wait ...
[root@web-db ~]# id uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [root@web-db ~]# /u01/app/oraInventory/orainstRoot.sh Changing permissions of /u01/app/oraInventory. Adding read,write permissions for group. Removing read,write,execute permissions for world. Changing groupname of /u01/app/oraInventory to oinstall. The execution of the script is complete. [root@web-db ~]# /u01/app/oracle/product/11.2.0/db_1/root.sh Running Oracle 11g root.sh script... The following environment variables are set as: ORACLE_OWNER= oracle ORACLE_HOME= /u01/app/oracle/product/11.2.0/db_1 Enter the full pathname of the local bin directory: [/usr/local/bin]: Copying dbhome to /usr/local/bin ... Copying oraenv to /usr/local/bin ... Copying coraenv to /usr/local/bin ... Creating /etc/oratab file... Entries will be added to the /etc/oratab file as needed by Database Configuration Assistant when a database is created Finished running generic part of root.sh script. Now product-specific root actions will be performed. Finished product-specific root actions.
六. 配置监听器
[oracle@web-db ~]$ netca Oracle Net Services Configuration: Configuring Listener:LISTENER Listener configuration complete. Oracle Net Listener Startup: Running Listener Control: /u01/app/oracle/product/11.2.0/db_1/bin/lsnrctl start LISTENER Listener Control complete. Listener started successfully. Oracle Net Services configuration successful. The exit code is 0
[oracle@web-db ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora //查看生成的文件 # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = web-db)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle
[oracle@web-db ~]$ lsnrctl status //查看监听器状态 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 17-OCT-2013 13:54:40 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=web-db)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 17-OCT-2013 13:48:10 Uptime 0 days 0 hr. 6 min. 31 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/web-db/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=web-db)(PORT=1521))) The listener supports no services The command completed successfully
七. 创建数据库实例clouddb
[oracle@web-db ~]$ dbca
注意:这边的密码千万别包含@字,否则在创建数据库实例的时候,
报错:ORA-12154 tns could not resolve the connect identifier specified
八. 创建Oracle启动脚本
1.修改oratab文件
[root@web-db ~]# cp /etc/oratab /etc/oratab_20131017.bak //N 改为 Y [root@web-db ~]# tail -n 1 /etc/oratab \ clouddb:/u01/app/oracle/product/11.2.0/db_1:Y
2. 修改dbstart跟dbshut脚本中ORACLE_HOME_LISTENER的值
【ORACLE_HOME_LISTNER=$1 修改为 ORACLE_HOME_LISTNER=$ORACLE_HOME
】
[root@web-db ~]# cp /u01/app/oracle/product/11.2.0/db_1/bin/dbstart /u01/app/oracle/product/11.2.0/db_1/bin/dbstart_20131017.bak [root@web-db ~]# cp /u01/app/oracle/product/11.2.0/db_1/bin/dbshut /u01/app/oracle/product/11.2.0/db_1/bin/dbshut_20131017.bak [root@web-db ~]# vi /u01/app/oracle/product/11.2.0/db_1/bin/dbstart //修改第80行 [root@web-db ~]# vi /u01/app/oracle/product/11.2.0/db_1/bin/dbshut //修改第50行
3.创建启动脚本文件
[root@web-db ~]# cat /etc/init.d/oracle #!/bin/bash # chkconfig: 2345 98 10 # description: Oracle auto start-stop script. # /etc/rc.d/init.d/oracle . /etc/rc.d/init.d/functions export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 export ORACLE_SID=clouddb export PATH=$PATH:$ORACLE_HOME/bin case "$1" in start) echo "==start oracle==" su oracle -c "$ORACLE_HOME/bin/dbstart" su oracle -c "$ORACLE_HOME/bin/emctl start dbconsole" su oracle -c "$ORACLE_HOME/bin/lsnrctl start" touch /var/lock/subsys/oracle echo "`date` ==oracle startup successful== ">> /var/log/oracle11g.log ;; stop) echo "==shutdown oracle==" su oracle -c "$ORACLE_HOME/bin/dbshut" su oracle -c "$ORACLE_HOME/bin/emctl stop dbconsole " su oracle -c "$ORACLE_HOME/bin/lsnrctl stop" rm -f /var/lock/subsys/oracle echo "`date` ==oracle shutdown successful== ">> /var/log/oracle11g.log ;; *) echo "Usage: "$0" start |stop " exit ;; esac exit 0
注意:上述脚本第2行chkconfig: 2345 98 10 中的98该值需要注意,我原来按照很多教程都写的99,发现系统重启之后,Oracle根本不会随机启动,查看发现有两个99的服务
[root@web-db ~]# ls /etc/rc2.d/S99* /etc/rc2.d/S99local /etc/rc2.d/S99oracle
所以改成不存在的数值:98,测试通过,完美运行。
4. 赋予可执行权限,加入开机启动
[root@web-db ~]# chmod a+x /etc/init.d/oracle [root@web-db ~]# chkconfig --add oracle [root@web-db ~]# chkconfig oracle on
5. 启动服务,查看是否成功
[root@web-db ~]# ps -ef |grep ora //没有ora真正进程 oracle 5598 1 0 13:23 pts/0 00:00:00 dbus-launch --autolaunch 29eae0cf81f05ed989bd283900000022 --binary-syntax --close-stderr oracle 5599 1 0 13:23 ? 00:00:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session root 5803 1716 0 13:54 pts/0 00:00:00 su - oracle oracle 5804 5803 0 13:54 pts/0 00:00:00 -bash root 20479 20462 0 15:49 pts/1 00:00:00 grep oracle
启动服务
[root@web-db ~]# service oracle start //启动oracle服务 Processing Database instance "clouddb": log file /u01/app/oracle/product/11.2.0/db_1/startup.log Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0 Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved. https://web-db:1158/em/console/aboutApplication Starting Oracle Enterprise Manager 11g Database Control .......... started. ------------------------------------------------------------------ Logs are generated in directory /u01/app/oracle/product/11.2.0/db_1/web-db_clouddb/sysman/log
再次查看ora进程
[root@web-db ~]# ps -ef |grep ora oracle 5598 1 0 13:23 pts/0 00:00:00 dbus-launch --autolaunch 29eae0cf81f05ed989bd283900000022 --binary-syntax --close-stderr oracle 5599 1 0 13:23 ? 00:00:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session root 5803 1716 0 13:54 pts/0 00:00:00 su - oracle oracle 5804 5803 0 13:54 pts/0 00:00:00 -bash oracle 20495 1 0 15:49 ? 00:00:00 /u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr LISTENER -inherit oracle 20632 1 0 15:49 ? 00:00:00 ora_pmon_clouddb oracle 20634 1 0 15:49 ? 00:00:00 ora_vktm_clouddb oracle 20638 1 0 15:49 ? 00:00:00 ora_gen0_clouddb oracle 20640 1 0 15:49 ? 00:00:00 ora_diag_clouddb oracle 20642 1 0 15:49 ? 00:00:00 ora_dbrm_clouddb oracle 20644 1 0 15:49 ? 00:00:00 ora_psp0_clouddb oracle 20646 1 0 15:49 ? 00:00:00 ora_dia0_clouddb oracle 20648 1 1 15:49 ? 00:00:01 ora_mman_clouddb oracle 20650 1 0 15:49 ? 00:00:00 ora_dbw0_clouddb oracle 20652 1 0 15:49 ? 00:00:00 ora_lgwr_clouddb oracle 20654 1 0 15:49 ? 00:00:00 ora_ckpt_clouddb oracle 20656 1 0 15:49 ? 00:00:00 ora_smon_clouddb oracle 20658 1 0 15:49 ? 00:00:00 ora_reco_clouddb oracle 20660 1 0 15:49 ? 00:00:00 ora_mmon_clouddb oracle 20662 1 0 15:49 ? 00:00:00 ora_mmnl_clouddb oracle 20664 1 0 15:49 ? 00:00:00 ora_d000_clouddb oracle 20666 1 0 15:49 ? 00:00:00 ora_s000_clouddb oracle 20748 1 0 15:49 ? 00:00:00 ora_qmnc_clouddb oracle 21053 1 0 15:49 ? 00:00:00 ora_cjq0_clouddb oracle 21265 1 0 15:49 ? 00:00:00 /u01/app/oracle/product/11.2.0/db_1/perl/bin/perl /u01/app/oracle/product/11.2.0/db_1/bin/emwd.pl dbconsole /u01/app/oracle/product/11.2.0/db_1/web-db_clouddb/sysman/log/emdb.nohup oracle 21289 21265 45 15:49 ? 00:00:26 /u01/app/oracle/product/11.2.0/db_1/jdk/bin/java -server -Xmx384M -XX:MaxPermSize=400M -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40 -DORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 -Doracle.home=/u01/app/oracle/product/11.2.0/db_1/oc4j -Doracle.oc4j.localhome=/u01/app/oracle/product/11.2.0/db_1/web-db_clouddb/sysman -DEMSTATE=/u01/app/oracle/product/11.2.0/db_1/web-db_clouddb -Doracle.j2ee.dont.use.memory.archive=true -Djava.protocol.handler.pkgs=HTTPClient -Doracle.security.jazn.config=/u01/app/oracle/product/11.2.0/db_1/oc4j/j2ee/OC4J_DBConsole_web-db_clouddb/config/jazn.xml -Djava.security.policy=/u01/app/oracle/product/11.2.0/db_1/oc4j/j2ee/OC4J_DBConsole_web-db_clouddb/config/java2.policy -Djavax.net.ssl.KeyStore=/u01/app/oracle/product/11.2.0/db_1/sysman/config/OCMTrustedCerts.txt-Djava.security.properties=/u01/app/oracle/product/11.2.0/db_1/oc4j/j2ee/home/config/jazn.security.props -DEMDROOT=/u01/app/oracle/product/11.2.0/db_1/web-db_clouddb -Dsysman.md5password=true -Drepapi.oracle.home=/u01/app/oracle/product/11.2.0/db_1 -Ddisable.checkForUpdate=true -Doracle.sysman.ccr.ocmSDK.websvc.keystore=/u01/app/oracle/product/11.2.0/db_1/jlib/emocmclnt.ks -Dice.pilots.html4.ignoreNonGenericFonts=true -Djava.awt.headless=true -jar /u01/app/oracle/product/11.2.0/db_1/oc4j/j2ee/home/oc4j.jar -config /u01/app/oracle/product/11.2.0/db_1/oc4j/j2ee/OC4J_DBConsole_web-db_clouddb/config/server.xml oracle 21302 21265 1 15:49 ? 00:00:01 /u01/app/oracle/product/11.2.0/db_1/bin/emagent oracle 21329 1 6 15:49 ? 00:00:03 oracleclouddb (LOCAL=NO) oracle 21364 1 1 15:49 ? 00:00:00 oracleclouddb (LOCAL=NO) oracle 21530 1 0 15:49 ? 00:00:00 ora_q000_clouddb oracle 21532 1 0 15:49 ? 00:00:00 ora_q001_clouddb oracle 21777 1 0 15:49 ? 00:00:00 oracleclouddb (LOCAL=NO) oracle 21782 1 1 15:49 ? 00:00:00 oracleclouddb (LOCAL=NO) oracle 21830 1 0 15:50 ? 00:00:00 oracleclouddb (LOCAL=NO) oracle 21837 1 0 15:50 ? 00:00:00 oracleclouddb (LOCAL=NO) oracle 21840 1 7 15:50 ? 00:00:02 oracleclouddb (LOCAL=NO) oracle 21861 1 8 15:50 ? 00:00:02 oracleclouddb (LOCAL=NO)
6登陆OEM,查看实例监控信息
-----------------------------------------------
用户名:sys
密码:创建数据库实例的时候设置的密码,那边我提醒密码不要包含@字符的,你懂了吧。
连接身份:SYSDBA
-----------------------------------------------