目录
systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
安装依赖环境
yum install -y pcre-devel zlib-devel openssl-devel gcc gcc-c++ make
创建运行用户、组
useradd -M -s /sbin/nologin nginx
上传nginx-1.15.9.tar.gz至/opt目录
cd /opt
tar xzvf nginx-1.15.9.tar.gz 解包
cd nginx-1.15.9/ 准备编译
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make j3 && make install 安装
路径优化
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
添加 Nginx 系统服务
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /lib/systemd/system/nginx.service 给权限
systemctl enable nginx.service 开机启动
systemctl start nginx.service 启动nginx
nginx -t 检查nginx配置文件
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
上传所需要的安装包到 /opt
pache-tomcat-9.0.16.tar.gz jdk-8u201-linux-x64.rpm
解压:
查看java版本 java -version
rpm -ivh jdk-8u201-linux-x64.rpm 解jdk包
设置JDK的环境变量
vim /etc/profile.d/java.sh #/etc/profile.d/ 环境变量脚本目录
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64 #输出指定java所需的类文件
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar #可执行文件的位置
export PATH=$JAVA_HOME/bin:$PATH
source /etc/profile.d/java.sh 全局变量加载生效
java -version 再次查看版本会有所变化
cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz 解包
mv apache-tomcat-9.0.16 /usr/local/tomcat #将解压后的包剪切到/usr/local 目录中,并改名为tomcat
ls /usr/local/tomcat 查看
优化管理tomcat
ln -s /usr/local/tomcat/bin/startup.sh /usr/local/bin/
ln -s /usr/local/tomcat/bin/shutdown.sh /usr/local/bin/
启动、关闭tomcat
startup.sh 开启
ps -aux | grep 8080 检查开启
shutdown.sh 关闭
优化Tomcat
vim /usr/java/jdk1.8.0_201-amd64/jre/lib/security/java.security
securerandom.source=file:/dev/urandom 修改117行
备份tomcat配置文件 cp
/usr/local/tomcat/conf/server.xml /usr/local/tomcat/conf/server.xml.bak
mkdir /usr/local/tomcat/webapps/test
vim /usr/local/tomcat/webapps/test/index.jsp #动态页面的配置
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<% out.println("动态页面 1,http://www.test1.com");%>
vim /usr/local/tomcat/conf/server.xml
shutdown.sh
startup.sh
tomcat2 添加虚拟主机配置
echo ‘
设置静态图片
配置负载均衡、反向代理
vim /usr/local/nginx/conf/nginx.conf
http {
......
#gzip on;
upstream tomcat {
server 192.168.226.129:8080 weight=1;
server 192.168.226.132:8080 weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~ .*\.jsp$ {
proxy_pass http://tomcatserver;
proxy_pass指令设置的主机名
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* \.(gif|jpg|swf|jpeg|bmp|ico)$ {
root /usr/local/nginx/html/img;
expires 1d;
}
location / {
root html;
index index.html index.htm;
}