Sie sind auf Seite 1von 18

Naresh i Technologies, Hyderabad, 04023746666

C, C++ and Java Programs Comila!ion on "N#$ %nvironmen!


&' (ri!e a Hello (orld C Program
Create the heoword.c program usng a Vm edtor as shown beow.
$ vm heoword.c
/* Heo Word C Program */
#ncude<stdo.h>
man()
{
prntf("Heo Word!");
}
2' )a*e s+re C Comiler ,gcc- is ins!alled on yo+r sys!em
Make sure gcc s nstaed on your system as shown beow.
$ wheres cc
cc: /usr/bn/cc /usr/share/man/man1/cc.1.gz
$ whch cc
/usr/bn/cc
$ dpkg - | grep gcc
gcc 4:4.3.3-1ubuntu1 The GNU C comper
gcc-4.3 4.3.3-5ubuntu4 The GNU C comper
gcc-4.3-base 4.3.3-5ubuntu4 The GNU Comper Coecton (base
package)
gcc-4.3-doc 4.3.3-5ubuntu4 Documentaton for the GNU compers
(gcc, go
gcc-4.3-ocaes 4.3.3-5ubuntu4 The GNU C comper (natve anguage
support
gcc-4.3-mutb 4.3.3-5ubuntu4 The GNU C comper (mutb fes)
b64gcc1 1:4.3.3-5ubuntu4 GCC support brary (64bt)
bgcc1 1:4.3.3-5ubuntu4 GCC support brary
3' Comile !he hello.orld'c Program
Compe the heoword.c usng cc command as shown beow. Ths w create the
a.out fe.
$ cc heoword.c
$ s -
-rw-r--r-- 1 ramesh ramesh 71 2009-08-28 14:06 heoword.c
-rwxr-xr-x 1 ramesh ramesh 9152 2009-08-28 14:07 a.out4. Execute the C Program
(a.out)
You can ether execute the a.out to see the output (or) rename t to some other
meanngfu name and execute t as shown beow.
$ ./a.out
Heo Word!
$ mv a.out heoword
$ ./heoword
Heo Word!
C++ Programs Comila!ion
Oueston: I woud ke to understand the bascs of how to wrte, compe and execute
a C++ program on Lnux OS. Can you expan t wth a smpe exampe?
Answer: Last week we revewed how to wrte C program on Unx OS. In ths artce,
et us revew very qucky how to wrte a basc Heo Word C++ program and how to
compe *.cc program on Lnux or Unx OS.
&' (ri!e a Hello (orld C++ Program
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
Create the heoword.cc program usng a Vm edtor as shown beow.
$ vm heoword.cc
// my frst program n C++
#ncude <ostream>
usng namespace std;
nt man ()
{
cout << "Heo Word!";
return 0;
}
2. Make sure C++ Compe (g++) s nstaed on your system
Make sure g++ s nstaed on your system as shown beow.
$ wheres c++
c++: /usr/bn/c++ /usr/ncude/c++ /usr/share/man/man1/c++.1.gz
$ whch c++
/usr/bn/c+
$ dpkg - | grep g++
g++ 4:4.3.3-1ubuntu1 The GNU C++ comper
g++-4.3 4.3.3-5ubuntu4 The GNU C++ comper
3' Comile !he hello.orld'cc Program
Compe the heoword.cc usng c++ command as shown beow. Ths w create the
a.out fe.
$ c++ heoword.cc
$ s -
-rw-r--r-- 1 ramesh ramesh 71 2009-09-03 11:03 heoword.cc
-rwxr-xr-x 1 ramesh ramesh 9152 2009-09-03 11:06 a.out4. Execute the C++
Program (a.out)
You can ether execute the a.out to see the output (or) rename t to some other
meanngfu name and execute t as shown beow.
$ ./a.out
Heo Word!
$ mv a.out heoword
$ ./heoword
Heo Word!
Java Programming on "N#$
The Lnux Lab
o The Lnux ab (do you know any rch person who wants a ab named
after them?) s a coecton of Lnux (UNIX) workstatons n Ungar 426,
pus a fe server workstaton (n the next room). It beongs to the
Department of Computer Scence. Ths ab provdes an up-to-date
computng envronment to teach computer scence courses.
Settng up your account
Command ne Computng (the rght thng for Computer Scentsts)
o Termna sessons
Once you have ogged nto a ab machne, avod the temptaton
to start cckng at thngs. Reay, that's for wmps. Actuay, t's
OK for startng appcatons, but t's not fast enough for rea
computng.
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
Start a termna sesson ... the tte wndow thng. When you
start a termna sesson you' be "n" your home drectory.
Start another termna sesson f you want ... you can have ots
of them runnng at the same tme.
Now you need to earn some UNIX commands ... the best way s
from your TA durng your ab sesson. Here're a few:
yppasswd - aows you to change your password
date - dspays the date and tme
s - sts the fes n your current drectory
s -a - sts a the fes, ncudng hdden ones (they start
wth a .)
cat - dspays a fe's contents
ess - dspays a fe's contents one page at a tme
cp - copes a fe
mv - renames or moves a fe
rm - removes fes
D (that's contro-D) ogs you out of the termna sesson
o Drectores
You are probaby famar wth the tree-of-drectores-and-fes
most operatng systems mpose on the dsk space. Gotta ove t.
In revew ...
There's a pace on the harddsk of a machne caed ee
where you can store a your fes. That's your home
directory.
Whenever you ogn to a ab machne, t ooks ke your
home drectory s on that machne. Neat, done by NFS.
You can create subdrectores to organze your fes.
Wndoze users ca subdrectores "foders".
Termna sesson commands for manpuatng drectores
mkdr - make a subdrectory
cd - moves you to another drectory (N.B., cd .. moves
you to the parent drectory)
rmdr - remove a subdrectory
Use the tree to organze your work. For ths course you must
have the foowng drectores off your home drectory (case
senstve):
MyPrograms (for your persona programs)
LabTasks (for your ab tasks)
Pro|ects (for the two pro|ects)
|ava Program Deveopment
|ava program fes must end wth .java. Create your .java fe usng
an edtor, e.g.,
prompt> v HeoWord.|ava
Compe your .java fe usng javac, e.g.,
prompt> |avac HeoWord.|ava
If there are no mstakes n HeoWord.|ava that w create
HeoWord.cass, whch contans the byte-code.
Run your byte-code .class fe usng java, but omt the .class (werd,
and t shoudn't be, but t s), e.g.,
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
prompt> |ava HeoWord
The output w be on your screen.
Edtng (|ava programs)
o nedt (for non-gurus)
Wndowng fu-featured edtor (.e., w not, n genera, run over
network connectons)
Not avaabe everywhere
The Help menu w get you gong
o gvm (for asprng gurus)
A graphca verson of vim, whch may be a good way to get nto
vim.
o v/vm (for gurus)
Pan text edtor (.e., w run over network connectons)
Avaabe on |ust about any UNIX system
About 35% of a serous UNIX hackers st prefer vi/vim (or a
dervatve)
vm s |ust vi improved. In the ab runnng vi w run vim.
vmtutor w get you gong
o emacs (for gurus wth fat noses)
About 35% of a serous UNIX hackers use Emacs. Aso
wdespread use on other operatng systems
emacs has zons of extensons
Dong ^H t nsde emacs w get you gong
|avac error messages
o If there are errors n a program submtted to |avac then error
messages w be spat out
o The error messages dentfy the ne at whch the error was noticed,
and provde cues about the nature of the error.
The error may be on an earer ne. The comper works hard to
understand your ravngs, and may have to go on past the actua
error ne to estabsh that there reay s an error.
The "cue" s ony that. Better you know |ava we than rey on
those cues to te you what's wrong.
o Fxng errors
Use two termna sessons, one for compng and one for edtng
Do a compaton, and f there are errors ...
Edt to fx at east the frst error, and others f you can
Compe agan
o Exampe: BuggyHeoWord.|ava
o Compaton s done n mutpe phases, so |avac fnds a the obvous
errors frst, and when you've got them a fxed |avac w ony then ook
for subte errors.
o Generay, fxng one error does not mean ess errors the next tme you
compe.
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
2in+34"ni3 #ns!alla!ion #ns!r+c!ions o5 Java
If you have an account on a shared system at a unversty or an Internet Servce
Provder, there's a good chance |ava s aready nstaed. Ask your oca support staff
how to access t. Otherwse foow these nstructons.
The Unx reease s a gzpped tar fe. You w need about sxty megabytes of free
dsk space to uncompress and untar the |DK. Doube that woud be very hepfu. You
do ths wth these commands:
$ gunzp |dk1_2_2-nux-386.tar.gz
$ tar xvf |dk1_2_2-nux-386.tar
The exact fename may be a tte dfferent f you're retrevng the reease for a
dfferent patform such as Irx or f the verson s dfferent.
You can untar t n your home drectory, or, f you have root prveges, n some
convenent pace ke /usr/oca/|ava where a users can have access to the fes.
However root prveges are not necessary to nsta or run |ava.
Untarrng the fe creates a necessary drectores and sub-drectores. The exact
path s unmportant, but for smpcty's sake ths book assumes t's nstaed t n
/usr/oca/|ava. If a sysop aready nstaed t, ths s probaby where t ves. (Under
Soars t's aso possbe the sysop put t nto /opt.) If ths s the case the fes ve
n /usr/oca/|ava/|dk1.2.2. If you're unpackng a dfferent verson, then you may fnd
t nstaed n a sghty dfferent drectory such as /usr/oca/|ava/|dk1.3. Ths aows
mutpe versons of the |DK to coexst harmonousy on the same system. If you
unpacked t somewhere other than /usr/oca/|ava, |ust repace /usr/oca/|ava by the
fu path to the |ava drectory n what foows. If you nstaed t n your home
drectory, you can use -/|ava nstead of a fu path.
You now need to add /usr/oca/|ava/|dk1.2.2/bn drectory to your PATH
envronment varabe. You use one of the foowng commands dependng on your
she.
csh, tcsh:
$ set PATH=($PATH /usr/oca/|ava/|dk1.2.2/bn)
sh:
$ PATH=($PATH /usr/oca/|ava/bn); export $PATH
You shoud aso add these nes to the end of your .profe or .cshrc fes so you
won't have to repeat them every tme you ogn.
To verfy that your |ava envronment s correcty confgured, type "|avac nofe.|ava"
at a she prompt ke ths
$ |avac nofe.|ava
If your computer responds wth error: Can't read: nofe.|ava, you're ready to begn.
If, on the other hand, t responds, |avac: Command not found or somethng smar,
then you the |ava envronment s not propery nstaed or your PATH s ncorrect.
You' need to fx t before contnung.
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
"ni342in+3 #ns!r+c!ions6
Start the Appet Vewer by dong the foowng:
From the command ne, cd to one of the drectores n
/usr/oca/|ava/|dk1.2.2/demo, for exampe
$ cd /usr/oca/|ava/|dk1.2.2/demo/appets/TcTacToe
Run the appetvewer on the fe named exampe1.htm:
$ appetvewer exampe1.htm
Pay Tc-Tac-Toe! It s aegedy possbe to wn.
7o.nload or ins!all C, C++ comiler on 0ed Ha! %n!errise
2in+3 8
A.In order to compe and use c/c++ under Lnux you need foowng packages
=> autoconf : GNU's Autoconf s a too for confgurng source code and Makefes.
=> make/automake : A GNU too for controng the generaton of executabes and
other
non-source fes of a program from the program's source fes.
=> GNU GCC C comper (gcc) : The gcc package contans the GNU Comper
Coecton verson 4.1
=> GNU GCC C++ comper (gcc-c++): Ths package adds C++ support to the GNU
Comper Coecton.
You have tota 3 optons to downoad and nsta GCC comper under Redhat /
CentOS / Fedora Lnux:
|a| Use GUI too
|b| Insta rpm from CDROM/DVD
|c| Downoad and nsta comper from RHN over nternet
9!ion : &6 "se ;"# !ool
Use GUI too caed system-confg-packages to nsta gcc. |ust type the foowng
command and seect gcc and above packages:
$ system-confg-packages &
9!ion : 26 #ns!all rm 5rom C709)47<7
Mount your CD/DVD and nsta foowng packages usng rpm command.
# rpm -vh gcc*
9!ion : 36 7o.nload and ins!all comiler 5rom 0HN over in!erne!
You can downoad and nsta packages usng RHN and yum command:
# yum nsta gcc gcc-c++ autoconf automake
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
/hor! ;+ide !o ins!all 9racle
The foowng short Gude shows how to nsta and confgure Orace 9.2.0 on RedHat
Lnux 7.2 / 8.0 You may downoad our Scrpts to create a database, we suggest ths
way and NOT usng DBASSIST. Besdes these scrpts, you can downoad our NET
confguraton fes: LISTNER.ORA, TNSNAMES.ORA and SOLNET.ORA.
/ys!em 0e=+iremen!s
Create Unx Group dba
Create Unx User orace
Setup Envronment ($HOME/.bash_profe) as foows
Mount the Orace 9 CD-ROM (ony f you have the CD) ...
... or Unpackng downoaded nstaaton fes
Insta wth Instaer n nteractve mode
Crea!e !he 7a!abase
Create your own DB-Create Scrpt (optona)
Start Lstener
Automatcay Start / Stop the Database
Setup Kerne Parameters ( f necessary )
Insta Orace Optons (optona)
Downoad Scrpts for RedHat Lnux
For our nstaaton, we used the foowng ORACLE_HOME AND ORACLE_SID, pease
ad|ust these parameters for your own envronment.
ORACLE_HOME = /opt/orace/product/9.2.0
ORACLE_SID = VEN1
System Requrements
Orace 9 needs Kerne Verson 2.4 and gbc 2.2, whch s ncuded n RedHat Lnux
7.2.
Component
Check wth ...
... Output
Lunx Kerne Verson 2.4
rpm -q kerne
kerne-2.4.7-10
System Lbrares
rpm -q gbc
gbc-2.2.4-19.3
Proc*C/C++
rpm -q gcc
gcc-2.96-98
Create Unx Group dba
$ groupadd -g 400 dba
Create Unx User orace
$ useradd -u 400 -c "Orace Owner" -d /home/orace \
-g "dba" -m -s /bn/bash orace
Setup Envronment ($HOME/.bash_profe) as foows
# Setup ORACLE envronment
ORACLE_HOME=/opt/orace/product/9.2.0; export ORACLE_HOME
ORACLE_SID=VEN1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
ORACLE_OWNER=orace; export ORACLE_OWNER
TNS_ADMIN=/home/orace/confg/9.2.0; export TNS_ADMIN
NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1; export NLS_LANG
ORA_NLS33=$ORACLE_HOME/ocommon/ns/admn/data; export ORA_NLS33
CLASSPATH=$ORACLE_HOME/|dbc/b/casses111.zp
LD_LIBRARY_PATH=$ORACLE_HOME/b; export LD_LIBRARY_PATH
### see |SDK: export CLASSPATH
# Set up |AVA and |SDK envronment:
export |AVA_HOME=/usr/oca/|dk
export |SDK_HOME=/usr/oca/|sdk
CLASSPATH=$CLASSPATH:$|AVA_HOME/b:$|SDK_HOME/b/|sdk.|ar
export CLASSPATH
# Set up the search paths:
PATH=$POSTFIX/bn:$POSTFIX/sbn:$POSTFIX/sendma
PATH=$PATH:/usr/oca/|re/bn:/usr/oca/|dk/bn:/bn:/sbn:/usr/bn:/usr/sbn
PATH=$PATH:/usr/oca/bn:$ORACLE_HOME/bn:/usr/oca/|sdk/bn
PATH=$PATH:/usr/oca/sbn:/usr/bn/X11:/usr/X11R6/bn:/root/bn
PATH=$PATH:/usr/oca/samba/bn
export PATH
Mount the Orace 9 CD-ROM (ony f you have the CD) ...
Mount the CD-ROM as user root.
$ su root
$ mkdr /cdrom
$ mount -t so9660 /dev/cdrom /cdrom
$ ext
... or Unpackng downoaded nstaaton fes
If you downoaded database nstaaton fes from Orace ste (Lnux9_Dsk1.cpo.gz,
Lnux9_Dsk2.cpo.gz and Lnux9_Dsk3.cpo.gz) gunzp them somewhere and you'
get three .cpo fes. The best way to downoad the huge fes s to use the too
GetRght ( http://www.getrght.com/ )
$ cd <somewhere>
$ cpo -dmv < Lnux9_Dsk1.cpo
$ cpo -dmv < Lnux9_Dsk2.cpo
$ cpo -dmv < Lnux9_Dsk3.cpo
Now you shoud have three drectores (Dsk1, Dsk2 and Dsk3) contanng
nstaaton fes.
Insta wth Instaer n nteractve mode
Insta Orace 9 wth Orace Instaer
$ cd Dsk1
$ DISPLAY=<Any X-Wndow Host>:0.0
$ export DISPLAY
$ ./runInstaer
Answer the questons n the Instaer, we use the foowng nsta drectores
Inventory Locaton: /opt/orace/product/oraInventory
Orace Unversa Instaer n: /opt/orace/product/ou
|ava Runtme Envronment n: /opt/orace/product/|re/1.1.8
Edt the Database Startup Scrpt /etc/oratab
VEN1:/opt/orace/product/9.2.0:Y
Create the Database
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
Edt and save the CREATE DATABASE Fe ntVEN1.sq n $ORACLE_HOME/dbs, or
create a symboc-Lnk from $ORACLE_HOME/dbs to your Locaton.
$ cd $ORACLE_HOME/dbs
$ n -s /home/orace/confg/9.2.0/ntVEN1.ora ntVEN1.ora
$ s -
ntVEN1.ora -> /home/orace/confg/9.2.0/ntVEN1.ora
Frst start the Instance, |ust to test your ntVEN1.ora fe for correct syntax and
system resources.
$ cd /home/orace/confg/9.2.0/
$ sqpus /noog
SOL> connect / as sysdba
SOL> startup nomount
SOL> shutdown mmedate
Now you can create the database
SOL> @ntVEN1.sq
SOL> @shutdown mmedate
SOL> startup
Check the Logfe: ntVEN1.og
Create your own DB-Create Scrpt (optona)
You can generate your own DB-Create Scrpt usng the Too:
$ORACLE_HOME/bn/dbca
Start Lstener
$ snrct start LSNRVEN1
Automatcay Start / Stop the Database
To start the Database automatcay on Boot-Tme, create or use our Startup Scrpts
dbora and snrora (ncuded n ora_confg_nux_901.tar.gz), whch must be nstaed
n /etc/rc.d/nt.d. Create symboc Lnks from the Startup Drectores n /etc/rc.d
(e.g. /etc/rc.d/rc2.d).
rwxrwxrwx 1 root root S99dbora -> ../nt.d/dbora*
rwxrwxrwx 1 root root S99snrora -> ../nt.d/snrora*
Setup Kerne Parameters ( f necessary )
Orace9 uses UNIX resources such as shared memory, swap space, and
semaphores extensvey for nterprocess communcaton. If your kerne parameter
settngs are nsuffcent for Orace9, you w experence probems durng
nstaaton and nstance startup. The greater the amount of data you can store n
memory, the faster your database w operate. In addton, by mantanng data n
memory, the UNIX kerne reduces dsk I/O actvty.
Use the pcs command to obtan a st of the systems current shared memory and
semaphore segments, and ther dentfcaton number and owner. You can modfy
the kerne parameters by usng the /proc fe system.
To modfy kerne parameters usng the /proc fe system:
1. Log n as root user.
2. Change to the /proc/sys/kerne drectory.
3. Revew the current semaphore parameter vaues n the sem fe usng the cat or
more utty
# cat sem
The output w st, n order, the vaues for the SEMMSL, SEMMNS, SEMOPM, and
SEMMNI parameters. The foowng exampe shows how the output w appear.
250 32000 32 128
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
In the precedng exampe, 250 s the vaue of the SEMMSL parameter, 32000 s the
vaue of the SEMMNS parameter, 32 s the vaue of the SEMOPM parameter, and
128 s the vaue of the SEMMNI parameter.
4. Modfy the parameter vaues usng the foowng command:
# echo SEMMSL_vaue SEMMNS_vaue SEMOPM_vaue SEMMNI_vaue > sem
In the precedng command, a parameters must be entered n order.
5. Revew the current shared memory parameters usng the cat or more utty.
# cat shared_memory_parameter
In the precedng exampe, the shared_memory_parameter s ether the SHMMAX or
SHMMNI parameter. The parameter name must be entered n owercase etters.
6. Modfy the shared memory parameter usng the echo utty. For exampe, to
modfy the SHMMAX parameter, enter the foowng:
# echo 2147483648 > shmmax
7. Wrte a scrpt to ntaze these vaues durng system startup and ncude the
scrpt n your system nt fes. Refer to the foowng tabe to determne f your
system shared memory and semaphore kerne parameters are set hgh enough for
Orace9. The parameters n the foowng tabe are the mnmum vaues requred to
run Orace9 wth a snge database nstance. You can put the ntazaton n the fe
/etc/rc.d/rc.oca
# Setup Kerne Parameters for Orace 9
echo 250 32000 100 128 > /proc/sys/kerne/sem
echo 2147483648 > /proc/sys/kerne/shmmax
echo 4096 > /proc/sys/kerne/shmmn
Insta Orace Optons (optona)
You may want to nsta the foowng Optons:
Orace |VM
Orcae XML
Orace Spata
Orace Utra Search
Orace OLAP
Orace Data Mnng
Exampe Schemas
Run the foowng scrpt nsta_optons.sh to enabe ths optons n the database.
Before runnng ths scrpts ad|ust the ntSID.ora paramaters as foows for the bud
process. After ths, you can reset the paramters to smaer vaues.
parae_automatc_tunng = fase
shared_poo_sze = 200000000
|ava_poo_sze = 100000000
$ ./nsta_optons.sh
Downoad Scrpts for RedHat Lnux
These Scrpts can be used as Tempates. Pease note, that some Parameters ke
ORACLE_HOME, ORACLE_SID and PATH must be ad|usted on your own Envronment.
Besdes ths, you shoud check the ntSID.ora Parameters for your Database (Sze,
Archveog, ...)
Cck here for the downoad (ora_confg_nux_920.tar.gz)
Please visi! 6 h!!644...'oracle'com4ls4db>24db>2''''emar*?docinde3
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
#ns!alling 9racle>i on 0edHa! 2in+3
Introduction
Ths verson of Orace s easer to nsta than many of the prevous ones. However
there are st some traps and ssues to get around. f you |ust need a database wth
transacton support, get Postgresq (www.postgresq.org) - t s very easy to nsta.
Before You Get Oracle
Ths reease recommends 512 Mb of RAM, 1 GB of swap and 3 GB of dsk ! You can
get away wth 320 MB, 750 Mb and 2.5 Gb respectvey - provded you do not
attempt to create a database at nsta tme (wat unt ater !)
Do not attempt to nsta at a f you have ess than 200 Mb of RAM as the nstaer
w crash at nk tme ! (If you are an Orace nsta pro then you can nk manuay to
compete the process, but ts a bt of a pest).
Ths reease requres a 2.4.4 Kerne and Gbc 2.2.2. However you can nsta wth
2.4.2 (Redhat 7.1) or 2.4.3 (Mandrake 8.0) Kernes.
There s an undocumented dependency on Bnuts. The verson that comes wth
Redhat 7.1 causes Orace to be unnkabe. The souton s to use the verson that
comes wth Redhat 7.0 (bnuts-2.10.0.18) or Mandrake 8.0 (bnuts-2.10.1.0.2).
The tested combnatons were :
1. Redhat 7.0 wth bnuts-2.10.0.18
2. Mandrake 8.0 wth bnuts-2.10.1.0.2.
Getting Oracle
Vst www.orace.com and cck on "Orace technoogy Network". The current URL for
downoads s here. Seect "9 Database" and then pck the "Lnux" entry. You must
then agree to the cense before the actua downoad page appears.
There are three bg fes :
1. Lnux9_Dsk1.cpo.gz (400Mb)
2. Lnux9_Dsk2.cpo.gz (620 Mb)
3. Lnux9_Dsk3.cpo.gz (80 Mb)
They are actuay cpo archves ( not gzpped cpo archves ! ). You need fast
nternet access...or a frend wth fast nternet access.
Once downoaded then expand the archves somewhere where you have 2 GB of
space :
# cd /var/bgspace
# cpo -dmv Lnux9_Dsk1.cpo.gz
# cpo -dmv Lnux9_Dsk2.cpo.gz
# cpo -dmv Lnux9_Dsk3.cpo.gz
These expanded archves can be burned to three CDs to provde a convenent and
professona ookng nstaaton.
Preparation
Decde where you want Orace to be nstaed and create a drectory for t ( I use
/usr/orace/|verson| but ts up to you). In addton create a group and user for
Orace (ogn as root for ths) :
# groupadd dba
# useradd orace
# mkdr /usr/orace
# mkdr /usr/orace/9.0
# chown -R orace:dba /usr/orace
Remember you need 3 GB or so !
In addton I usuay create the fe /etc/oratab used to record databases :
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
# touch /etc/oratab
# chown orace:dba /etc/oratab
There s some fokore about settng a pethora of envronment varabes and a thng
caed "Optma Fexbe Archtecture". Ths busness s best summed up by sayng :
The procedure s nether optma, fexbe nor an archtecture... but a way of ayng
out fes that some Orace fok ke.
Ensure that you have nstaed X on your machne, as there s no onger a character
mode nstaer.
Orace, ke most databases, needs to use IPC to create shared memory. Typcay
the defaut amount confgured on most Lnux dstrbutons s mnma. To sort ths
out : ( as root here )
# sysct -w kerne.shmmax=100000000
# echo "kerne.shmmax = 100000000" >> /etc/sysct.conf
Ths enabes a shared memory segment to be 100 Mb ( probaby enough to start
you off...)
Installation
Logn as orace and proceed to nsta :
$ cd /var/bgspace
$ cd Dsk1
$ export ORACLE_HOME=/usr/orace/9.0
$ ./runInstaer
The |ava Gu nstaer w start and gude you through the process.
Ths part s now fary easy - |ust pck "9 Database", then ether of "Enterprse" or
"Standard Edton" dependng whether you want a the fancy bts or not ( btmap
ndexes, parttons, transportabe tabespaces etc requre Enterprse Edton).
The next step asks about what database you want, I usuay say "Software Ony"
and do the database ater.
You w be asked where |DK s... f you don't have a |DK t does not matter ( uness
you wsh to do |ava deveopment of course).
Then cck on nsta and wat for a whe.
At some pont you w be asked about the "other ocatons" for the remanng
software archves.. ts fary straghtforward what to be there ( f you have cut CDs,
ensure your termna wndow s not st cd'ed nto the cdrom mount drectory... )
Post Installation
Now comes creatng a database. There s a reasonabe Gu too for ths :
$ export PATH=$PATH:$ORACLE_HOME/bn
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/b
$ dbca &
Addtonay there s a network confguraton too wth a smar UI :
$ netca &
However I w deta a command ne creaton and confguraton of a database so
that some understandng of what s happenng can be ganed:
Set up confguraton for a database caed db1 :
$ cat "db1:/usr/orace/9.0:Y >> /etc/oratab"
$ cd $ORACLE_HOME/dbs
$ cat ntdw.ora |sed s/"#db_name = MY_DB_NAME"/"db_name = db1"/|sed
s/#contro_fes/contro_fes/ > ntdb1.ora
Start and create database :
$ export PATH=$PATH:$ORACLE_HOME/bn
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/b
$ export ORACLE_SID=db1
$ sqpus /noog <<!
connect / as sysdba
startup nomount
create database db1;
!
Ths creates a defaut database wth fes n $ORACLE_HOME/dbs
Now add the database meta data to actuay make t usefu :
$ sqpus /noog <<!
connect / as sysdba
@?/rdbms/admn/cataog
@?/rdbms/admn/catproc
!
Now create a user and gve t wde rangng permssons :
$ sqpus /noog <<!
connect / as sysdba
create user myuser dentfed by password;
grant create sesson,create any tabe to myuser;
grant unmted tabespace to myuser;
!
Now the usua sort of database stuff can be done :
$ sqpus myuser/password <<!
create tabe mytabe(d nteger, va varchar2(100));
nsert nto mytabes vaues(1,'xxxxx');
seect * from mytabe;
!
You can shut down the database wth :
$ sqpus /noog <<!
connect / as sysdba
shutdown
!
And start t agan wth :
$ sqpus /noog <<!
connect / as sysdba
startup
!
Smpe command ne versons of these are provded :
$ dbshut
$ dbstart
The thng that s unusua about Orace s that there s a one to one correspondence
between database server (ORACLE_SID) and database (db_name n
nt$ORACLE_SID.ora) - .e : one server manages one and ony one database.
Compare ths to Mysq or Postgresq where one server manages many databases. If
you want another database, then you must go through the above steps agan wth
ORACLE_SID set dfferenty and a new ntazaton fe wth a new db_name n t.
Networking
It s nce f remote cents can see your database, so here s the story :
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
$ echo " LISTENER = (ADDRESS_LIST= (ADDRESS=(PROTOCOL=tcp)
(HOST=ocahost)(PORT=1521)) (ADDRESS=(PROTOCOL=pc)(KEY=PNPKEY)))" >
$ORACLE_HOME/network/admn/stener.ora
$ nsrct start
$ echo "DB1 = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL =
TCP)(HOST = < your host >)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME =
db1)))" > $ORACLE_HOME/network/admn/tnsnames.ora
These two commands te the network stener where to sten, and cents were to
send connecton requests to. Ths can be tested by :
$ tnspng db1 1
Ths shoud return (ok) |number|
Housekeeping
It s easy to make Orace start automatcay. Create a scrpt caed orace n
/etc/nt.d that s ke : ( you need to be root here )
#!/bn/sh
#
# orace Ths she scrpt takes care of startng and stoppng
# the orace servces.
#
# chkconfg: 345 90 10
# descrpton: Orace server
#
# probe: true

# Source functon brary.
. /etc/rc.d/nt.d/functons
# Source networkng confguraton.
f | ! -f /etc/sysconfg/network |; then
ext 0
f
# Check for echo -n vs echo \c
f echo '\c' | grep -s c > /dev/nu 2 > &1 ; then
ECHO_N="echo -n"
ECHO_C=""
ese
ECHO_N="echo"
ECHO_C='\c'
f
# See how we were caed.
case "$1" n
start)
# Start server.
$ECHO_N "Startng Orace: "$ECHO_C
su - orace -c sqpus /noog >/dev/nu <<!
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
connect / as sysdba
startup
!
su - orace -c "snrct start > /dev/nu"
;;
stop)
# Stop server.
$ECHO_N "Stoppng Orace: "$ECHO_C
su - orace -c sqpus /noog > /dev/nu <<!
connect / as sysdba
shutdown abort
!
su - orace -c "snrct stop > /dev/nu"
;;
*)
echo $"Usage: $0 {start|stop}"
ext 1
;;
esac
ext 0
Then te the system to run t : ( as root agan )
# chkconfg --add orace
It s nce to set up the Orace .bash_profe to get ORACLE_SID and PATH workng by
defaut :
# .bash_profe
# Get the aases and functons
f | -f -/.bashrc |; then
. -/.bashrc
f

export BASH_ENV=$HOME/.bashrc
export ORAENV_ASK=NO
export ORACLE_SID=db1
f | -f /usr/oca/bn/oraenv |;then
. /usr/oca/bn/oraenv
f
ORAENV_ASK=YES
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/b
Fnay a more sophstcated scrpt to create a database n /var/oradata ( for
exampe ) : ( as orace )
#!/bn/bash
# ---------------------------------------------------------------------------
# fe : createdb1.sq
# ---------------------------------------------------------------------------

DB=db1
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
DBPATH=/var/oradata
ORACLE_SID=$DB

mknt()
{
export ORACLE_SID=$DB
export ORAENV_ASK=NO
. /usr/oca/bn/oraenv
cp nt$DB.ora $ORACLE_HOME/dbs
}

mkdb()
{
sqpus /noog <<!
CONNECT / AS SYSDBA
STARTUP NOMOUNT
CREATE DATABASE $DB
DATAFILE '$DBPATH/$DB/sys.dat' SIZE 200M
AUTOEXTEND ON
NEXT 10M
LOGFILE GROUP 1 '$DBPATH/$DB/og01.dat' SIZE 50M,
GROUP 2 '$DBPATH/$DB/og02.dat' SIZE 50M
;
!
}

scdb()
{
sqpus /noog <<!
CONNECT / AS SYSDBA
@?/rdbms/admn/cataog
@?/rdbms/admn/catproc
!
}

mktb()
{
sqpus /noog <<!
CONNECT / AS SYSDBA
CREATE TABLESPACE roback
DATAFILE '$DBPATH/$DB/roback.dat' SIZE 100M
AUTOEXTEND ON
NEXT 100M
DEFAULT STORAGE ( INITIAL 10M NEXT 10M PCTINCREASE 0)
;
CREATE TABLESPACE temp
DATAFILE '$DBPATH/$DB/temp.dat' SIZE 100M
AUTOEXTEND ON
NEXT 100M
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
DEFAULT STORAGE ( INITIAL 10M NEXT 10M PCTINCREASE 0)
TEMPORARY
;
CREATE TABLESPACE data
DATAFILE '$DBPATH/$DB/data.dat' SIZE 200M
AUTOEXTEND ON
NEXT 100M
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO
;
!
}

mko|()
{
sqpus /noog <<!
CONNECT / AS SYSDBA
CREATE ROLLBACK SEGMENt t0 ;
ALTER ROLLBACK SEGMENT t0 ONLINE;
SET TRANSACTION USE ROLLBACK SEGMENT t0;
CREATE ROLLBACK SEGMENT r0 TABLESPACE roback;
CREATE ROLLBACK SEGMENT r1 TABLESPACE roback;
ALTER ROLLBACK SEGMENT t0 OFFLINE;
DROP ROLLBACK SEGMENT t0;
!
echo "roback_segments = (r0,r1)" >> $ORACLE_HOME/dbs/nt$DB.ora
}

resp=n
echo -n "Create nta fes ?"
read resp
case $resp n
y) echo "Creatng ntazaton fes"
mknt
;;
esac


resp=n
echo -n "Create database ?"
read resp
case $resp n
y) echo "Creatng $DB"
mkdb
;;
esac

resp=n
echo -n "Run database scrpts ?"
Prepared by )r' /+bba 0a1+
Naresh i Technologies, Hyderabad, 04023746666
read resp
case $resp n
y) echo "Runnng scrpts for $DB"
scdb
;;
esac


resp=n
echo -n "Create tabespaces ?"
read resp
case $resp n
y) echo "Creatng tabespaces for $DB"
mktb
;;
esac

resp=n
echo -n "Create ob|ects ?"
read resp
case $resp n
y) echo "Creatng some ob|ects for $DB"
mko|
;;
esac
Prepared by )r' /+bba 0a1+

Das könnte Ihnen auch gefallen