综合架构后续内容及期末架构开场

2019-08-26  本文已影响0人  一只打不死的小强

综合架构的愿景

错误提示参考此文章------>Linux必备故障及原因50个


期末架构

期末架构的衍生

期末架构图

期末架构
设备名称 包含服务 用途 说明
用户浏览器 nginx(expire gzip) 浏览器缓存
网络加速设备 CDN 缓存网站的静态页面
防火墙 iptables,firewalld,安全组(阿里云) 访问控制 限制黑名单和白名单
负载均衡 lvs,nginx,haproxy lvs支持更高的并发(几万到几十万) nginx是四层和七层,lvs四层
缓存 nginx,varnish 缓存静态资源
网站 lnmp 实现动静分离
缓存 redis 缓存数据库的缓存,保持会话共享 数据库为整个架构中的短板
数据库 mysql,mongodb 数据库高可用,数据库主从 网站文字信息,文章内容,订单信息
存储 nfs,samba, 用户上传的数据 用户数据,数据库,配置文件,脚本网站代码
备份服务器 rsync,硬件 用户数据,数据库,配置文件,脚本网站代码 通常进行实时备份

补充:代码上线的过程

图片.png

面试的相关事项((只要有面试 就要有 总结)


面试的具体内容

笔试题(基础 )

面试(经验 框架 排错 优化)
考察

优化体系

系统优化
服务优化(nginx php tomcat)
安全优化

基础必备优化:

NetworkManager network
相同地方 管理网络 管理网络 区别 通过nmcli命令 修改配置文件 重启网卡生效

  1. 网络管理服务
NetworkManager network
相同地方 管理网络 管理网络
区别 通过nmcli命令 修改配置文件 重启网卡
#en_US.UTF8
#zh_CN.UTF8

二.基础服务优化:

Port 22 #修改默认的端口号
PermitRootLogin no #禁止root远程登陆

ssh远程连接慢

UseDNS no #禁止系统把ip解析对应域名
GSSAPIAuthentication no

配置内外网监听不同端口
ListenAddress 10.0.0.7:52113
ListenAddress 172.16.1.7:22

必须安装的工具 tree vim wget bash-completion (默认源) bash-completion-extras(epel) lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc

命令 作用
tree 以树形显示目录结构
psmisc pstree 等命令
vim vi升级版
wget 下载工具
bash-completion(默认源) 自动补全增强工具,可以补全命令参数
bash-completion-extras(epel) 自动补全超级增强工具,可以补全命令参数
lrzsz 上传下载工具 rz和sz
net-tools ifconfig route命令属于的软件包
sysstat sar iostat 属于的软件包
iotop 查询系统每个进程的io读写情况 swap写入情况
iftop 查询网络流量情况
nethogs 显示每个进程的流量情况
htop top升级版
unzip 解压
nc ncat 类似telnet
nmap 网络扫描工具
telnet 检查端口是否开启
bc 基础计算器
lsof 显示所有被打开的文件
1)临时 ulimit -n65535 
2)永久 /etc/security/limits.conf
echo '* - nofile 65535 ' >>/etc/security/limits.conf

export TMOUT=300 #timeout linux不进行任何操作 300s之后自动登出
export HISTFILE=1000 history 命令最多记录几条
export HISTFILESIZE=1000 history 历史记录的文件里面最多记录几条
export HISTCONTROL=ignorespace #控制history 命令如何记录 历史命令
只要以空格开头的命令 history不记录

三.内核优化:

前言:tracert 追踪路由的路径


追踪路由

中间的可以忽略,只关注开头和结尾。中间丢包因为途中经过国家骨干网,ping被禁止。

  echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf 
  sysctl -p 

注:为0时表示开启ping功能。

[root@web01 ~]# ip a 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:a5:bb brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.7/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:a5bb/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:82:a5:c5 brd ff:ff:ff:ff:ff:ff
    inet 172.16.1.7/24 brd 172.16.1.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe82:a5c5/64 scope link 
       valid_lft forever preferred_lft forever

[root@web01 ~]# echo '  net.ipv4.icmp_echo_ignore_all=1' >> /etc/sysctl.conf  
[root@web01 ~]# sysctl -p  #使刚才配置的生效。
net.ipv4.icmp_echo_ignore_all = 1
[root@web01 ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all 
1   

也可以echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
注意:使用此方法低于vi /etc/sysctl.conf的优先级,即使使用"echo 1 > (一定要加空格,否则会被认为输出重定向。)/proc/sys/net/ipv4/icmp_echo_ignore_all"的方法sysctl -p 会重新加载/etc/sysctl.conf文件下修改的内容,且echo 1到内存的方法是临时的。

[root@web01 ~]# ping 10.0.0.7
PING 10.0.0.7 (10.0.0.7) 56(84) bytes of data.
^C
--- 10.0.0.7 ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 5000ms

[root@web01 ~]# ping 172.16.1.7
PING 172.16.1.7 (172.16.1.7) 56(84) bytes of data.
^C
--- 172.16.1.7 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 999ms

开启内核转发功能(内网服务器,上外网的时候需要用到)

echo 'net.ipv4.ip_forward=1 ' >>/etc/sysctl.conf 
sysctl -p
/proc/sys/net/ipv4/ip_forward 

tcp的四次挥手time_wait等待断开连接的数量过多,需要将此优化。
显示tcp的各种状态--->ss -ant(netstat -tlunp)
java程序比较常见

 echo 'net.ipv4.tcp_tw_recycle=1 ' >>/etc/sysctl.conf 
 echo 'net.ipv4.tcp_tw_reuse=1 ' >>/etc/sysctl.conf 

/proc/sys/net/ipv4/tcp_tw_recycle #开启tcp回收功能
/proc/sys/net/ipv4/tcp_tw_reuse #开启tcp重复使用功能

echo 'vm.swappiness=10 ' >>/etc/sysctl.conf    

控制系统是否优先使用swap 数字越大越优先使用swap 越小越优先使用物理内存。

四、服务优化

nginx优化

点击download有不同的下载版本,版本为数值为奇数时时测试版,为偶数时为稳定版本。。

image

编译安装nginx 
./configure   生成配置文件 用于下一步的编译  
 make          编译代码--->命令或文件
 make install  编译生成的命令或文件 复制到 指定目录(-prefix) 

注意:如果不指定安装目录则默认安装到/usr/local下

编译安装的详细步骤

tar zcf  /backup/nginx-conf.bak   /etc/nginx/  #先进行备份
[root@web01 /html/blog]# rpm -e nginx 
error: Failed dependencies:    nginx is needed by (installed) nginx-mod-httpxslt-filter-1:1.12.2-3.el7.x86_64    
nginx is needed by (installed) nginx-mod-httpperl-1:1.12.2-3.el7.x86_64   
nginx is needed by (installed) nginx-mod-mail1:1.12.2-3.el7.x86_64    
nginx is needed by (installed) nginx-mod-stream1:1.12.2-3.el7.x86_64    
nginx is needed by (installed) nginx-mod-httpgeoip-1:1.12.2-3.el7.x86_64    
nginx is needed by (installed) nginx-mod-httpimage-filter-1:1.12.2-3.el7.x86_64 
[root@web01 /html/blog]# rpm -e nginx --nodeps #卸载时将相关依赖也卸载掉。
warning: /etc/nginx/nginx.conf saved as /etc/nginx/nginx.conf.rpmsave warning: file /etc/nginx/conf.d/default.conf: remove failed: No such file or directory

注意:尽量不要用yum remove nginx,可能将软件依赖其他的软件也同样给卸载掉。

开始进行编译安装

wget -P /app/tools   http://nginx.org/download/nginx-1.16.1.tar.gz #将源码包指定到/app/tools中,-P如果没有这个目录,则进行创建。
cd /app/tools #进入目录
tar xf nginx-1.16.1.tar.gz 解压源码包
cd nginx-1.16.1/ #进入解压目录
[root@zabbix nginx-1.16.1]# ll 
total 748
drwxr-xr-x 6 www www    326 Aug 27 17:18 auto
-rw-r--r-- 1 www www 296463 Aug 13 20:51 CHANGES
-rw-r--r-- 1 www www 452171 Aug 13 20:51 CHANGES.ru
drwxr-xr-x 2 www www    168 Aug 27 17:18 conf
-rwxr-xr-x 1 www www   2502 Aug 13 20:51 configure #脚本文件
drwxr-xr-x 4 www www     72 Aug 27 17:18 contrib
drwxr-xr-x 2 www www     40 Aug 27 17:18 html
-rw-r--r-- 1 www www   1397 Aug 13 20:51 LICENSE
drwxr-xr-x 2 www www     21 Aug 27 17:18 man
-rw-r--r-- 1 www www     49 Aug 13 20:51 README
drwxr-xr-x 9 www www     91 Aug 27 17:18 src
nginx-xxx/src/core/nginx.h 
nginx-xxx/src/http/ngx_http_header_filter_module.c 
nginx-xxx/src/http/ngx_http_special_response.c
把nginx 响应头的信息 nginx---->old-guang 
#C语言编写,#号不是注释。
root@web01 /app/tools/nginx-1.16.1]# grep -n old- src/core/nginx.h 
14:#define NGINX_VER          "old-guang/" NGINX_VERSION
22:#define NGINX_VAR          "old-guang"
[root@web01 /app/tools/nginx-1.16.1]# grep -n old-guang src/http/ngx_http_header_filter_module.c
49:static u_char ngx_http_server_string[] = "Server: old-guang" CRLF;
[root@web01 /app/tools/nginx-1.16.1]# grep -n old-guang  src/http/ngx_http_special_response.c
36:"<hr><center>old-guang</center>" CRLF
 ./configure --prefix=/app/nginx-1.16.1  --user=nginx --group=nginx --with-http_ssl_module  --with-http_stub_status_module

编译安装说明

./configure #--prefix=/app/nginx-1.16.1 指定按照路径 替你创建 >--user=nginx --group=nginx 服务运行用户
--with-http_ssl_module https
--with-http_stub_status_module stub_status 状态模块

 /configure: error: SSL modules require the OpenSSL library. 
You can either do not enable the modules, or install the OpenSSL library into the system, 
or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option

会出现没有相关依赖包的错误,需要安装相关依赖包。

yum install openssl-devel pcre-devel -y(pcre 语言兼容的正则表达式)
make  && make install
>如何知道上一步的编译安装是否成功,使用echo $?,如果$?=0则表示上一部执行成功,否则都运行失败。
 ln -s /app/nginx1.16.1/  /app/nginx  #生成软链接
[root@web01 /app/nginx-1.16.1]# ll  /app/nginx/ #避免使用nginx目录过长,生成一个软链接。 
total 0 
drwxr-xr-x 2 root root 333 Aug 27 11:03 conf #配置文件
drwxr-xr-x 2 root root  40 Aug 27 11:03 html 
drwxr-xr-x 2 root root   6 Aug 27 11:03 logs 
drwxr-xr-x 2 root root  36 Aug 27 11:28 sbin #命令
[root@web01 /app/nginx-1.16.1]# /app/nginx/sbin/nginx 
[root@web01 /app/nginx-1.16.1]# lsof -i:80 
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME nginx   15978  root    6u  IPv4  78226      0t0  TCP *:http (LISTEN) nginx   15979 nginx    6u  IPv4  78226      0t0  TCP *:http (LISTEN)
[root@web01 /app/nginx-1.16.1]# curl -I 10.0.0.7
HTTP/1.1 200 OK Server: old-guang/1.16.1 
Date: Tue, 27 Aug 2019 03:49:49 GMT 
Content-Type: text/html 
Content-Length: 612 
Last-Modified: Tue, 27 Aug 2019 03:03:32 GMT Connection: keep-alive 
ETag: "5d649d84-264" Accept-Ranges: bytes

如何将http响应报文中的版本信息隐藏

user www www; 将worker进程的用户变为www
worker_processes  4;#和cpu核心数一致
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    server_tokens off; #配置此命令,但是无法将版本修改为其他的字符串,nginx商业版支持。
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;

nginx -s reload 重新加载配置文件

[root@zabbix conf]# ps -ef |grep nginx 
root       7686      1  0 20:16 ?        00:00:00 nginx: master process nginx
www        7687   7686  0 20:16 ?        00:00:00 nginx: worker process
www        7688   7686  0 20:16 ?        00:00:00 nginx: worker process
www        7689   7686  0 20:16 ?        00:00:00 nginx: worker process
www        7690   7686  0 20:16 ?        00:00:00 nginx: worker process

让服务器cpu均衡nginx的服务

image
上一篇下一篇

猜你喜欢

热点阅读