網站架構,通常認爲是根據客戶需求分析的結果,準肯定位網站目標羣體,設定網站總體架構,規劃、設計網站欄目及其內容,制定網站開發流程及順序,以最大限度地進行高效資源分配與管理的設計。其內容有程序架構,呈現架構,和信息架構三種表現。前端
PV(Page View,頁面瀏覽量)即點擊量,一般意義上說PV的多少是衡量一個網絡新聞頻道或網站甚至一條網絡新聞的主要指標。pv的解釋是這樣的:一個訪問者在24小時(0點-23點)內到底看了網站的幾個頁面。須要注意的是:同一我的瀏覽網站的同一個頁面,不重複計算pv量,點擊100次頁只算1次。java
注:實線是正常狀況下的數據流向鏈接,虛線是異常狀況下的數據流向鏈接
mysql
軟件包:連接:https://pan.baidu.com/s/1YivUZgSCzpZMLPgvZ-Zobg
提取碼:b5hblinux
主機 | 系統 | IP地址 | 用途 |
---|---|---|---|
master | CentOS7 | 192.168.37.128 | nginx反向代理主機、redis緩存主機、mysql數據主庫 |
backup | CentOS7 | 192.168.37.130 | nginx反向代理備機、redis緩存備機、mysql數據備庫 |
web 1 | CentOS7 | 192.168.37.131 | tomcat服務器 |
web 2 | CentOS7 | 192.168.37.132 | tomcat服務器 |
一、關閉防火牆、SELinuxnginx
systemctl stop firewalld.service
setenforce 0web
二、yum安裝nginx、keepalived服務(主、從相同操做)redis
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/\
nginx-release-centos-7-0.el7.ngx.noarch.rpm
#安裝nginx包
yum install nginx keepalived -ysql
三、修改master上keepalived配置文件數據庫
vim /etc/keepalived/keepalived.confapache
! Configuration File for keepalived global_defs { router_id NGINX_HA #修改id,刪除如下四行 } vrrp_instance VI_1 { state MASTER interface ens33 #修改網卡 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.37.188 #內網虛擬IP 192.168.200.188 #外網虛擬IP } }
四、修改backup上keepalived配置文件
scp /etc/keepalived/keepalived.conf root@192.168.37.130:/etc/keepalived #配置文件複製到backup
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { router_id NGINX_HB #修改id } vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 51 #修改id號 priority 90 #優先級低於master advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.37.188 #內網虛擬IP 192.168.200.188 #外網虛擬IP } }
五、修改ngin反向代理(主、從操做相同)
vim /etc/nginx/nginx.conf
#gizp on upstream tomcat_pool { server 192.168.37.131:8080; #tomcat 1 server 192.168.37.132:8080; #tomcat 2 ip_hash; #穩固會話,不然沒法經過vip地址登陸 } server { listen 80; server_name 192.168.37.188; #虛擬IP location / { proxy_pass http://tomcat_pool; proxy_set_header X-Real-IP $remote_addr; } }
六、開啓nginx、keepalived服務
systemctl start keepalived.service
nginx -t -c /etc/nginx/nginx.conf #檢查配置文件正確性
systemctl start nginx.service
一、解壓java環境包、tomcat安裝包
tar zxf jdk-8u144-linux-x64.tar.gz -C /usr/local
tar zxf apache-tomcat-8.5.23.tar.gz -C /usr/local
二、對解壓後軟件包重命名
cd /usr/local
mv apache-tomcat-8.5.23/ tomcat8
mv jdk1.8.0_144/ java
三、添加java環境變量
vim /etc/profile #末尾添加
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export PATH=$PATH:/usr/local/java/bin
export CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib
四、加載環境變量,檢測java是否識別
source /etc/profile
java -version #查看版本
五、創建tomcat啓動文件的軟鏈接,使系統識別
ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup
ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown
六、修改首頁,區分兩臺tomcat
cd /usr/local/tomcat8/webapps/ROOT vim index.jsp this is tomcat 1 #另外一臺首頁爲 ** this istomcat 2**
七、開啓tomcat服務
cd /usr/local/tomcat8/webapps/ROOT
tomcatup
八、經過虛擬IP訪問tomcat驗證服務
cd /usr/local/tomcat8/conf/ vim server.xml (148行) <Context path="" docBase="SLSaleSystem" reloadable="true" debug="0"></Context> #SLSaleSystem:稍後會將此文件加入指定目錄
一、yum安裝mariadb(此處爲了方便安裝,用mariadb代替mysql);
yum install mariadb mariadb-server -y
二、開啓mariadb服務
systemctl start mariadb
netstat -ntap | grep 3306
三、mariadb數據庫常規安全設置
mysql_secure_installation
Enter current password for root (enter for none): 回車 #當前root密碼 Set root password? [Y/n] y #密碼自定 Remove anonymous users? [Y/n] n #不須要匿名用戶 Disallow root login remotely? [Y/n] n #須要root遠程登陸 Remove test database and access to it? [Y/n] n #不須要刪除 Reload privilege tables now? [Y/n] y #從新加載表
四、導入數據庫商城數據
mysql -u root -p < /opt/abc/rhel7/pv/slsaledb-2014-4-10.sql
#slsaledb-2014-4-10.sql 須要自行導入,都放在博文開始的安裝包中
五、數據庫中受權,使商城能夠管理數據庫
mysql -u root -p
MariaDB [(none)]> grant all on slsaledb.* to 'root'@'%' identified by 'abc123';
MariaDB [(none)]> flush privileges;
一、將商城項目放到指定目錄
tar zxf SLSaleSystem.tar.gz -C /usr/local/tomcat8/webapps/
#SLSaleSystem.tar.gz在博文開始的安裝包中
二、修改配置文件
cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes
vim jdbc.properties
driverClassName=com.mysql.jdbc.Driver url=jdbc\:mysql\://192.168.37.188\:3306/slsaledb?useUnicode\=true&characterEncoding\=UTF-8 #改爲虛擬ip uname=root password=abc123 # 修改mysql的root密碼
三、重啓tomcat服務,訪問虛擬IP
tomcatdown
tomcatup
一、yum安裝redis
yum install epel-release -y
yum install redis -y
二、主redis上修改配置文件
vim /etc/redis.conf #改下面1行 bind 0.0.0.0
三、從redis上修改配置文件
vim /etc/redis.conf bind 0.0.0.0 #slaveof <masterip> <masterport> 266行 slaveof 192.168.37.128 6379 #指向主服務器的ip和端口
四、開啓redis服務
systemctl start redis.service
五、鏈接主redis,寫入內容
redis-cli -h 192.168.37.128 -p 6379 #鏈接redis
192.168.37.128:6379> set name test #寫入內容
192.168.37.128:6379> get name #查看內容
六、鏈接從redis,驗證是否同步
redis-cli -h 192.168.37.130 -p 6379 #鏈接redis
192.168.37.130:6379> get name #能看到主服務器寫入的內容"test"
七、經過虛擬IP鏈接redis驗證
redis-cli -h 192.168.37.188 -p 6379
一、查看redis狀態
redis-cli -h 192.168.37.128 info Replication
二、修改配置文件
vim /etc/redis-sentinel.conf //17行 protected-mode no #開啓羣集功能 //69行 sentinel monitor mymaster 192.168.71.128 6379 1 #master的地址,端口,從服務器1臺 //98行 sentinel down-after-milliseconds mymaster 3000 #設置切換時間
三、開啓服務(主、從都開啓)
systemctl start redis-sentinel.service
四、驗證主從切換
redis-cli -h 192.168.37.128 -p 26379 info Sentinel #查看羣集信息
systemctl stop redis #關掉主redis
cd /usr/local/tomcat8/webapps/SLSaleSystem/WEB-INF/classes
vim applicationContext-mybatis.xml
<!--redis 配置 開始--> <constructor-arg value="192.168.37.188"/> #指向虛擬IP <constructor-arg value="6379"/>
注意:配置完重啓tomcat服務
一、修改主、從mariadb配置文件
vim /etc/my.cnf
[mysqld] binlog-ignore-db=mysql,information_schema character_set_server=utf8 log_bin=mysql_bin server_id=1 #從服務器爲2 log_slave_updates=true sync_binlog=1
二、開啓mariadb
systemctl restart mariadb.service
三、主mariadb上受權
MariaDB [(none)]>grant replication slave on . to 'rep'@'192.168.37.%' identified by 'abc123';
MariaDB [(none)]>flush privileges;
MariaDB [(none)]>show master status;
四、從mariadb上同步
MariaDB [(none)]>change master to master_host='192.168.37.128',master_user='rep',master_password='abc123',master_log_file='mysql_bin.000001',master_log_pos=699;
MariaDB [(none)]>start slave;
MariaDB [(none)]>show slave status\G;
五、重啓mariadb
systemctl restart mariadb.service