CentOS 7 安装Nginx 部署Tomcat集群
来源:互联网 发布:360数据恢复是免费的吗 编辑:程序博客网 时间:2024/05/17 03:00
CentOS 7 安装Nginx
互联网的开放性成就了程序员的未来,I Love Internet!
一、安装依赖包
顺序安装依赖包:遇到【y/n】都选y回车yum install gcc*yum install pcre*yum install zlib*yum install openssl*yum install links*yum install lsb查看系统版本:lsb_release -a
二、下载安装包
进入opt目录,创建software文件夹 存放Nginx下载的安装程序
mkdir /opt/softwarecd /opt/software/wget http://nginx.org/download/nginx-1.10.2.tar.gztar -zxvf nginx-1.10.2.tar.gzcd nginx-1.10.2/mkdir -p /var/cache/nginxwget https://www.openssl.org/source/openssl-1.0.2j.tar.gztar -zxvf openssl-1.0.2j.tar.gz
四、编译 安装
cd /opt/software/nginx-1.10.2/./configure \--prefix=/usr/local/nginx\--sbin-path=/usr/sbin/nginx \--conf-path=/etc/nginx/nginx.conf \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx.pid \--lock-path=/var/run/nginx.lock \--http-client-body-temp-path=/var/cache/nginx/client_temp \--http-proxy-temp-path=/var/cache/nginx/proxy_temp \--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \--http-scgi-temp-path=/var/cache/nginx/scgi_temp \--user=nobody \--group=nobody \--with-pcre \--with-http_v2_module \--with-http_ssl_module \--with-http_realip_module \--with-http_addition_module \--with-http_sub_module \--with-http_dav_module \--with-http_flv_module \--with-http_mp4_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_random_index_module \--with-http_secure_link_module \--with-http_stub_status_module \--with-http_auth_request_module \--with-mail \--with-mail_ssl_module \--with-file-aio \--with-ipv6 \--with-http_v2_module \--with-threads \--with-stream \--with-stream_ssl_module \--with-openssl=/opt/software/nginx-1.10.2/openssl-1.0.2jmake & make install
五、启动验证安装成功
/usr/local/nginx/sbin/nginxlinks 127.0.0.1
显示welcome to nginx!安装成功。
六、开放80访问端口
开放80端口firewall-cmd --zone=public --add-port=80/tcp --permanent重启防火墙firewall-cmd --reload关闭防火墙service firewalld stop
七、编辑启动脚本
vim /etc/init.d/nginx复制一下代码到nginx文件中--------------------开始-----------------#!/bin/sh# chkconfig: 2345 80 20# Description: Start and Stop Nginx# Provides: nginx# Default-Start: 2 3 4 5# Default-Stop: 0 1 6PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binNAME=nginxNGINX_BIN=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/$NAME.confPIDFILE=/usr/local/nginx/logs/pid/$NAME.pidSCRIPTNAME=/etc/init.d/$NAMEcase "$1" instart)echo -n "Starting $NAME... "if netstat -tnpl | grep -q nginx;thenecho "$NAME (pid `pidof $NAME`) already running."exit 1fi$NGINX_BIN -c $CONFIGFILEif [ "$?" != 0 ] ; thenecho " failed"exit 1elseecho " done"fi;;stop)echo -n "Stoping $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "$NAME is not running."exit 1fi$NGINX_BIN -s stopif [ "$?" != 0 ] ; thenecho " failed. Use force-quit"exit 1elseecho " done"fi;;status)if netstat -tnpl | grep -q nginx; thenPID=`pidof nginx`echo "$NAME (pid $PID) is running..."elseecho "$NAME is stopped"exit 0 fi;;force-quit)echo -n "Terminating $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "$NAME is not running."exit 1fikill `pidof $NAME`if [ "$?" != 0 ] ; thenecho " failed"exit 1elseecho " done" fi;;restart)$SCRIPTNAME stopsleep 1$SCRIPTNAME start;;reload) echo -n "Reload service $NAME... "if netstat -tnpl | grep -q nginx; then$NGINX_BIN -s reloadecho " done"elseecho "$NAME is not running, can't reload."exit 1fi;;configtest)echo -n "Test $NAME configure files... "$NGINX_BIN -t;;*)echo "Usage: $SCRIPTNAME {start|stop|force-quit|restart|reload|status|configtest}"exit 1;;esac-----------------结束---------------------:wq! 保存分配可执行权限chmod a+x /etc/init.d/nginx重启服务器:reboot启动service nginx start停止service nginx stop重启service nginx reconfigure查看状态service nginx status
八、配置开机启动Nginx
新增nginx.service文件vim /lib/systemd/system/nginx.service------------------内容--------------------[Unit]Description=nginx After=network.target [Service] Type=forking ExecStart=/etc/init.d/nginx start ExecReload=/etc/init.d/nginx restart ExecStop=/etc/init.d/nginx stop PrivateTmp=true [Install] WantedBy=multi-user.target------------------结束--------------------保存:wq!启用:systemctl enable nginx.service测试配置是否成功:systemctl start nginx.service查看是否启动:netstat -lntp|grep nginx
九、配置nginx.conf
重点内容根据一下内容修改nginx配置项,没有无需改动,相同无需改动.
vim /usr/local/nginx/conf/nginx.conf-------------------开始---------------------events{ use epoll; worker_connections 51200; multi_accept on; } http { server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; server_tokens off; log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; server { } }-------------------结束---------------------
十、部署Tomcat集群
vim /usr/local/nginx/conf/nginx.conf-------------------开始---------------------未完待续-------------------结束---------------------
0 0
- CentOS 7 安装Nginx 部署Tomcat集群
- Nginx+Tomcat集群部署
- Centos+nginx+tomcat 集群
- Nginx和Tomcat集群部署
- CentOS apache+Tomcat集群部署
- nginx tomcat集群安装
- nginx安装&tomcat集群
- day30 Linux中安装JDK, MySQL, tomcat, 部署nginx集群, 以及window中部署tomcat+nginx集群
- ActiveMQ CentOS集群安装部署
- Centos 7 从零搭建nginx+tomcat集群
- CentOs下Nginx安装部署
- Nginx安装,及集群tomcat
- nginx+tomcat集群安装配置
- Centos7+nginx+tomcat 集群部署实战
- CentOS+Nginx+Tomcat集群及负载均衡
- (四)Linux环境部署(Centos+Nginx+Tomcat+Mysql) - 安装Tomcat和JDK 以及 Nginx与Tomcat整合
- nginx安装和nginx、tomcat集群配置
- Centos安装配置nginx+tomcat
- 添加 swap 分区
- java继承
- 在Linux上的使用开源C++日志库---log4cplus
- Fibonacci数
- 委托、事件与Observer设计模式
- CentOS 7 安装Nginx 部署Tomcat集群
- Oracle数据库导入导出命令总结
- UIScrollView 代理 实现事件的监听
- cuda 入门
- spark core 2.0 CoarseGrainedSchedulerBackend SchedulerBackend ExecutorAllocationClient 源代码解析
- linux中ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- swap 分区扩展
- centos安装kubernetes1.3(二)
- 使用log.retention.hours改变消息端的消息保存时间