nginx + tomcat 8.5 优化配置,安装nginx【centos6、7】

第一步安装 软件

1.1 依赖包

# yum -y install gcc
# yum install expat-devel
# sudo yum install  zlib-devel


到http://apr.apache.org/download.cgi#apr1这个地址下载所需要的包
apr-1.6.5.tar.gz
apr-iconv-1.2.2.tar.gz
apr-util-1.6.1.tar.gz

1.2安装APR

tar zxvf apr-1.6.5.tar.gz
cd apr-1.6.5
./configure --prefix=/usr/local/apr
make
make install
cd ..

写入到环境变量中

vi /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib

source /etc/profile
如果这个不写,第一次启动tomcat 没有问题,第二次就挂了,不知道什么鬼

1.3安装apr-iconv

tar -zxvf apr-iconv-1.2.2.tar.gz
cd apr-iconv-1.2.2
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
make
make install
cd ..


1.4安装 apr-util

tar zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-apr-iconv=/usr/local/apr-iconv/bin/apriconv
make && make install
cd ..

1.5 安装openssl-1.0.2

[root@localhost openssl-1.0.2f]# wget http://www.openssl.org/source/openssl-1.0.2f.tar.gz
[root@localhost openssl-1.0.2f]# tar -xzf openssl-1.0.2f.tar.gz
[root@localhost openssl-1.0.2f]# cd openssl-1.0.2f
[root@localhost openssl-1.0.2f]# mkdir /usr/local/openssl
[root@localhost openssl-1.0.2f]# ./config -fPIC --prefix=/usr/local/openssl enable-shared
[root@localhost openssl-1.0.2f]# make clean
[root@localhost openssl-1.0.2f]# make
[root@localhost openssl-1.0.2f]# make install
查看路径
[root@localhost openssl-1.0.2f]# which openssl
	/usr/local/openssl/bin/openssl
[root@localhost openssl-1.0.2f]# mv /usr/bin/openssl /usr/bin/openssl.bak1
[root@localhost openssl-1.0.2f]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
[root@localhost openssl-1.0.2f]# cd /usr/local/openssl
--------------------- 
查看版本
[root@localhost openssl-1.0.2f]#  openssl version
/usr/local/openssl/bin/openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or director
找不到动态库libssl.so.1.1,小问题,执行如下命令:
[root@localhost openssl-1.0.2f]#  vim /etc/ld.so.conf

在最后追加一行: 
/usr/local/openssl/lib 
然后执行:
[root@localhost openssl-1.0.2f]#  ldconfig /etc/ld.so.conf
[root@localhost openssl-1.0.2f]#  openssl version
OpenSSL 1.1.0f  25 May 2017

4.检测安装是否成功

openssl version -a

第二步 tomcat优化
2.1进入文件夹tomcat/bin. 打开catalina.sh文件,
找到下面的注释

# OS specific support.  $var _must_ be set to either true or false.

export JAVA_OPTS="-server -Xms512M -Xmx1400M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicit

2.2tomcat 配置文件

# mv /usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml.bak
# vi /usr/local/tomcat/conf/server.xml


  
  
  
  
  

  
    
  


  
    
   
    

    

         
        
      

      
        
      
    
  

 

2.3tomcat 安装native

cd /usr/local/tomcat/bin/
tar xzfv tomcat-native.tar.gz
cd tomcat-native-1.2.17-src/native/
./configure --with-apr=/usr/local/apr --with-java-home=/usr/java/jdk1.8.0_191-amd64 --with-ssl=/usr/local/openssl
		【备用命令./configure --with-apr=/usr/bin/apr-1-config】
make
make install

安装成功后提示

nginx + tomcat 8.5 优化配置,安装nginx【centos6、7】_第1张图片

2.4 tomcat整合 apr

vim /etc/profile
#在文件中加入下面这句话
export CATALINA_OPTS=-Djava.library.path=/usr/local/apr/lib
#使配置生效
source /etc/profile

2.5 修改tomcat 配置文件

vim tomcat/conf/server.xml
#将配置中的
Connector port="8080" protocol="HTTP/1.1"
改成
Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"

将配置中的
Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
改成
Connector port="8009" protocol="org.apache.coyote.ajp.AjpAprProtocol" redirectPort="8443"

重启tomcat,启动日志出现以下内容证明此时以APR模式启动

3,安装nginx 以及性能优化

3.1 SSL功能需要openssl库,下载地址:http://www.openssl.org/

3.2 gzip模块需要zlib库,下载地址:http://www.zlib.net/

3.3 rewrite模块需要pcre库,下载地址:http://www.pcre.org/

mkdir -p /home/nginx/logs

mkdir -p /etc/nginx

yum zlib 
yum install -y nginx

mv /etc/nginx/nginx.conf  /etc/nginx/nginx.conf.bak

vi /etc/nginx/nginx.conf


mkdir -p /usr/local/nginx/fastcgi_cache  用于缓存

nginx.conf

worker_processes                  8;
worker_rlimit_nofile              102400;

events {
    use epoll;
    worker_connections            65535;
    multi_accept                  on;
}


http {
    server_tokens                 off;
    open_file_cache               max=102400 inactive=20s;
    open_file_cache_valid         30s;
    open_file_cache_min_uses      1;
    reset_timedout_connection     on;
	charset   utf-8;

	server_names_hash_bucket_size 128;
	client_header_buffer_size 2k;
	large_client_header_buffers 4 4k;
	client_max_body_size 8m;
	
	fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
                 keys_zone=TEST:10m
                 inactive=5m;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 16 16k;
    fastcgi_busy_buffers_size 16k;
    fastcgi_temp_file_write_size 16k;
    fastcgi_cache TEST;
    fastcgi_cache_valid 200 302 1h;
    fastcgi_cache_valid 301 1d;
    fastcgi_cache_valid any 1m;
    fastcgi_cache_min_uses 1;
    fastcgi_cache_use_stale error timeout invalid_header http_500;  


    gzip                          on;
    gzip_min_length               2k;
    gzip_buffers                  4 32k;
    gzip_http_version             1.1;
    gzip_comp_level               6;
    gzip_types                    text/plain text/javascript text/xml text/css application/json application/javascript application/x-javascript application/xml;
    gzip_disable                  "MSIE [1-6]\."
    gzip_vary                     on;
    gzip_proxied                  any;

    tcp_nopush                    on;
    tcp_nodelay                   on;

    include                       mime.types;
    default_type                  application/octet-stream;
    sendfile                      on;

    keepalive_timeout             16;

    proxy_connect_timeout         8s;
    proxy_send_timeout            8s;
    proxy_read_timeout            8s;
    send_timeout                  3s;

    upstream web {
               server 127.0.0.1:80 max_fails=5 fail_timeout=30s weight=1;
    }

    server {
        listen       80;
        server_name  www.ityhy.com;
        
        proxy_set_header host                $host;
        proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
	    proxy_set_header   X-Real-IP   $remote_addr;

        location / {
            proxy_pass http://web;
        }
		
		location /status{
			 stub_status on;
		 }
		
		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css){
		expires       30d;
		}

    }
}

nginx 启动

nginx

nginx -s reload 

重启Nginx

service nginx restart
/etc/init.d/nginx stop
/etc/init.d/nginx start

指定文件启动nginx -c /etc/nginx/nginx.conf

指定文件重启nginx -c /etc/nginx/nginx.conf -s reload

https://www.cnblogs.com/odbo/p/5295690.html 【yum 安装 nginx 所在文件位置】

 

你可能感兴趣的:(java,docker)