首页 > 代码库 > 基于Linux环境Tomcat-MySQL的服务器搭建

基于Linux环境Tomcat-MySQL的服务器搭建

在开发日趋激烈的今天,我们可不能再只会编码了,这样搞不好,就成了一辈子的码奴!所以这里简单的分享一下服务器的搭建,由于Linux的安全性等一切因素让它成为了服务器平台的首选环境!今天跟大家分享的是Java项目的服务器搭建,好啦,步骤来了:

1、下载jdk

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html


2、下载tomcat

wget http://apache.etoak.com/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz

3、解压jdk和tomcat

mkdir /nac/www
mkdir /nac/www
cd  /nac/www
tar zxvf jdk-7u25-linux-i586.gz  
tar zxvf apache-tomcat-7.0.42.tar.gz

chmod –R 755  /nac

mv jdk1.7.0_25/  jdk
mv apache-tomcat-7.0.42  tomcat 

4、配置环境变量

vi /etc/profile
export JAVA_HOME=/nac/www/jdk
export PATH=$JAVA_HOME/bin:$JRE_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$LCASSPATH
export CATALINA_HOME=/nac/www/tomcat
export CLASSPATH=.:$JAVA_HOME/lib:$CATALINA_HOME/lib
export PATH=$PATH:$CATALINA_HOME/bin

刷新配置
source /etc/profile

5、修改*.sh权限和执行脚本

cd /apache-tomcat/bin/
chmod 777 *.sh
bash catalina.sh start

bash /apache-tomcat/bin/catalina.sh start

6、修改iptables

vi /etc/sysconfig/iptables

在里面添加

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT    //添加mysql
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT    //添加tomcat

7、修改mysql和tomcat开机启动

Chkconfig mysqld on
 Chkconfig mysqld –list  检查开机启动
修改vi /etc/rc.d/rc.local
/apache-tomcat/bin/catalina.sh start

8、添加mysql的用户名和密码

Mysql –u root

GRANT ALL PRIVILEGES ON *.* TO hupu@"%" IDENTIFIED BY 'hupu' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO hupu@localhost IDENTIFIED BY 'hupu' WITH GRANT OPTION;



GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY 'root' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'root' WITH GRANT OPTION;

9、在浏览器输入服务器的ip:8080,如下:“10.10.2.221:8080”,

当看到这里页面的时候,说明一切都ok了,就这样可以运行部署Java项目的服务器就搭建好了!