项目总体介绍html
**整个项目包括如下几个应用工程** 一、 用户APP 二、 商家APP 三、 业务平台管理后台 四、 商家业务管理后台 五、 官网 **总体项目规划设计以下** 一、 用户APP采用JAVA环境布署,初始环境两台服务器,实现负载均衡与高可用,前端负载使用nginx 作负载 二、 商家APP采用JAVA环境布署,初始环境两台服务器,实现负载均衡与高可用,前端负载使用nginx 作负载 三、 业务平台管理后台采用JAVA环境布署,初始环境一台服务器,前端使用nginx 反向代理,后续业务流量扩大,架构从新扩展 四、 商家平台管理后台采用JAVA环境布署,初始环境一台服务器,前端使用nginx 反向代理,后续业务流量扩大,架构从新扩展 五、 官方网站都是一些静态页面,采用nginx布署,WEB服务另安装FTP服务器,作为业务管理后台一些静态资源的上传 六、 数据库使用Mysql主从复制架构,程序上实现读写分享,从库开启binlog作备份使用 七、 全网全部备份数据所有同步到专业内网备份服务器,全部业务备份数据保留30天 八、 全网全部服务器监控(基本监控与服务监控)都采用zabbix监控
服务器IP地址规划以下前端
服务器环境与应用软件版本介绍java
服务器环境 [root@centos ~]# cat /etc/redhat-release CentOS release 6.8 (Final) [root@centos ~]# uname -r2.6.32-642.el6.x86_64
应用软件版本mysql
Nginx 1.12.1 Mysql 5.7.17 Jdk 1.8Tomcat 8.5.9 Zabbix 3.0Yum 源使用16三、阿里去、sohu国内的源均可以,自行选择Redis 4.0.1
服务器逻辑架构图linux
服务器基础环境配置
因使用云主机服务器,初始系统安装就略过了,若是须要批量安装的请参考前面的文章nginx
配置国内YUM源,以163为例c++
[root@centos ~]# cd /etc/yum.repos.d/[root@centos yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo[root@centos yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak[root@centos yum.repos.d]# mv CentOS6-Base-163.repo CentOS-Base.repo
安装须要的软件包web
[root@centos ~]# yum install lsof vim telnet dos2unix lrzsz tree –y
关闭不须要启动的服务redis
[root@centos ~]#for service in `chkconfig --list|grep 3:on|awk '{print $1}'`;do chkconfig --level 3 $service off;done[root@centos ~]#for service in crond network sshd rsyslog;do chkconfig --level 3 $service on;done[root@centos ~]# chkconfig --list|grep 3:on
修改SSH服务的默认配置sql
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak sed -i 's%#Port 22%Port 2233%g' /etc/ssh/sshd_config sed -i 's%#PermitRootLogin yes%PermitRootLogin no%g' /etc/ssh/sshd_config sed -i 's%#PermitEmptyPasswors no%PermitEmptyPasswors no%g' /etc/ssh/sshd_config sed -i 's%#UseDNS yes%UseDNS no%g' /etc/ssh/sshd_config egrep "UseDNS|2233|RootLogin|EmptyPass" /etc/ssh/sshd_config /etc/init.d/sshd reload
关闭selinux
配置文件/etc/selinux/config sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config egrep "SELINUX=" /etc/selinux/config
关闭防火墙
若是不是对外网的服务器,直接关闭防火墙,有外网地址的可建议开启,并容许相关的服务端口,并发高的服务器也不须要开启防火墙,可能会影响性能
/etc/invited/pintables stop/etc/invited/pintables statuspintables: Firewall is not running.
锁定系统关键文件
for file in /etc/passed /etc/shadow /etc/services /etc/initial /etc/rc.localdo chattr +i $filedone
配置普通操做用户及sudo权限
具体操做请参考公众号相关文章介绍
配置全网服务器时间同步
/usr/sbin/ntpdate time.windows.comcat>>/var/spool/cron/root<<EOF#this cron is for ntpdate */5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1#cron config end EOF
配置全网服务器hosts文件
Cat>>/etc/hosts<<EOF 10.0.0.1 nginx-lb 10.0.0.2 nginx-proxy 10.0.0.3 nginx 10.0.0.4 userapp 10.0.0.5 sjapp 10.0.0.6 admin 10.0.0.7 shangjia 10.0.0.8 web 10.0.0.9 mysql-m 10.0.0.10 mysql-s 10.0.0.11 ftp-backup 10.0.0.12 redis 10.0.0.13 backup-server 10.0.0.14 zabbix EOF
规范全部服务器目录
[root@centos ~]# mkdir /download/tools/ -p[root@centos ~]# mkdir /app/logs -p[root@centos ~]# mkdir /app -p[root@centos ~]# mkdir /server/{scripts,backup} –p
至此基本的服务器优化配置也就结束了,接下来就是安装各种服务
分发hosts文件到其它服务器
分发服务器使用全网备份服务器
首先建立分发用户
[root@centos ~]# useradd fenfa -u 999[root@centos ~]# echo "123456"|passwd --stdin fenfaChanging password for user fenfa. passwd: all authentication tokens updated successfully. [root@centos ~]# /bin/cp /etc/sudoers /etc/sudoers.bak[root@centos ~]# echo "fenfa ALL=(root) NOPASSWD:/usr/bin/rsync" >>/etc/sudoers[root@centos ~]# tail -1 /etc/sudoersfenfa ALL=(root) NOPASSWD:/usr/bin/rsync
切换到fenfa用户建立密钥
安装配置expect服务[root@centos ~]$ yum install expect* -y
编写脚本
[fenfa@centos ~]$ vim fenfa.exp#!/usr/bin/expectif {$argc != 2} { send_user "usage: expect xxxx.exp file host\n" it }#define varset file [lindex $argv 0]set host [lindex $argv 1]set password "123456"spawn ssh-copy-id -i $file fenfa@$hostexpect { "yes/no" {send "yes\r";exp_continue} "password" {send "$password\r"} } expect eof [fenfa@centos ~]$ vim fenfa_key.sh#!/bin/sh. /etc/init.d/functionsfor ip in `cat host.list`doexpect fenfa.exp ~/.ssh/id_dsa.pub $ip >/dev/null 2>&1if [ $? -eq 0 ];then action "$ip" /bin/true else action "$ip" /bin/falsefidone
执行脚本结果以下
[fenfa@centos ~]$ sh fenfa_key.sh10.0.0.1 [ OK ]10.0.0.2 [ OK ]10.0.0.3 [ OK ]10.0.0.4 [ OK ]10.0.0.5 [ OK ]10.0.0.6 [ OK ]10.0.0.7 [ OK ]10.0.0.8 [ OK ]10.0.0.9 [ OK ]10.0.0.10 [ OK ]10.0.0.11 [ OK ]10.0.0.12 [ OK ]10.0.0.13 [ OK ]10.0.0.14 [ OK ] [root@centos ~]# su - fenfa[fenfa@centos ~]$ ll /home/fenfa/.ssh/ total 4-rw------- 1 fenfa fenfa 602 Sep 21 12:14 authorized_keys
编写分发文件脚本
只须要将文件替换成你所须要分发的文件便可
前端反向代理及管理后台服务器的配置
前端nginx反向代理服务器配置
安装所需的依赖包
[root@centos ~]# yum install pcre-devel zlib-devle openssl-devel gcc-c++ –y
编译安装nginx
cd /download/tools/ wget http://nginx.org/download/nginx-1.12.1.tar.gz tar zxf nginx-1.12.1.tar.gz cd nginx-1.12.1./configure --prefix=/app/nginx-1.12.1make && make install [root@centos ~]# cd /app/[root@centos app]# ln -s nginx-1.12.1 nginx[root@centos ~]# cd /app/nginx/conf/[root@centos conf]# mkdir extra[root@centos conf]# cp nginx.conf nginx.conf.bak
在nginx.conf文件后增长下面的配置
include extra/*.conf; [root@centos ~]# cd /app/nginx/conf/extra/[root@centos extra]# vim admin.mingongge.conf## HTTPS server configuration#server { listen 80; server_name admin.mingongge.com; location / { proxy_pass http://10.0.0.6:8080; proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600; } } [root@centos extra]# vim shangjia.mingongge.conf## HTTPS server configuration#server { listen 80; server_name shangjia.mingongge.com; location / { proxy_pass http://10.0.0.7:8080; proxy_connect_timeout 600; proxy_read_timeout 600; proxy_send_timeout 600; } }
业务平台管理后台admin.mingongge.com
JDK Tomcat环境安装
tar zxf apache-tomcat-8.5.9.tar.gz mv apache-tomcat-8.5.9 /usr/local/tomcat tar zxf jdk-8u111-linux-x64.tar.gz -C /usr/local/cd /usr/local/ ln -s jdk1.8.0_111 jdk cat >>/etc/profile <<EOFexport JAVA_HOME=/usr/local/jdk1.8.0_111export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport PATH=$JAVA_HOME/bin:$PATHexport CATALINA_HOME=/usr/local/apache-tomcat-8.5.9 EOF [root@centos local]# source /etc/profile[root@centos local]# java -versionjava version "1.8.0_111"Java(TM) SE Runtime Environment (build 1.8.0_111-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
JDK Tomcat环境配置
<Context path="" docBase="/www/admin" debug="0" reloadable="true" crossContext="true" />echo "this is the admin.mingongge.com" >/www/admin/index.html /usr/local/tomcat/bin/startup.sh
商家管理后台 shangjia.mingongge.com
JDK Tomcat环境安装请参考前面的步骤 <Context path="" docBase="/www/shangjia" debug="0" reloadable="true" crossContext="true" />echo "this is the shangjia.mingongge.com" >/www/shangjia/index.html /usr/local/tomcat/bin/startup.sh
测试反向代理
[root@centos ~]# curl http://admin.mingongge.comthis is the admin.mingongge.com [root@centos ~]# curl http://shangjia.mingongge.comthis is the shangjia.mingongge.com
模拟用户访问