---
title: "Red Hat Linux 5 配置（Java&Tomcat&Mysql）"
author: "jef"
date: "2009-05-08T14:07:16Z"
tags: []
slug: "red-hat-linux-5-java-tomcat-mysql"
draft: false
lastmod: "2009-05-08T14:07:16Z"
id: 382073
url: "https://jef.iteye.com/blog/382073"
---

**服务器环境配置：**

**服务器：**  
CPU：Intel至强双核2.40GHz  
MEM：2G  
DISK：100G  
NET：Intel 82540EM

OS：Red Hat Enterprise Linux Server release 5.1 (Tikanga)  
Kernel：2.6.18-53.el5

**JAVA:**  
版本：jdk 1.6  
安装文件：jdk-6u5-linux-i586-rpm.bin  
安装路径：默认

**Tomcat:**  
版本：6.0.16  
安装文件：apache-tomcat-6.0.16.tar.gz  
安装路径：/usr/local/tomcat6/

**Mysql:**  
版本：5.1.34 Community Server (Red Hat Enterprise Linux 5 RPM (x86))  
安装文件：MySQL-server-community-5.1.34-0.rhel5.i386.rpm  
安装路径：默认

**安装过程：**

**Java**  
**1） 使jdk-6u5-linux-i586-rpm.bin变为可执行文件**  
*chmod a+x jdk-6u5-linux-i586-rpm.bin*  
**2） 解压jdk-6u5-linux-i586-rpm.bin**  
*./jdk-6u5-linux-i586-rpm.bin*  
**3） 安装\*.rpm**  
*rpm -ivh jdk-6u5-linux-i586.rpm*  
**4） 注意问题：**  
a) 配置/etc/profile文件增加环境变量（配置内容视具体情况而定）  
*export JAVA\_HOME=/usr/java/jdk1.6.0\_05*  
*export CLASSPATH=.:$JAVA\_HOME/lib:$JAVA\_HOME/jre/lib:$CLASSPATH*  
*export PATH=$PATH:$JAVA\_HOME/jre/bin*  
b) Red hat操作系统自带了java代码编译器（GIJ），需要使用sun jdk取代系统默认编译器。  
具体操作，删除 /usr/bin/java文件，建立文件软链接 ln –s /usr/java/jdk1.6.0\_05/jre/bin/java /usr/bin/java

**Tomcat**  
**1） 解压压缩包**  
*tar -zxvf apache-tomcat-6.0.16.tar.gz*  
**2） 移动至安装目录**  
*mv /usr/tomcat6/apache-tomcat-6.0.16/* /usr/tomcat6*  
**3） 修改配置文件**  
a) 修改默认端口  
b) 修改默认http路径指向（默认页面为Tomcat的欢迎页面）  
如：Host元素增加：*&lt;Context path="" docBase="at" debug="0" reloadable="true" /&gt;*  
**4） 启动与停止**  
启动：/usr/local/tomcat6/bin/startup.sh 后台模式  
/usr/local/tomcat6/bin/catalina.sh run 命令行模式  
停止：/usr/local/tomcat6/bin/shutdown.sh

**Mysql**  
**1） 安装服务器端**  
*Rpm –ivh MySQL-server-community-5.1.34-0.rhel5.i386.rpm MySQL-client-community-5.1.34-0.rhel5.i386.rpm*  
**2） 安装客户端**  
*rpm -ivh MySQL-client-community-5.1.34-0.rhel5.i386.rpm*  
**3） 修改默认的root用户密码（默认为空）**  
*mysqladmin -uroot password newpassword*  
**4） 启动与停止**  
启动：/etc/rc.d/init.d/mysql start  
停止：/etc/rc.d/init.d/mysql stop  
其他参数：  
*\[root@localhost ~]# /etc/rc.d/init.d/mysql*  
*Usage: /etc/rc.d/init.d/mysql  {start|stop|restart|reload|force-reload|status}  \[ MySQL server options ]*  
**5） 选择配置文件**  
a) 查看所有的配置文件

*\[root@localhost mysql]# find /usr/share/mysql/ -name 'my-\*' -print*  
*/usr/share/mysql/my-innodb-heavy-4G.cnf*  
*/usr/share/mysql/my-medium.cnf*  
*/usr/share/mysql/my-huge.cnf*  
*/usr/share/mysql/my-small.cnf*  
*/usr/share/mysql/my-large.cnf*

b) 配置文件说明  
***i. my-innodb-heavy-4G.cnf***  
*This is a MySQL example config file for systems with 4GB of memory*  
*running mostly MySQL using InnoDB only tables and performing complex*  
*queries with few connections.*  
***ii. my-medium.cnf***  
*Example MySQL config file for medium systems.*  
*This is for a system with little memory (32M - 64M) where MySQL plays*  
*an important part, or systems up to 128M where MySQL is used together with*  
*other programs (such as a web server)*  
***iii. my-huge.cnf***  
*Example MySQL config file for very large systems.*  
*This is for a large system with memory of 1G-2G where the system runs mainly*  
*MySQL.*  
***iv. my-small.cnf***  
*Example MySQL config file for small systems.*  
*This is for a system with little memory (&lt;= 64M) where MySQL is only used*  
*from time to time and it's important that the mysqld daemon*  
*doesn't use much resources.*  
***v. my-large.cnf***  
*Example MySQL config file for large systems.*  
*This is for a large system with memory = 512M where the system runs mainly*  
*MySQL.*  
c) 配置文件使用  
*You can copy this file to /etc/my.cnf to set global options, mysql-data-dir/my.cnf to set server-specific options (in this installation this directory is /var/lib/mysql) or ~/.my.cnf to set user-specific options.*  
*set global options 全局*  
*set server-specific options 指定数据库服务器*  
*set user-specific options 指定用户*  
*一般拷贝至 /etc/my.cnf 即可（全局有效）。*  
**6） 安装目录介绍**  
a) /var/lib/mysql/ 数据库文件，日志文件，mysql.sock  
*atapp   atest    ib\_logfile0  localhost.localdomain.err  mysql             mysql-bin.000002  mysql-bin.000004  mysql.sock*  
*atbase  ibdata1  ib\_logfile1  localhost.localdomain.pid  mysql-bin.000001  mysql-bin.000003  mysql-bin.index   test*  
b) /usr/share/mysql/ 可选配置文件，mysql.server，语言，字符集  
*binary-configure   czech       fill\_help\_tables.sql  japanese                my-large.cnf                    mysql.server                  norwegian-ny  serbian*  
*ChangeLog          danish      french                korean                  my-medium.cnf                   mysql\_system\_tables\_data.sql  polish        slovak*  
*charsets           dutch       german                mi\_test\_all             my-small.cnf                    mysql\_system\_tables.sql       portuguese    spanish*  
*config.huge.ini    english     greek                 mi\_test\_all.res         mysqld\_multi.server             mysql\_test\_data\_timezone.sql  romanian      swedish*  
*config.medium.ini  errmsg.txt  hungarian             my-huge.cnf             mysql\_fix\_privilege\_tables.sql  ndb-config-2-node.ini         russian       ukrainian*  
*config.small.ini   estonian    italian               my-innodb-heavy-4G.cnf  mysql-log-rotate                norwegian                     SELinux*  
c) /usr/bin/ mysql客户端和实用工具程序  
*\[root@localhost mysql]# find /usr/bin/ -name 'mysql\*' -print*  
*/usr/bin/mysql\_install\_db*  
*/usr/bin/mysql\_fix\_privilege\_tables*  
*/usr/bin/mysqlimport*  
*/usr/bin/mysql\_fix\_extensions*  
*/usr/bin/mysql\_waitpid*  
*/usr/bin/mysql\_find\_rows*  
*/usr/bin/mysql\_zap*  
*/usr/bin/mysqlhotcopy*  
*/usr/bin/mysql\_setpermission*  
*/usr/bin/mysql\_upgrade*  
*/usr/bin/mysql\_secure\_installation*  
*/usr/bin/mysqld\_multi*  
*/usr/bin/mysqlslap*  
*/usr/bin/mysqldumpslow*  
*/usr/bin/mysqlcheck*  
*/usr/bin/mysqltest*  
*/usr/bin/mysqlbinlog*  
*/usr/bin/mysqlaccess*  
*/usr/bin/mysql\_tzinfo\_to\_sql*  
*/usr/bin/mysqldump*  
*/usr/bin/mysql*  
*/usr/bin/mysql\_convert\_table\_format*  
*/usr/bin/mysqladmin*  
*/usr/bin/mysqld\_safe*  
*/usr/bin/mysqlshow*  
*/usr/bin/mysqlbug*  
**7） 其他**  
a) 字符集设定  
my.cnf文件 \[client]，\[mysqld]下分别添加 default-character-set=utf8  
b) 默认存储引擎设定  
my.cnf文件 \[mysqld]下添加 default-storage-engine=InnoDB  
c) 添加公网访问用户（不限IP）  
*grant all privileges on \*.* to yourname@"%" identified by 'yourpassword';*  
d) 常用命令  
i. show variables; 显示mysql配置信息（修改my.cnf后使用该命令检查配置更新）  
ii. show variables like '%character%'; 显示字符集信息  
iii. show create table tablename; 显示建表脚本  
iv. show index from tablename; 显示表索引  
v. mysql.server  
*Usage: ./mysql.server {start|stop|restart|reload|force-reload|status}  \[ MySQL server options ]*  
vi. mysqladmin  
*ping                  Check if mysqld is alive*  
*processlist           Show list of active threads in server*  
*reload                Reload grant tables*  
*refresh               Flush all tables and close and open logfiles*  
*shutdown              Take server down*  
*status                Gives a short status message from the server*  
*start-slave           Start slave*  
*stop-slave            Stop slave*  
*variables             Prints variables available*  
*version               Get version info from server*