经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库运维 » LinuxShell » 查看文章
集群搭建笔记
来源:cnblogs  作者:程康华  时间:2018/10/8 8:59:02  对本文有异议

目录

综合架构图

主机规划 ip

服务器主机名和 IP 规划参考模板

主机名 eth0 网卡 eth1 网卡 服务简介
lb01 10.0.0.5/24 172.16.1.5/24 负载服务
lb02 10.0.0.6/24 172.16.1.6/24 负载服务
web01 10.0.0.7/24 172.16.1.7/24 phpwww 服务
web02 10.0.0.8/24 172.16.1.8/24 php www 服务
tweb01 10.0.0.9/24 172.16.1.9/24 tomcat www 服务
db01 10.0.0.51/24 172.16.1.51/24 数据库服务
nfs01 10.0.0.31/24 172.16.1.31/24 存储服务
backup 10.0.0.41/24 172.16.1.41/24 备份服务
m01 10.0.0.61/24 172.16.1.61/24 管理服务

基础优化

  1. 修改ip地址
  2. sed -i 's#222#61#g' /etc/sysconfig/network-scripts/ifcfg-eth[01]
  3. 永久修改主机名
  4. [root@oldboy-c7 ~]# hostnamectl set-hostname oldboyedu-cc7
  5. [root@web01 data]# vim /etc/hosts
  6. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  7. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  8. 172.16.1.5 lb01
  9. 172.16.1.6 lo02
  10. 172.16.1.7 web01
  11. 172.16.1.8 web02
  12. 172.16.1.9 sweb
  13. 172.16.1.31 nfs
  14. 172.16.1.41 backup
  15. 172.16.1.51 db
  16. #批量推送其他主机
  17. [root@web01 data]# scp -rp /etc/hosts root@172.16.1.31:/etc/
  18. 调整yum
  19. CentOS 7
  20. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  21. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  22. //1.安装基础软件包
  23. yum install net-tools vim tree htop iftop iotop lrzsz sl wget unzip telnet nmap nc psmisc dos2unix bash-completion iotop iftop sysstat screen -y
  24. 1.自动补全
  25. yum install bash-completion -y
  26. 退出一次,然后重新登录
  27. 安装net-tools工具,可使用ifconfig命令
  28. yum install net-tools -y
  29. //2.关闭firewalld防火墙
  30. systemctl disable firewalld
  31. systemctl stop firewalld
  32. systemctl status firewalld
  33. //3.关闭selinux
  34. # 方式一
  35. sed -ri 's#(^SELINUX=).*#\1disabled#g' /etc/selinux/config
  36. # 方式二
  37. sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
  38. # 方式三
  39. vim /etc/selinux/config
  40. # 临时生效
  41. setenforce 0
  42. //4.优化ulimit
  43. echo '* - nofile 65535' >> /etc/security/limits.conf
  44. //5 重启快照

m01 搭建yum仓库

  1. 1.基础环境准备
  2. //安装ftp服务,启动并加入开机启动
  3. yum -y install vsftpd
  4. systemctl start vsftpd
  5. systemctl enable vsftpd
  6. //开启yum缓存功能
  7. vim /etc/yum.conf
  8. [main] cachedir=/var/cache/yum/$basearch/$releasever
  9. keepcache=1
  10. yum clean all
  11. 2.提供基础base
  12. mkdir /var/ftp/centos75
  13. mount /dev/cdrom /mnt
  14. cp -rp /mnt/Packages/*.rpm /var/ftp/centos75
  15. 3.提供第三方源
  16. mkdir /var/ftp/ops
  17. yum install net-tools vim tree htop iftop iotop lrzsz sl wget unzip telnet nmap nc psmisc dos2unix bash-completion iotop iftop sysstat screen -y
  18. //复制已缓存的 Nginx docker 及依赖包 到自定义 YUM 仓库目录中
  19. [root@yum_server_69_112 ~]# find /var/cache/yum/x86_64/7/ -iname "*.rpm" -exec cp -rf {} /var/ftp/ops \;
  20. 4.安装createrepo并创建 reopdata仓库
  21. //安装createrepo
  22. [root@yum_server_69_112 ~]# yum -y install createrepo
  23. //生成仓库信息
  24. createrepo /var/ftp/ops
  25. createrepo /var/ftp/centos75
  26. //注意: 如果此仓库每次新增软件则需要重新生成一次
  27. 客户端使用yum源
  28. 1.配置并使用base基础源
  29. [root@yum_client_69_113 ~]# gzip /etc/yum.repos.d/*
  30. [root@yum_client_69_113 ~]# vim /etc/yum.repos.d/centos7.repo
  31. [centos75]
  32. name=centos74_base
  33. baseurl=ftp://172.16.1.61/centos75
  34. gpgcheck=0
  35. 2.客户端指向本地ops源
  36. [root@yum_client_69_113 ~]# vim /etc/yum.repos.d/ops.repo
  37. [ops]
  38. name=local ftpserver
  39. baseurl=ftp://172.16.1.61/ops
  40. gpgcheck=0
  41. yum clean all
  42. yum makecache
  43. #其他客户端同步推送过去
  44. [root@backup ~]# rsync -avz /etc/yum.repos.d root@172.16.1.6:/etc/ --delete

backup- rsync全网备份

  1. [root@backup ~]# yum install rsync -y //基础环境已经安装
  2. [root@backup ~]# cat /etc/rsyncd.conf
  3. uid = www
  4. gid = www
  5. port = 873
  6. fake super = yes
  7. use chroot = no
  8. max connections = 200
  9. timeout = 600
  10. ignore errors
  11. read only = false
  12. list = false
  13. auth users = rsync_backup
  14. secrets file = /etc/rsync.password
  15. log file = /var/log/rsyncd.log
  16. #####################################
  17. [backup]
  18. path = /backup
  19. [data]
  20. path = /data
  21. [root@backup ~]# mkdir /backup/
  22. [root@backup ~]# groupadd -g666 www
  23. [root@backup ~]# useradd -u666 -g666 www
  24. [root@backup ~]# chown -R www.www /backup/
  25. [root@backup ~]# chmod 755 /backup
  26. # 创建rsync使用的虚拟连接用户
  27. [root@backup ~]# echo "rsync_backup:1" > /etc/rsync.password
  28. [root@backup ~]# chmod 600 /etc/rsync.password
  29. [root@backup ~]# systemctl enable rsyncd
  30. [root@backup ~]# systemctl start rsyncd
  31. 1 客户端定时执行脚本 推送 backup服务器
  32. [root@nfs ~]# mkdir -p /server/scripts/
  33. [root@nfs scripts]# cat /server/scripts/client_rsync_backup.sh
  34. #!/usr/bin/bash
  35. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  36. #1.定义变量
  37. Host=$(hostname)
  38. Addr=$(ifconfig eth1|awk 'NR==2{print $2}')
  39. Date=$(date +%F)
  40. Dest=${Host}_${Addr}_${Date}
  41. Path=/backup
  42. #2.创建备份目录
  43. [ -d $Path/$Dest ] || mkdir -p $Path/$Dest
  44. #3.备份对应的文件
  45. cd / && [ -f $Path/$Dest/system.tar.gz ] || tar czf $Path/$Dest/system.tar.gz etc/fstab etc/rsyncd.conf && [ -f $Path/$Dest/log.tar.gz ] || tar czf $Path/$Dest/log.tar.gz var/log/messages var/log/secure &&
  46. #4.携带md5验证信息
  47. [ -f $Path/$Dest/flag_$Date ] || md5sum $Path/$Dest/*.tar.gz >$Path/$Dest/flag_${Date}
  48. #4.推送本地数据至备份服务器
  49. export RSYNC_PASSWORD=1
  50. rsync -avz $Path/ rsync_backup@172.16.1.41::backup
  51. #5.本地保留最近7天的数据
  52. find $Path/ -type d -mtime +7|xargs rm -rf
  53. 2 服务端backup 校验压缩包 发送给管理员
  54. 1.配置邮箱(配发件服务器)
  55. [root@backup ~]# cat /etc/mail.rc
  56. yum install mailx -y
  57. set from=343264992@163.com
  58. set smtp=smtps://smtp.163.com:465
  59. set smtp-auth-user=343264992@163.com
  60. set smtp-auth-password=aa123456
  61. set smtp-auth=login
  62. set ssl-verify=ignore
  63. set nss-config-dir=/etc/pki/nssdb/
  64. [root@backup ~]# mkdir /server/scripts -p
  65. [root@backup scripts]# vim check_backup.sh
  66. #!/usr/bin/bash
  67. #1.定义全局的变量
  68. export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  69. #2.定义局部变量
  70. Path=/backup
  71. Date=$(date +%F)
  72. #3.查看flag文件,并对该文件进行校验, 然后将校验的结果保存至result_时间
  73. find $Path/*_${Date} -type f -name "flag_$Date"|xargs md5sum -c >$Path/result_${Date}
  74. #4.将校验的结果发送邮件给管理员
  75. mail -s "Rsync Backup $Date" 343264992@qq.com <$Path/result_${Date}
  76. #5.删除超过7天的校验结果文件, 删除超过180天的备份数据文件
  77. find $Path/ -type f -name "result*" -mtime +7|xargs rm -f
  78. find $Path/ -type d -mtime +180|xargs rm -rf
  79. 定时任务
  80. #多台客户端
  81. [root@nfs ~]# crontab -l
  82. 00 01 * * * /usr/bin/bash /server/scripts/clinet_rsync_backup.sh >/dev/null 2>&1
  83. 测试
  84. [root@web01 ~]# sh /server/scripts/client_rsync_backup.sh
  85. # 多台客户端快速增加
  86. [root@nfs01 yum.repos.d]# scp -rp /var/spool/cron/root root@172.16.1.7:/var/spool/cron/
  87. [root@nfs01 yum.repos.d]# rsync -avz /server root@172.16.1.8:/
  88. #服务端
  89. [root@backup backup]# crontab -l
  90. 00 05 * * * /usr/bin/bash /server/scripts/check_backup.sh >/dev/null 2>&1

nfs 共享存储项目

  1. nfs服务端
  2. [root@nfs ~]# yum install nfs-utils -y (已安装)
  3. [root@nfs ~]# cat /etc/exports
  4. /data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
  5. # nfs 依赖环境
  6. [root@nfs ~]# groupadd -g 666 www
  7. [root@nfs ~]# useradd -u 666 -g 666 www
  8. [root@nfs ~]# mkdir /data
  9. [root@nfs ~]# chown -R www.www /data
  10. # 启动nfs
  11. [root@nfs ~]# systemctl enable rpcbind nfs-server
  12. [root@nfs ~]# systemctl start rpcbind nfs-server
  13. nfs 客户端
  14. #安装工具包
  15. [root@web01 ~]# yum install nfs-utils -y (已安装)
  16. [root@web01 ~]# systemctl start rpcbind (默认开机自启动)
  17. #创建目录用于挂载
  18. [root@web01 ~]# mkdir /data
  19. # 挂载nfs的data目录
  20. root@web01 ~]# showmount -e 172.16.1.31
  21. Export list for 172.16.1.31:
  22. /data 172.16.1.0/24
  23. [root@web01 ~]# mount -t nfs 172.16.1.31:/data /data
  24. # 加入开机自启动
  25. 172.16.1.31:/data /data nfs defaults 0 0
  26. 测试:
  27. #通过windows上传一个视频或图片至/data
  28. wget http://img.mp.itc.cn/upload/20170511/cad88c2e57f44e93b664a48a98a47108_th.jpg
  29. # 验证内容是否存在nfs服务器
  30. [root@nfs ~]# ls /data/
  31. 1111 cad88c2e57f44e93b664a48a98a47108_th.jpg tes1 test

NFS 共享存储数据实时复制到 backup

  1. 安装inotify-tools
  2. [root@nfs ~]# yum install inotify-tools rsync -y
  3. 安装sersync
  4. [root@nfs ~]# wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz
  5. 解压重命名
  6. [root@nfs01 ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
  7. [root@nfs01 local]# mv GNU-Linux-x86/ sersync
  8. #配置sersync
  9. <fileSystem xfs="true"/> <!-- 文件系统 -->
  10. <inotify> <!-- 监控的事件类型 -->
  11. <delete start="true"/>
  12. <createFolder start="true"/>
  13. <createFile start="true"/>
  14. <closeWrite start="true"/>
  15. <moveFrom start="true"/>
  16. <moveTo start="true"/>
  17. <attrib start="false"/>
  18. <modify start="false"/>
  19. </inotify>
  20. <sersync>
  21. <localpath watch="/data"> <!-- 监控的目录 -->
  22. <remote ip="172.16.1.41" name="data"/> <!-- backupIP以及模块 -->
  23. </localpath>
  24. <rsync> <!-- rsync的选项 -->
  25. <commonParams params="-az"/>
  26. <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pass"/>
  27. <userDefinedPort start="false" port="874"/><!-- port=874 -->
  28. <timeout start="true" time="100"/><!-- timeout=100 -->
  29. <ssh start="false"/>
  30. </rsync>
  31. #创建密码文件
  32. [root@nfs01 sersync]# echo "1" > /etc/rsync.pass
  33. [root@nfs01 ~]# chmod 600 /etc/rsync.pass
  34. #backup创建目录
  35. [root@backup /]# mkdir /data
  36. [root@backup /]# chowm -R www.www /data
  37. 启动sersync
  38. [root@nfs ~]# /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml

SSH、Ansible,批量管理服务项目

  1. [root@backup ~]# rpm -ql openssh-server
  2. /etc/ssh/sshd_config --- ssh服务配置文件
  3. /usr/sbin/sshd --- ssh服务进程启动命令
  4. [root@backup ~]# rpm -ql openssh-clients
  5. /usr/bin/scp --- 远程拷贝命令
  6. /usr/bin/sftp --- 远程文件传输命令
  7. /usr/bin/ssh --- 远程连接登录命令
  8. /usr/bin/ssh-copy-id --- 远程分发公钥命令
  9. 1.创建密钥对
  10. [root@m01 ~]# ssh-keygen -t rsa -C xuliangwei.com #一路回车即可
  11. [root@m01 ~]# ls ~/.ssh/
  12. id_rsa(钥匙) id_rsa.pub(锁头)
  13. 2#发送密钥给需要登录的用户
  14. [root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.31
  15. #远程登录对端主机方式
  16. [root@m01 ~]# ssh root@172.16.1.41
  17. # 不登陆主机执行命令
  18. [root@m01 ~]# ssh root@172.16.1.41 "hostname -i"
  19. .ansible借助公钥批量管理
  20. #利用非交换式工具实现批量分发公钥与批量管理服务器
  21. [root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.41
  22. [root@m01 ~]# yum install ansible -y
  23. //检查ansible版本
  24. [root@m01 ~]# ansible --version
  25. ansible 2.6.1
  26. 配置ansible 主机清单
  27. [root@m01 ~]# vim /etc/ansible/hosts
  28. [root@m01 7]# cat /etc/ansible/hosts
  29. [lb]
  30. 172.16.1.5
  31. 172.16.1.6
  32. [web]
  33. 172.16.1.7
  34. 172.16.1.8
  35. [sweb]
  36. 172.16.1.9
  37. [nfs]
  38. 172.16.1.31
  39. [backup]
  40. 172.16.1.41
  41. [db]
  42. 172.16.1.51
  43. # ansible是通过ssh端口探测通信
  44. [root@m01 ~]# ansible all -m ping
  45. #批量执行命令
  46. [root@m01 ~]# ansible all -m command -a "df -h"
  47. [root@m01 ~]# ansible all -m command -a "hostname"

MySQL 数据库环境搭建

  1. # 1.下载MySQL官方扩展源 (yum仓库已经准备好)
  2. [root@nginx ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
  3. #2.安装mysql5.7, 文件过大可能会导致下载缓慢
  4. [root@nginx ~]# yum install mysql-community-server -y
  5. #3.启动数据库, 并加入开机自启动
  6. [root@nginx ~]# systemctl start mysqld
  7. [root@nginx ~]# systemctl enable mysqld
  8. #4.由于mysql5.7默认配置了默认密码, 需要过滤temporary password关键字查看对应登陆数据库密码
  9. [root@nginx ~]# grep 'temporary password' /var/log/mysqld.log
  10. #5.登陆mysql数据库[password中填写上一步过滤的密码]
  11. [root@web02 ~]# mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
  12. #6.重新修改数据库密码
  13. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ckh123.com';
  14. # 服务器mysql允许远程用户连接 (授权法)
  15. grant all privileges on *.* to 'all'@'%' identified by 'Ckh123.com';
  16. flush privileges;
  17. #7. web客户端安装 mysql (命令 测试用 可以不用装)
  18. [root@web02 ~]# yum provides mysql
  19. [root@web02 ~]# yum install mariadb -y
  20. [root@web02 ~]# mysql -h172.16.1.51 -uall -pCkh123.com

Nginx+PHP 流行动态 Web 环境搭建

  1. #1.使用Nginx官方提供的rpm包 (yum仓库已经准备好)
  2. [root@nginx ~]# cat /etc/yum.repos.d/nginx.repo
  3. [nginx]
  4. name=nginx repo
  5. baseurl=http://nginx.org/packages/centos/7/$basearch/
  6. gpgcheck=0
  7. enabled=1
  8. #2.执行yum安装
  9. [root@nginx ~]# yum install nginx -y
  10. # 修改nginx 运行身份
  11. sed -i '/^user/c user www;' /etc/nginx/nginx.conf
  12. [root@web01 ~]# id www
  13. uid=666(www) gid=666(www) 组=666(www)
  14. [root@web01 ~]# # groupadd -g 666 www
  15. [root@web01 ~]# # useradd -u666 -g666 www
  16. #3.启动并加入开机自启动
  17. [root@web01 ~]# systemctl start nginx
  18. [root@nginx ~]# systemctl enable nginx
  19. #检查 运行进程中式否www 用户运行
  20. [root@web01 ~]# ps aux |grep nginx
  21. www 2396 0.0 0.3 46996 1784 ? S 08:44 0:00 nginx: worker process
  22. root 2398 0.0 0.2 112720 984 pts/0 R+ 08:44 0:00 grep --color=auto nginx
  23. 使用第三方扩展epel源安装php7.1
  24. #1.移除旧版php (没有旧版 )
  25. [root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common
  26. #2.安装扩展源 (yum仓库已经准备了)
  27. # 依赖包
  28. [root@nginx ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  29. [root@nginx ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  30. # 或者用yum自行解决依赖包安装
  31. #3.安装php7.1版本
  32. [root@nginx ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
  33. #4.替换php-fpm运行的用户和组身份
  34. [root@web02 ~]# sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
  35. [root@web02 ~]# sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
  36. #5.启动php-fpm管理进程, 并加入开机自启
  37. [root@nginx ~]# systemctl start php-fpm
  38. [root@nginx ~]# systemctl enable php-fpm
  39. ansible 批量管理
  40. [root@m01 7]# ansible web -m yum -a "name=nginx state=installed"
  41. [root@m01 7]# ansible web -m shell -a "sed -i '/^user/c user www;' /etc/nginx/nginx.conf "
  42. [root@m01 7]# ansible web -m group -a "name=www gid=666"
  43. [root@m01 7]# ansible web -m user -a "name=www uid=666 group=666 "
  44. [root@m01 7]# ansible web -m service -a "name=nginx state=started enabled=yes"
  45. [root@m01 7]# ansible web -m yum -a "name=php71w,php71w-cli,php71w-common,php71w-devel,php71w-embedded,php71w-gd,php71w-mcrypt,php71w-mbstring,php71w-pdo,php71w-xml,php71w-fpm,php71w-mysqlnd,php71w-opcache,php71w-pecl-memcached,php71w-pecl-redis,php71w-pecl-mongodb state=installed"
  46. [root@m01 7]# ansible web -m shell -a "sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf;sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf"
  47. [root@m01 7]# ansible web -m service -a "name=php-fpm state=started enabled=yes"
  48. 调整网站上传文件大小
  49. vim /etc/php.ini
  50. memory_limit=1024M
  51. post_max_size=1024M
  52. upload_max_filesize=1024M  
  53. max_execution_time=60
  54. max_input_time=60
  55. vim nginx配置文件 nginx.conf, 找到http{} 添加
  56. client_max_body_size 1024M;
  57. # 重启服务生效配置
  58. [root@web01 code]# systemctl restart nginx php-fpm
  59. wordpress 安装 *
  60. [root@web01 conf.d]# cat wordpress.conf
  61. server {
  62. server_name wordpress.etiantian.org;
  63. listen 80;
  64. root /code/wordpress;
  65. index index.php index.html;
  66. location ~ \.php$ {
  67. root /code/wordpress;
  68. fastcgi_pass 127.0.0.1:9000;
  69. fastcgi_index index.php;
  70. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  71. include fastcgi_params;
  72. }
  73. }
  74. [root@web01 conf.d]# nginx -t
  75. [root@web01 conf.d]# systemctl restart nginx
  76. #1.获取wordpress代码
  77. [root@web01 ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
  78. #2.解压网站源码文件,拷贝至对应站点目录,并授权站点目录
  79. [root@web01 ~]# tar xf wordpress-4.9.4-zh_CN.tar.gz -C /code/wordpress/
  80. [root@web01 ~]# chown -R www.www /code/wordpress/
  81. # wordpress 产品需要手动创建数据库
  82. #1.登陆数据库
  83. [root@http-server ~]# mysql -uroot -pCkh123.com
  84. #2.创建wordpress数据库
  85. MariaDB [(none)]> create database wordpress;
  86. MariaDB [(none)]> exit
  87. # windows hosts解析 登录浏览器访问wordpress.etiantian.org 并安装
  88. wecenter 安装 *
  89. [root@web01 conf.d]# cat wecenter.conf
  90. server {
  91. server_name wecenter.etiantian.org;
  92. listen 80;
  93. root /code/wecenter;
  94. index index.php index.html;
  95. location ~ \.php$ {
  96. root /code/wecenter;
  97. fastcgi_pass 127.0.0.1:9000;
  98. fastcgi_index index.php;
  99. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  100. include fastcgi_params;
  101. }
  102. }
  103. [root@web01 code]# nginx -t
  104. [root@web01 code]# systemctl restart nginx
  105. # 下载wecenter 产品
  106. [root@web01 ~]# wget http://ahdx.down.chinaz.com/201605/WeCenter_v3.2.1.zip
  107. [root@web01 ~]# unzip WeCenter_v3.1.9.zip
  108. [root@web01 code]# mv WeCenter_3-2-1 wecenter
  109. [root@web01 ~]# chown -R www.www /code/wecenter/
  110. #1.登陆数据库
  111. [root@http-server ~]# mysql -uroot -pCkh123.com
  112. #2.创建wecenter数据库
  113. MariaDB [(none)]> create database wecenter;
  114. MariaDB [(none)]> exit
  115. # window hosts解析 通过浏览器访问 wecenter.etiantian.org 并安装

Nginx+Tomcat 流行动态 Web 环境搭建

  1. 1.准备Java基础环境
  2. [root@web02 ~]# yum install java jarjar-maven-plugin -y
  3. [root@web03 ~]# mkdir /server && cd /server
  4. 2.下载并安装Tomcat服务
  5. wget http://mirrors.shu.edu.cn/apache/tomcat/tomcat-8/v8.5.34/bin/apache-tomcat-8.5.34.tar.gz
  6. [root@web03 server]# tar xf apache-tomcat-8.5.34.tar.gz
  7. [root@web03 server]# ln -s /server/apache-tomcat-8.5.34 /server/tomcat8_1
  8. # 启动 tomcat 服务
  9. [root@lb01 ~]# /server/tomcat8_1/bin/startup.sh
  10. [root@lb01 ~]# netstat -lntp
  11. # 浏览器访问 http://10.0.0.9:8080/
  12. [root@web03 WEB-INF]# pwd
  13. /server/tomcat-8080/webapps/ROOT/WEB-INF
  14. [root@web03 webapps]# jar xf jpress-web-newest.war
  15. # 浏览器访问 http://10.0.0.9:8081/jpress
  16. 0.准备数据库[db01]
  17. mysql> create database jpress;
  18. 4.启动tomcat
  19. [root@web03 tomcat]# /root/tomcat/bin/startup.sh
  20. 关闭tomcat方式
  21. [root@web03 tomcat]# /root/tomcat/bin/shutdown.sh
  22. 5.proxy上新增java节点
  23. upstream php {
  24. server 172.16.1.7:80;
  25. server 172.16.1.8:80;
  26. }
  27. upstream java {
  28. server 172.16.1.9:8081;
  29. }
  30. server {
  31. server_name wordpress.etiantian.org;
  32. listen 80;
  33. location / {
  34. proxy_pass http://php;
  35. include proxy_params;
  36. }
  37. }
  38. server {
  39. server_name jpress.etiantian.org;
  40. listen 80;
  41. location / {
  42. proxy_pass http://java;
  43. include proxy_params;
  44. }
  45. }
  46. [root@lb01 conf.d]# nginx -t
  47. [root@lb01 conf.d]# systemctl restart nginx
  48. 6.tomcat提供静态存储[nfs操作]
  49. [root@nfs ~]# cat /etc/exports
  50. /data/blog 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
  51. /data/java 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666) #新增
  52. [root@nfs ~]# mkdir /data/java
  53. [root@nfs ~]# chown -R www.www /data/java/
  54. [root@nfs ~]# systemctl restart nfs-server
  55. 7.web03上操作
  56. [root@web03 ROOT]# yum install nfs-utils -y
  57. [root@web03 ROOT]# showmount -e 172.16.1.31
  58. Export list for 172.16.1.31:
  59. /data/java 172.16.1.0/24
  60. /data/blog 172.16.1.0/24
  61. 8.准备挂载环境
  62. [root@web03 ROOT]# groupadd -g 666 www
  63. [root@web03 ROOT]# useradd -g www -u 666 www
  64. 挂载
  65. [root@web03 ROOT]# cp -rp attachment/ attachment_bak
  66. [root@web03 ROOT]# rm -rf attachment/*
  67. [root@web03 ROOT]# mount -t nfs 172.16.1.31:/data/java /root/apache-tomcat-8.5.33/webapps/ROOT/attachment
  68. [root@web03 ROOT]# cp -rp attachment_bak/* attachment/
  69. 永久挂载
  70. [root@web03 ROOT]# cat /etc/fstab
  71. 172.16.1.31:/data/java /root/apache-tomcat-8.5.33/webapps/ROOT/attachment nfs defaults,_rnetdev 0 0
  72. [root@web03 ROOT]# mount -a

将 PHP 产品和 Tomcat 产品上传目录挂载到 NFS

  1. #1.web先找出图片存储的路径,然后进行挂载
  2. wordpress wp-content/uploads/
  3. wecenter uploads
  4. jpress attachment/
  5. # nfs01 服务器提供静态存储
  6. [root@nfs01 data]# cat /etc/exports
  7. /data/wordpress 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
  8. /data/wecenter 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
  9. /data/jpress 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
  10. [root@nfs01 data]# mkdir /data/{wecenter,jpress,wordpress}
  11. [root@nfs01 data]# chown -R www.www /data
  12. [root@nfs01 data]# systemctl restart nfs-server
  13. # web01 安装 nfs工具 (已经安装)
  14. [root@web01 code]# yum install nfs-utils
  15. [root@web01 code]# showmount -e 172.16.1.31
  16. Export list for 172.16.1.31:
  17. /data/jpress 172.16.1.0/24
  18. /data/wecenter 172.16.1.0/24
  19. /data/wordpress 172.16.1.0/24
  20. [root@web01 ~]# groupadd -g 666 www (已经创建了)
  21. [root@web01 ~]# useradd -g www -u 666 www
  22. # 挂载
  23. [root@web01 wecenter]# pwd
  24. /code/wecenter
  25. [root@web01 wecenter]# cp -rp uploads/ uploads_bak
  26. [root@web01 code]# mount -t nfs 172.16.1.31:/data/wecenter /code/wecenter/uploads
  27. [root@web01 code]# cp -rp /code/wecenter/uploads_bak/* /code/wecenter/uploads/
  28. [root@web01 code]# cat /etc/fstab
  29. 172.16.1.31:/data/wecenter /code/wecenter/uploads nfs defaults 0 0
  30. [root@web01 wp-content]# pwd
  31. /code/wordpress/wp-content
  32. [root@web01 wp-content]# cp -rp uploads/ uploads_bak
  33. [root@web01 code]# mount -t nfs 172.16.1.31:/data/wordpress /code/wordpress/wp-content/uploads
  34. [root@web01 code]# cp -rp /code/wordpress/wp-content/uploads_bak/* /code/wordpress/wp-content/uploads/
  35. [root@web01 code]# cat /etc/fstab
  36. 172.16.1.31:/data/wordpress /code/wordpress/wp-content/uploads nfs defaults 0 0
  37. #web03 的jpress
  38. [root@web03 jpress]# pwd
  39. /server/tomcat-8080/webapps/jpress
  40. [root@web03 jpress]# cp -rp attachment/ attachment_bak
  41. [root@web03 jpress]# mount -t nfs 172.16.1.31:/data/jpress /server/tomcat-8080/webapps/ROOT/attachment
  42. [root@web03 jpress]# groupadd -g 666 www
  43. [root@web03 jpress]# useradd -g www -u 666 www
  44. [root@web03 jpress]# chown -R www.www /server/tomcat-8080/webapps
  45. [root@web03 jpress]# cp -rp attachment_bak/* attachment/
  46. [root@web03 jpress]# cat /etc/fstab
  47. 172.16.1.31:/data/jpress /server/tomcat8_1/webapps/jpress/attachment nfs defaults 0 0

搭建 Nginx+keepalived 七层负载,172.16.1.5/6/lb01/lb02

  1. # web01 和web02 环境保持一模一样
  2. [root@web01 code]# rsync -avz /code root@172.16.1.8:/
  3. [root@web01 code]# rsync -avz /etc/nginx root@172.16.1.8:/etc/ --delete
  4. [root@web01 code]# scp -rp /etc/php.ini root@172.16.1.8:/etc/
  5. [root@web02 ~]# vim /etc/fstab
  6. 172.16.1.31:/data/wecenter /code/wecenter/uploads nfs defaults 0 0
  7. 172.16.1.31:/data/wordpress /code/wordpress/wp-content/uploads nfs defaults 0 0
  8. [root@web02 ~]# mount -a
  9. [root@web02 ~]# df -h
  10. [root@web02 code]# systemctl restart nginx php-fpm
  11. # 安装nginx
  12. [root@db01 ~]# yum install nginx
  13. [root@db01 conf.d]# mv default.conf default.conf.off
  14. [root@db01 conf.d]# cat proxy.conf
  15. upstream php {
  16. server 172.16.1.7:80;
  17. server 172.16.1.8:80;
  18. }
  19. upstream java {
  20. server 172.16.1.9:8080;
  21. }
  22. server {
  23. listen 80;
  24. server_name wordpress.etiantian.org;
  25. location / {
  26. proxy_pass http://php;
  27. include proxy_params;
  28. }
  29. }
  30. server {
  31. listen 80;
  32. server_name wecenter.etiantian.org;
  33. location / {
  34. proxy_pass http://php;
  35. include proxy_params;
  36. }
  37. }
  38. server {
  39. listen 80;
  40. server_name jpress.etiantian.org;
  41. location / {
  42. proxy_pass http://java;
  43. include proxy_params;
  44. }
  45. }
  46. [root@db01 conf.d]# cat /etc/nginx/proxy_params
  47. proxy_set_header Host $http_host;
  48. proxy_set_header X-Real-IP $remote_addr;
  49. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  50. proxy_connect_timeout 30;
  51. proxy_send_timeout 60;
  52. proxy_read_timeout 60;
  53. proxy_buffering on;
  54. proxy_buffer_size 32k;
  55. proxy_buffers 4 128k;
  56. [root@db01 conf.d]# nginx -t
  57. [root@db01 conf.d]# systemctl restart nginx
  58. ##windows hosts 解析 浏览器访问
  59. # +keepalived
  60. #两台lb 一模一样配置 , 快速配置一台lb02-6
  61. [root@lb02 ~]# yum install nginx
  62. [root@lb02 ~]# scp -rp root@172.16.1.5:/etc/yum.repos.d /etc/ (基础环境已经配置好yum仓库)
  63. [root@lb02 conf.d]# rsync -avz root@172.16.1.5:/etc/nginx /etc/ --delete
  64. [root@lb02 ~]# systemctl start nginx
  65. [root@lb02 ~]# systemctl enable nginx
  66. # 安装 keepalived
  67. [root@lb01 ~]# yum install keepalived -y
  68. [root@lb02 ~]# yum install keepalived -y
  69. #配置 keepalived
  70. [root@lb01 conf.d]# cat /etc/keepalived/keepalived.conf
  71. global_defs {
  72. router_id lb01
  73. }
  74. vrrp_instance VI_1 {
  75. state BACKUP
  76. interface eth0
  77. virtual_router_id 50
  78. priority 150
  79. advert_int 1
  80. authentication {
  81. auth_type PASS
  82. auth_pass 1111
  83. }
  84. virtual_ipaddress {
  85. 10.0.0.3
  86. }
  87. }
  88. [root@lb01 conf.d]# systemctl restart keepalived
  89. [root@lb01 conf.d]# systemctl enable keepalived
  90. [root@lb02 conf.d]# cat /etc/keepalived/keepalived.conf
  91. global_defs {
  92. router_id lb02
  93. }
  94. vrrp_instance VI_1 {
  95. state MASTER
  96. interface eth0
  97. virtual_router_id 50
  98. priority 100
  99. advert_int 1
  100. authentication {
  101. auth_type PASS
  102. auth_pass 1111
  103. }
  104. virtual_ipaddress {
  105. 10.0.0.3
  106. }
  107. }
  108. [root@lb02 conf.d]# systemctl restart keepalived
  109. [root@lb01 conf.d]# systemctl enable keepalived

配置 Nginx- tomcat- HTTPS 加密访问项目

  1. [root@web01 code]# mkdir /etc/nginx/ssl_key
  2. [root@web01 code]# cd /etc/nginx/ssl_key/
  3. [root@web01 ~]# openssl genrsa -idea -out server.key 2048
  4. 这里密码设置1234
  5. [root@web01 ~]# openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
  6. Country Name (2 letter code) [XX]:CN
  7. State or Province Name (full name) []:WH
  8. Locality Name (eg, city) [Default City]:WH
  9. Organization Name (eg, company) [Default Company Ltd]:edu
  10. Organizational Unit Name (eg, section) []:SA
  11. Common Name (eg, your name or your server's hostname) []:bgx
  12. Email Address []:bgx@foxmail.com
  13. [root@web01 ssl_key]# cat /etc/nginx/conf.d/wecenter-https.conf
  14. server {
  15. listen 443;
  16. server_name wecenter.etiantian.org;
  17. ssl on;
  18. ssl_certificate ssl_key/server.crt;
  19. ssl_certificate_key ssl_key/server.key;
  20. location / {
  21. root /code/wecenter;
  22. index index.php index.html;
  23. }
  24. location ~ \.php$ {
  25. root /code/wecenter;
  26. fastcgi_pass 127.0.0.1:9000;
  27. fastcgi_index index.php;
  28. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  29. include fastcgi_params;
  30. }
  31. }
  32. [root@web01 ~]# cat /etc/nginx/conf.d/wordpress-https.conf
  33. server {
  34. server_name wordpress.etiantian.org;
  35. listen 443;
  36. root /code/wordpress;
  37. index index.php index.html;
  38. ssl on;
  39. ssl_certificate ssl_key/server.crt;
  40. ssl_certificate_key ssl_key/server.key;
  41. location ~ \.php$ {
  42. root /code/wordpress;
  43. fastcgi_pass 127.0.0.1:9000;
  44. fastcgi_index index.php;
  45. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  46. include fastcgi_params;
  47. }
  48. }
  49. [root@web01 conf.d]# rsync -avz /etc/nginx root@172.16.1.8:/etc/ --delete
  50. [root@web01 ssl_key]# nginx -t
  51. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  52. nginx: configuration file /etc/nginx/nginx.conf test is successful
  53. [root@web01 ssl_key]# systemctl restart nginx
  54. # 负载均衡配置
  55. [root@lb01 code]# mkdir /etc/nginx/ssl_key
  56. [root@lb01 code]# cd /etc/nginx/ssl_key/
  57. [root@lb01 ssl_key]# scp -rp root@172.16.1.7:/etc/nginx/ssl_key/* ./
  58. [root@lb01 nginx]# cat /etc/nginx/conf.d/proxy-https.conf
  59. upstream php {
  60. server 172.16.1.7:443;
  61. server 172.16.1.8:443;
  62. }
  63. upstream java {
  64. server 172.16.1.9:8080;
  65. }
  66. server {
  67. listen 80;
  68. server_name wordpress.etiantian.org;
  69. return 302 https://$server_name$request_uri;
  70. }
  71. server {
  72. listen 80;
  73. server_name wecenter.etiantian.org;
  74. return 302 https://$server_name$request_uri;
  75. }
  76. server {
  77. listen 80;
  78. server_name jpress.etiantian.org;
  79. return 302 https://$server_name$request_uri;
  80. }
  81. server {
  82. listen 443 ssl;
  83. server_name jpress.etiantian.org;
  84. ssl on;
  85. ssl_certificate ssl_key/server.crt;
  86. ssl_certificate_key ssl_key/server.key;
  87. ssl_session_cache shared:SSL:1m;
  88. ssl_session_timeout 5m;
  89. ssl_ciphers HIGH:!aNULL:!MD5;
  90. ssl_prefer_server_ciphers on;
  91. location / {
  92. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  93. proxy_set_header Host $http_host;
  94. proxy_set_header X-Forwarded-Proto https;
  95. proxy_redirect off;
  96. proxy_connect_timeout 240;
  97. proxy_send_timeout 240;
  98. proxy_read_timeout 240;
  99. # note, there is not SSL here! plain HTTP is used
  100. proxy_pass http://java;
  101. }
  102. }
  103. server {
  104. listen 443;
  105. server_name wordpress.etiantian.org;
  106. ssl on;
  107. ssl_certificate ssl_key/server.crt;
  108. ssl_certificate_key ssl_key/server.key;
  109. location / {
  110. proxy_pass https://php;
  111. include proxy_params;
  112. }
  113. }
  114. server {
  115. listen 443;
  116. server_name wecenter.etiantian.org;
  117. ssl on;
  118. ssl_certificate ssl_key/server.crt;
  119. ssl_certificate_key ssl_key/server.key;
  120. location / {
  121. proxy_pass https://php;
  122. include proxy_params;
  123. }
  124. }
  125. # lb02 一样的配置
  126. [root@lb01 ssl_key]# rsync -avz /etc/nginx root@172.16.1.6:/etc/ --delete
  127. #其中最为关键的就是 ssl_certificate 和 ssl_certificate_key 这两项配置,其他的按正常配置。不过多了一个 proxy_set_header X-Forwarded-Proto https; 配置。
  128. Tomcat server.xml 完整配置
  129. [root@web03 server]# cat tomcat8_1/conf/server.xml
  130. <?xml version="1.0" encoding="UTF-8"?>
  131. <Server port="8011" shutdown="SHUTDOWN">
  132. <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  133. <Listener className="org.apache.catalina.security.SecurityListener" />
  134. -->
  135. <!--APR library loader. Documentation at /docs/apr.html -->
  136. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  137. <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  138. <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  139. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  140. <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  141. <Resource name="UserDatabase" auth="Container"
  142. type="org.apache.catalina.UserDatabase"
  143. description="User database that can be updated and saved"
  144. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  145. pathname="conf/tomcat-users.xml" />
  146. </GlobalNamingResources>
  147. <Service name="Catalina">
  148. <Connector port="8081" protocol="HTTP/1.1"
  149. connectionTimeout="20000"
  150. redirectPort="443"
  151. proxyPort="443" />
  152. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  153. <Engine name="Catalina" defaultHost="localhost">
  154. <Realm className="org.apache.catalina.realm.LockOutRealm">
  155. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  156. resourceName="UserDatabase"/>
  157. </Realm>
  158. <Host name="localhost" appBase="webapps"
  159. unpackWARs="true" autoDeploy="true">
  160. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  161. remoteIpHeader="x-forwarded-for"
  162. remoteIpProxiesHeader="x-forwarded-by"
  163. protocolHeader="x-forwarded-proto"
  164. prefix="localhost_access_log" suffix=".txt"
  165. pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  166. </Host>
  167. </Engine>
  168. </Service>
  169. </Server>
  170. #上述的配置中没有什么特别的,但是特别特别注意的是必须有 proxyPort="443",这是整篇文章的关键,当然 redirectPort 也必须是 443。同时 <Value> 节点的配置也非常重要,否则你在 Tomcat 中的应用在读取 getScheme() 方法以及在 web.xml 中配置的一些安全策略会不起作用。

将 NFS 存储数据实时复制到静态 Web 本地 172.16.1.9/10/web01/02

  1. # web01准备环境
  2. [root@web01 ~]# yum install rsync -y //基础环境已经安装
  3. [root@web01 ~]# cat /etc/rsyncd.conf
  4. uid = www
  5. gid = www
  6. port = 873
  7. fake super = yes
  8. use chroot = no
  9. max connections = 200
  10. timeout = 600
  11. ignore errors
  12. read only = false
  13. list = false
  14. auth users = rsync_backup
  15. secrets file = /etc/rsync.password
  16. log file = /var/log/rsyncd.log
  17. #####################################
  18. [data]
  19. path = /data
  20. [root@web01 ~]# mkdir /data/
  21. [root@web01 ~]# groupadd -g666 www (用户已经存在)
  22. [root@web01 ~]# useradd -u666 -g666 www
  23. [root@web01 ~]# chown -R www.www /data/
  24. [root@web01 ~]# chmod 755 /data (默认755)
  25. # 创建rsync使用的虚拟连接用户
  26. [root@web01 ~]# echo "rsync_backup:1" > /etc/rsync.password
  27. [root@web01 ~]# chmod 600 /etc/rsync.password
  28. [root@web01 ~]# systemctl enable rsyncd
  29. [root@web01 ~]# systemctl restart rsyncd
  30. # 复制之前的sersync 配置文件修改
  31. [root@nfs01 data]# cd /usr/local/sersync/
  32. [root@nfs01 sersync]# cp confxml.xml web01-confxml.xml
  33. [root@nfs01 sersync]# vim web01-confxml.xml # 修改的地方
  34. <host hostip="localhost" port="8009"></host>
  35. <remote ip="172.16.1.7" name="data"/>
  36. #启动服务
  37. [root@nfs01 sersync]# /usr/local/sersync/sersync2 -dro /usr/local/sersync/web01-confxml.xml
  38. web02 操作类似

Nginx 静态 Web 服务环境搭建 172.16.1.9/10/sweb01/02 +实现动静分离

  1. flag-------------------------------
  2. 系统 服务 地址
  3. CentOS7.5 proxy 10.0.0.5 lb01
  4. CentOS7.5 Nginx 10.0.0.7 web01
  5. CentOS7.5 TOmcat 10.0.0.9 web03
  6. # web01静态资源
  7. [root@web01 data]# wget http://nginx.org/nginx.png
  8. [root@web01 data]# cat /etc/nginx/conf.d/ds.conf
  9. server {
  10. listen 80;
  11. server_name ds.etiantian.org;
  12. root /data;
  13. index index.php index.html;
  14. location ~* .*\.(png|jpg|gif)$ {
  15. root /data;
  16. }
  17. }
  18. # web03 动态资源
  19. [root@web03 webapps]# cat /server/tomcat8_1/webapps/ROOT/java-test.jsp
  20. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
  21. <HTML>
  22. <HEAD>
  23. <TITLE>JSP Test Page</TITLE>
  24. </HEAD>
  25. <BODY>
  26. <%
  27. Random rand = new Random();
  28. out.println("<h1>Random number:</h1>");
  29. out.println(rand.nextInt(99)+100);
  30. %>
  31. </BODY>
  32. </HTML>
  33. #lb01 整合静态和动态资源在一个页面
  34. # nginx 配置
  35. [root@lb01 conf.d]# cat /etc/nginx/conf.d/ds.conf
  36. upstream static {
  37. server 10.0.0.7:80;
  38. }
  39. upstream javaround {
  40. server 10.0.0.9:8080;
  41. }
  42. server {
  43. listen 80;
  44. server_name ds.etiantian.org;
  45. location / {
  46. root /soft/code;
  47. index index.html;
  48. }
  49. location ~ .*\.(png|jpg|gif)$ {
  50. proxy_pass http://static;
  51. include proxy_params;
  52. }
  53. location ~ .*\.jsp$ {
  54. proxy_pass http://javaround;
  55. include proxy_params;
  56. }
  57. }
  58. # 代码
  59. [root@lb01 conf.d]# cat /soft/code/index.html
  60. <html lang="en">
  61. <head>
  62. <meta charset="UTF-8" />
  63. <title>测试ajax和跨域访问</title>
  64. <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
  65. </head>
  66. <script type="text/javascript">
  67. $(document).ready(function(){
  68. $.ajax({
  69. type: "GET",
  70. url: "http://ds.etiantian.org/java-test.jsp",
  71. success: function(data) {
  72. $("#get_data").html(data)
  73. },
  74. error: function() {
  75. alert("fail!!,请刷新再试!");
  76. }
  77. });
  78. });
  79. </script>
  80. <body>
  81. <h1>测试动静分离</h1>
  82. <img src="http://ds.etiantian.org/nginx.png">
  83. <div id="get_data"></div>
  84. </body>
  85. </html>
  86. # windows hosts 解析 10.0.0.5 ds.etiantian.org
  87. # 浏览器访问 http://ds.etiantian.org/ 图片和动态随机数同时显示在一个页面上,
  88. # 停掉web01 的nginx 页面的图片不显示,动态资源正常显示 反之一样
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号