Molet

Centos 5.5下配置nginx tomcat jdk

Molet linux 2023-01-25 449浏览 0

在Centos 5.5中安装Nginx+jdk+mysql+tomcat是非常容易的。只需yum安装环境包和nginx、解压安装jdk和tomcat、配置profile文件、server.xml和nginx.conf文件即可。具体步骤如下

一、安装环境包
1、首先使用yum命令安装、升级所需的程序库。
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-server krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

二、安装mysql和nginx
1、安装mysql5.5.13
安装cmake
tar zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4/
./configure  –prefix=/usr
gmake
gmake install

tar zxvf bison-2.4.3.tar.gz
cd cd bison-2.4.3
./configure
make
make install

安装mysql5.8.13
Groupadd mysql
Useradd -g mysql mysql
cmake -DMYSQL_USER=mysql -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql/data -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_SSL=yes -DWITH_DEBUG=0
make
make install
/usr/local/mysql/scripts/mysql_install_db –basedir=/usr/local/mysql/ –datadir=/data/mysql/data –user=mysql
cd /usr/local/mysql/support-files/
cp my-innodb-heavy-4G.cnf /data/mysql/my.cnf
cp mysql.server /etc/rc.d/init.d/mysql
chown mysql:mysql /etc/rc.d/init.d/mysql
chmod +w /etc/rc.d/init.d/mysql

2、安装nginx1.0.0
tar -zxvf pcre-8.12.tar.gz
cd pcre-8.12
./configure –prefix=/usr/local
make
make install
tar -zxvf nginx-1.0.0.tar.gz
cd nginx-1.0.0
./configure –prefix=/usr/local/nginx –user=www –group=www –with-http_stub_status_module –without-http_rewrite_module –with-http_ssl_module –with-pcre –with-http_realip_module
make
make install

三、安装jdk和tomcat
1、安装jdk
下载jdk:
wget http://download.oracle.com/otn-pub/java/jdk/6u29-b11/jdk-6u29-linux-i586.bin
安装jdk:
chmod +x jdk-6u29-linux-i586.bin
./jdk-6u29-linux-i586.bin
mv jdk1.6.0_29 /usr/local/jdk
配置环境变量:
vim /etc/profile
在/etc/profile末尾加入如下内容
JAVA_HOME="/usr/local/jdk"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:%JAVA_HOME/bin"
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME

保存退出
运行命令让环境变量生效
source /etc/profile

2、安装tomcat
下载tomcat
wget http://apache.etoak.com/tomcat/tomcat-7/v7.0.22/bin/apache-tomcat-7.0.22.tar.gz
tar -zxvf apache-tomcat-7.0.22.tar.gz
mv apache-tomcat-7.0.22 /usr/local/tomcat

设置路径和tomcat监听端口

mkdir /www
cp –rf /usr/local/tomcat/webapps/* /www/
vim /usr/local/tomcat/conf/server.xml
查找appBase=”webapps”,修改为appBase=”/www”,其中/www 即为网页的根目录。
安装完成后,启动tomcat,默认监听端口为8080
#/usr/local/tomcat/bin/startup.sh
停止tomcat可以使用以下命令:
#/usr/local/tomcat/bin/shutdown.sh

四、nginx配置监听tomcat运行端口
编辑配置nginx配置文件,我这里每个域名对应一个配置文件
vi /usr/local/nginx/conf/host/tomcat.conf

输入如下内容:
server
  {
    listen       80;
    server_name  192.168.4.212;
    index index.html index.htm index.jsp;
    root  /www/ROOT;

    #limit_conn   crawler  20;

    location ~ .*.jsp$
    {
      index index.jsp;
      proxy_pass http://127.0.0.1:8080;
      }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #设定访问静态文件直接读取不经过tomcat
    {
      expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }

#定义访问日志的写入格式
     log_format  access  '$remote_addr – $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /usr/local/nginx/logs/localhost.log access;#设定访问日志的存放路径

   }

启动nginx、tomcat就可以正常访问到jsp文件了
 

继续浏览有关 LINUX技术 的文章
发表评论