centos 6.5 搭建JSP运行环境

时间:2022-02-21 17:32:24

一、安装nginx

yum install nginx      #安装nginx,根据提示,输入Y安装即可成功安装
service nginx start #启动
chkconfig nginx on #设为开机启动

这样就可以访问nginx的测试页面了。

二、安装JDK

上oracle的官网下载jdk for linux:

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

这个用wget下载不行,所以我就先在本地下载后用ftp上传上去了。

安装:

rpm -ivh jdk-7u75-linux-x64.rpm

添加环境变量

vi /etc/profile

在最后添加以下内容,这是默认的安装目录(我也不知道为什么是分号。。。)

export JAVA_HOME=/usr/java/jdk1.7.0_75
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

三、安装tomcat

下载tomcat:

http://tomcat.apache.org/download-70.cgi

然后解压下载的zip

unzip apache-tomcat-7.0.59.zip

添加环境变更

vi /etc/profile

在最后添加

export TOMCAT_HOME=opt/tomcat

还需要给执行的权限,我懒得去弄,直接给了全部权限(有空再写一篇Linux权限的)

chmod -R 777 /opt/tomcat

启动服务器

./startup.sh

这个时候就可以访问tomcat了

四、安装mysql

1、安装

yum install -y mysql-server mysql mysql-devel

2、启动服务

[root@iZ94xzz4gddZ bin]# service mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h iZ94xzz4gddZ password 'new-password' Alternatively you can run:
/usr/bin/mysql_secure_installation which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ]
Starting mysqld: [ OK ]

看到上面的提示:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h iZ94xzz4gddZ password 'new-password'

于是乎我们重置一下mysql的root用户的密码:

/usr/bin/mysqladmin -u root password 'new-password'

这个时候就可以通过mysql命令行登录。

五、通过nginx把请求转发到tomcat(即把80端口的请求转到8080端口下)

打开nginx的配置文件

vim /etc/nginx/conf.d/default.conf

改成如下:  

location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
proxy_pass http://localhost:8080/;
}

重启nginx服务

service nginx restart

打完收工。