9-nfs-crontab
Nginx反向代理三台服务器共用一台nfs
安装Nginx配置反向代理
安装方式:
yum install epel-relase
yum install nginx //epel方式安装
./configure --prefix=/usr/local/nginx --without-http_write_module //编译安装
启动方式:
/usr/local/nginx/sbin/nginx -c /usr/lcoal/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx -s reload
nginx负载均衡:
-
基于轮询:
http{ upstream myweb{ server 10.0.0.10; server 10.0.0.11; server 10.0.0.12; } server{ listen 80; location /{ proxy_pass http://myweb; } } }
-
基于权重
http{ upstream myweb{ server 10.0.0.10 weight=2; server 10.0.0.11 weight=1; server 10.0.0.12 weight=3; } server{ listen 80; location /{ proxy_pass http://myweb; } } }
-
基于IP
[root@bogon home]# cat 1.conf
http{
upstream myweb{
ip_hash;
server 10.0.0.10;
server 10.0.0.11;
server 10.0.0.12;
}
server{
listen 80;
location /{
proxy_pass http://myweb;
}
}
}
安装NFS存储服务
-
服务端
yum install rpcbind nfs-utils -y
-
服务端配置文件
/etc/exports
/share 192.168.1.102/24(rw,sync,fsid=0)
-
服务端产看
showmount * //查看自己共享的服务 rpcinfo exports showmount -a //显示已经与客户端连接上的目录信息 systemctl start rpcbind.service systemctl start nfs-server.service
-
客户端
yum install rpcbind nfs-utils -y systemctl enable rpcbind.service && systemctl start rpcbind.service show mount -e NFS服务器IP //检查服务器是否有共享目录
-
挂载服务器
mount -t nfs 192.168.16.107:/share /var/www/html/
crontab 定时任务
编写日志切割脚本,结合计划任务,每天凌晨两点,自动备份并切割nginx的访问日志
/usr/sbin/logrotate -f /etc/logrotate.d/nginx
mv /mnt/nginxaccess.log.1 /mnt/`date +%y%m%d`.log
tar vczf /mnt/`date +%y%m%d`.access.tar.gz /mnt/`date +%y%m%d`.log
rm `date +%y%m%d`.log
Crontab
2 0 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx
2 0 * * * /247/myscript/tar_nginxlog.sh