Article category: Java programming
Keywords: Linux Java Runtime Environment configuration MySQL JDK Tomcat
To enable Web applications, that is, websites, the first task is to install the running environment and configure the environment accordingly.
This article describes in detail how to build and configure a Java Web runtime environment on Linux (RedHat or other UNIX.
--------------------------------------------------------
|Step 2: prepare the required Installation Software
--------------------------------------------------------
(1) JDK: j2sdk-1_4_2_09-linux-i586.bin; 34.7 MB (36,429,599 bytes)
(2) WEB: jakarta-tomcat-4.1.31.tar.gz; 7.68 MB (8,058,534 bytes)
(3) DB: mysql-standard-4.1.15-pc-linux-gnu-i686-glibc23.tar.gz; 24.1 MB (25,276,587 bytes)
(4) jar: mysql-connector-java-3.1.11-bin.jar; 430 KB (440,483 bytes)
(4) is the jar package of mysql. After installing mysql, copy it to the mysql directory.
For mysql, try not to use versions earlier than 4.1.15 because UTF-8 encoding is not supported.
Some linux versions such as redhat will install a mysql by default during system installation. please uninstall it with the rpm command first.
The environment is relatively old. Please forgive me. I am used to this one and it is relatively stable. I have not changed it yet.
--------------------------------------------------------
|Step 2: Upload the software FTP to the Linux Server
--------------------------------------------------------
Upload the above installation software to a directory on linux using ftp, for example, temporarily put it in the/home directory.
--------------------------------------------------------
|Step 2 install JDK (j2sdk-1_4_2_09-linux-i586.bin)
--------------------------------------------------------
3.1 modify the installation package file to be executable
Reference chmod a + x j2sdk-1_4_2_09-linux-i586.bin
3.2 Installation started
Reference./j2sdk-1_4_2_09-linux-i586.bin
3.3 move to the specified installation and running directory
Reference mv j2sdk1.4.2 _ 09/usr/local/jdk1.4.2
Note: If you use the report image generation function such as jfreechat, and the report image contains Chinese characters, you must make the following settings.
Rename/usr/local/jdk1.4.2/jre/lib/font. properties. zh_CN.Redhat to font. properties,
Change the name of the original font. properties file to font. properties. old for backup.
--------------------------------------------------------
|Step 2: Install MySQL (mysql-standard-4.1.15-pc-linux-gnu-i686-glibc23.tar.gz)
--------------------------------------------------------
4.1 decompress the file
Reference tar xvzf mysql-standard-4.1.15-pc-linux-gnu-i686-glibc23.tar.gz
4.2 configure, install, and move
Reference cd mysql-standard-4.1.15-pc-linux-gnu-i686-glibc23
./Configure -- prefix =/usr/local/mysql
Music mysql-standard-4.1.15-pc-linux-gnu-i686-glibc23/usr/local/mysql
The default installation directory of mysql is/usr/local/mysql. If you do not want to install it in this directory, you must modify the mysql file (bin/mysqld_safe ), replace all '/usr/local/mysql' with the directory you want.
4.3 set the mysql user group and user)
Reference groupadd mysql; useradd-g mysql; cd/usr/local; chown-R mysql; chgrp-R mysql
4.4 start mysql
Reference/usr/local/mysql/bin/mysqld_safe-u mysql &
4.5 stop mysql
Reference/usr/local/mysql/bin/mysqladmin shutdown-u root
--------------------------------------------------------
|Step 2: install Tomcat (jakarta-tomcat-4.1.31.tar.gz)
--------------------------------------------------------
5.1 decompress the file
Reference tar zxvf jakarta-tomcat-4.1.31.tar.gz
5.2 move to the specified running directory
Reference music jakarta-tomcat-4.1.31/usr/local/tomcat4.1.31
5.3 copy the mysql-connector-java-3.1.11-bin.jar to/usr/local/tomcat4.1.31/common/lib
5.4 modify jvm memory count
Vi/usr/local/tomcat4.1.31/bin/catalina. sh Add the configuration JAVA_OPTS = '-Xms128m-xmx512m'
The specific location can be placed below:
Reference # JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"
# Command is executed. The default is 8000.
#
# Jsse_home (optional) may point at your Java Secure Sockets Extension
# (JSSE) installation, whose jar files will be added to
# System class path used to start Tomcat.
#
# Catalina_pid (optional) path of the file which shoshould contains the PID
# Of Catalina startup Java Process, when start (fork) is used
#
# $ Id: catalina. sh, v 1.37 15:20:15 markt Exp $
#-----------------------------------------------------------------------------
JAVA_OPTS = '-Xms128m-xmx512m'
# OS specific support. $ var _ must _ be set to either true or false.
Cygwin = false
Os400 = false
Note:
On unix/linux platforms, jdk cannot use the lib library of AWT for Image Generation and display. Therefore, the following configuration must be performed:
(1) This configuration is required for the jdk version. jdk 1.4.2 or later must be used, and jdk 1.4.1 cannot be used (tested ).
(2) modify the tomcat configuration file vi/usr/local/tomcat4.1.31/bin/catalina. sh
Add the string "-Djava. awt. headless = true/" to the following position in the file /"
Reference elif ["$1" = "start"]; then
Shift
Touch "$ CATALINA_BASE"/logs/catalina. out
If ["$1" = "-security"]; then
Echo "Using Security Manager"
Shift
"$ _ RUNJAVA" $ JAVA_OPTS $ CATALINA_OPTS/
-Djava. endorsed. dirs = "$ JAVA_ENDORSED_DIRS"-classpath "$ CLASSPATH "/
-Djava. security. manager/
-Djava. security. policy = "$ CATALINA_BASE"/conf/catalina. policy/
-Dcatalina. base = "$ CATALINA_BASE "/
-Dcatalina. home = "$ CATALINA_HOME "/
-Djava. io. tmpdir = "$ CATALINA_TMPDIR "/
-Djava. awt. headless = true/
Org. apache. catalina. startup. Bootstrap "$ @" start/
> "$ CATALINA_BASE"/logs/catalina. out 2> & 1 &
If [! -Z "$ CATALINA_PID"]; then
Echo $! > $ CATALINA_PID
Fi
Else
"$ _ RUNJAVA" $ JAVA_OPTS $ CATALINA_OPTS/
-Djava. endorsed. dirs = "$ JAVA_ENDORSED_DIRS"-classpath "$ CLASSPATH "/
-Dcatalina. base = "$ CATALINA_BASE "/
-Dcatalina. home = "$ CATALINA_HOME "/
-Djava. io. tmpdir = "$ CATALINA_TMPDIR "/
-Djava. awt. headless = true/
Org. apache. catalina. startup. Bootstrap "$ @" start/
> "$ CATALINA_BASE"/logs/catalina. out 2> & 1 &
If [! -Z "$ CATALINA_PID"]; then
Echo $! > $ CATALINA_PID
By now, all the software has been installed, and some configuration is required.
1. MySQL requires a configuration file my. CNF
(The file is included in the zip package in my attachment). You must put the file in the/etc directory of the linux server.
It mainly sets the database to adopt UTF-8 encoding, and also uses this configuration file to adjust various mysql running parameters.
Reference [client]
# Password = your_password
Default-character-set = utf8
Port = 3306
Socket =/tmp/mysql. sock
# Here follows entries for some specific programs
# The MySQL server
[Mysqld]
Default-character-set = utf8
Default-collation = utf8_general_ci
Port = 3306
Socket =/tmp/mysql. sock
2. mysql root User initialization password and adding a common user
Execute Command
Reference/usr/local/mysql/bin/mysqld_safe-u mysql &
/Usr/local/mysql/bin/mysql-uroot-p
Use mysql
# Set root password
Reference update user set password = password ('20140901') where user = 'root ';
Flush privileges;
# Create a database: testdb
Reference create database testdb default character set utf8 COLLATE utf8_general_ci;
# Create a test user for testdb database: username = testuser, password = testuser123
Reference delete from user where user = 'testuser ';
Insert into user (Host, User, password, Select_priv, Insert_priv,
Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv,
Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv,
Index_priv, Alter_priv, Show_db_priv, Super_priv,
Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv,
Repl_client_priv, ssl_type, ssl_cipher, x509_issuer, x509_subject,
Max_questions, max_updates, max_connections) VALUES ('%', 'testuser ',
'', 'N ', 'N', 'n ',
'N', 'n ','','', '','', 0, 0, 0 );
Update user set password = password ('testuser123') where user = 'testuser ';
Delete from db where user = 'testuser ';
Insert
Db (host, db, user, Select_priv, Insert_priv, Update_priv, Delete_priv, Lock_tables_priv)
Values ('%', 'testdb', 'testuser', 'y ');
Flush privileges;
3. Configure two configuration files under the conf directory of tomcat
: Server. xml, web. xml
For more information about the configuration, see the file in the attachment zip package.
You can configure virtual hosts through server. XML to allow many websites to share port 80 of Tomcat. (After Tomcat is installed, port 8080 is used by default. If it is placed on the Internet, change it to port 80)
4. Create a tomcat Startup Script File
, The content is as follows (if it is saved as startweb. Sh, You need to modify the attribute to execute chmod A + x startweb. Sh ):
Reference export java_home =/usr/local/jdk1.4.2
Export Path = $ java_home/bin: $ path
Export classpath = $ java_home/lib: $ java_home/JRE/lib/RT. jar :.
/Usr/local/tomcat4.1.31/bin/shutdown. Sh
/Usr/local/MySQL/bin/mysqladmin shutdown-u root-pabcxyz123456
I = 'ps-Ef | grep-e "Java" | grep-V grep | awk '{print $2 }''
Kill-9 $ I
I1 = 'ps-Ef | grep-e "mysqld_safe" | grep-V grep | awk '{print $2 }''
Kill-9 $ I1
/Usr/local/MySQL/bin/mysqld_safe-u MySQL &
/Usr/local/tomcat4.1.31/bin/startup. Sh
If you want to start or restart tomcat, you only need to execute this script file.
5. Set tomcat to self-start.
In the/etc/rc. d/rc. Local file, add
Reference/Script directory/startweb. Sh
So far, the Java Web environment has been installed, and all the software has been installed in the directory
/Usr/local/directory. because the corresponding installation software is relatively large, it is not provided here, and you need to download the corresponding software on your own. if the installation software you find is different from the one mentioned above
Same, please refer to the above installation and configuration methods, different software versions, installation and configuration may be different.