网站设计改版,影楼网站模板下载,建设防伪网站,在什么网站可以做推广公司企业架构LNMP(单点服务器部署) 学习目标和内容 1、能够描述项目流程 2、能够了解PV、QPS、DAU等参数 3、能够实现服务器基本环境配置 4、能够部署配置MySQL生产环境 5、能够部署配置Nginx生产环境 6、能够部署配置PHP生产环境 7、能够理解PHP-FPM和Nginx关联关系 8、能够配…公司企业架构LNMP(单点服务器部署) 学习目标和内容 1、能够描述项目流程 2、能够了解PV、QPS、DAU等参数 3、能够实现服务器基本环境配置 4、能够部署配置MySQL生产环境 5、能够部署配置Nginx生产环境 6、能够部署配置PHP生产环境 7、能够理解PHP-FPM和Nginx关联关系 8、能够配置Nginx关联到PHP-FPM 一、运维十年演变发展史
1、项目开发流程
公司老板和产品经理根据市场调查决定开发的一整套互联网产品
互动社交电商用户论坛BBS 产品决策老板产品UI设计》代码开发程序开发人员[前端开发[客户端页面或者APP]和后端开发[java php python node ruby]》测试工作测试人员》部署上线运维人员SA、dev 开发ops 运维 项目从开始策划实施上线维护一直到结束。称之为项目的生命周期。
作为运维人员来说不仅仅是在上线流程中参与。
需要在策划实施之初就进行准备工作。学习对应架构和方案的知识点等。
比如
①项目代码使用lnmp架构 那么就需要对lnmp架构熟悉
②开发人员需要多人协作开发合并代码就需要服务器上搭建代码版本控制器
③测试人员需要用到的测试环境等等
2、企业架构分布式集群解决方案 集群多台服务器在一起作同样的事 。 分布式 多台服务器在一起作不同的事 。 小饭店原来只有一个厨师切菜洗菜备料炒菜全干。后来客人多了厨房一个厨师忙不过来又请了个厨师两个厨师都能炒一样的菜这两个厨师的关系是集群。为了让厨师专心炒菜把菜做到极致又请了个配菜师负责切菜备菜备料厨师和配菜师的关系是分布式一个配菜师也忙不过来了又请了个配菜师两个配菜师关系是集群 最终的架构图示
实现负载均衡LB、高可用HA、数据库主从复制M-S、读写分离R-W、缓存中间件[memcached、Redis] nosql[mongodb]······· 3、业务背景 年份2008-2010 发布产品类型互联网动态站点 社区论坛 商城 社交类站点 ⽤户数量 100-500 PV 1000-300024小时访问次数总和 8小时 页面访问数量 点击量 QPS 5-10每秒访问查询次数 并发量 吞吐量 TPS RPS DAU 10-50每日活跃用户数 日活数 根据用户登录等方式 QPS 两种方法 ①计算 pv/时间 qps ②压测 使用ab等并发测试软件 在规定时间发送一定的请求数量 二、服务器基本环境部署
为了学习的方便和需要需要先进行基本环境的搭建 1、安装一台虚拟机centos6.9操作系统 2、网络配置 3、机器名FQDN设置 4、DNS解析设置 本地Hosts解析 5、各类防火墙暂时关闭 6、配置需要的yum环境及其源地址 7、vim安装配置 8、网络校时 ntpd 1、虚拟机软件搭建
可以参考文档《虚拟机和镜像.doc》
2、准备好ISO镜像文件
这里安装系统镜像采用minimal的方式自定义选择开发工具。安装更加快速系统也更加轻便。
可以参考文档《虚拟机和镜像.doc》
以上操作完成基本服务器镜像系统的安装
3、网络配置和检测
维护的机器数量比较多时单独配置静态IP是很繁琐。这里使用NAT模式DHCP自动分配IP
①vmware NAT连接方式本地DHCP服务启用 注意NAT服务和DHCP服务需要启动 ②IP租约和续约 不管采用何种方式获取到IP都可以能够管理清晰和使用明白即可。 4、FQDN设置重要
在集群中配置FQDN有助于进行区分主机身份。
server01 server01.lnmp.com
①添加修改/etc/hosts
shell vim /etc/hosts
#在文件里追加一行
192.168.17.102 server01.lnmp.com server01
②网卡配置/etc/sysconfig/network
shell vim /etc/sysconfig/network
#修改HOSTNAME的值为server01
HOSTNAMEserver01
5、防火墙关闭
centos6.x系列中
①关闭iptables
#关闭iptables
shell service iptables stop
#关闭开机自启动
shell chkconfig iptables off
②关闭selinux
#临时关闭
shell setenforce 0 /dev/null
#修改配置文件 永久关闭
shell sed -i s/SELINUXenforcing/SELINUXdisabled/ /etc/selinux/config;
6、yum源环境配置
配置本地光盘源使用centos的两个光盘
①虚拟机添加新光驱并选择光盘路径
注意添加设备需要关闭虚拟机里的操作系统 ②linux挂载多个光盘 #建立光盘挂载目录文件夹
shell mkdir /dvd1 /dvd2
#手动挂载光盘 顺便调整光盘顺序
shell mount /dev/sr0 /dvd2
shell mount /dev/sr1 /dvd1
#lsblk查看是否挂载成功
#添加到开启加载脚本 开机自动挂载光盘
shell echo mount /dev/sr0 /dvd2 /etc/rc.local
shell echo mount /dev/sr1 /dvd1 /etc/rc.local ③配置yum本地光盘源
shell cd /etc/yum.repos.d
shell mkdir bak
#移动默认源 备份并使其失效
shell mv ./* ./bak
#按照挂载光盘位置配置光盘源
7、安装vim编辑器并配置
①yum 安装vim配置显示行号
shell yum -y install vim
#配置vim默认显示行号
shell echo set nu /root/.vimrc
②grep搜索关键字高亮显示
#搜索关键字高亮
shell sed -i 8calias grepgrep --color /root/.bashrc
#当前窗口重新加载配置
shell source /root/.bashrc
8、网络校时重要 服务器校时的原因 ①因为计划任务要执行提供准确的时间 ②服务器间进行通信时需要统一的一致时间 #安装校时命令和服务
shell yum -y install ntp
#开启ntpd服务
shell service ntpd start
#开机自启ntpd
shell chkconfig ntpd on
国内第三方NTP校时网址
https://opsx.alibaba.com/service?langzh-cnactiveKey2
三、企业服务器LNMP环境搭建 常见的软件架构 ①C/S client/server ②B/S browser/server 不管是C还是B都是属于客户端属于前端。那么运维人员主要负责和管理的是server端也统称为服务器端。为了能够提供快速的提供服务端使用互联网中有多种解决方案和架构其中以下两种架构有着广泛的使用基础。 1 LAMP LinuxApacheMySQLPHP 2 LNMP LinuxNginxMySQLPHP lnmpa nginxmysqlphpapache lnmt nginxmysqltomcatjdk nginxmysqlpythonnodejs|ruby) 之前已经学习过了LAMP架构接上来学习LNMP架构解决方案。
在企业中搭建实际业务环境时一般依赖文件小文件使用yum安装解决生产业务环境需要使用源码编译的方式进行安装。 源码编译预估时间: Mysql 852s≈15m Nginx 27s≈1m PHP 564s≈10m 1、MySQL
###1.1、相关参数介绍
编译参数的说明
-DCMAKE_INSTALL_PREFIX安装到的软件目录-DMYSQL_DATADIR数据文件存储的路径-DSYSCONFDIR配置文件路径 (my.cnf)-DENABLED_LOCAL_INFILE1使用localmysql客户端的配置-DWITH_PARTITION_STORAGE_ENGINE使mysql支持分表-DEXTRA_CHARSETS安装支持的字符集-DDEFAULT_CHARSET默认字符集使用 这里配置为utf8mb4-DDEFAULT_COLLATION连接字符集-DWITH_SSL开启mysql的ssl使用
初始化参数说明
--basedir安装到的软件目录--datadir数据文件存储路径--usermysql使用的用户
###1.2、脚本实现安装及其初始化
#!/bin/bash
#源码编译安装MySQL
mysql_install() {#1、创建用户
id mysql /dev/null
[ $? -ne 0 ] useradd -s /sbin/nologin -M mysql
#2、解决依赖
yum install -y cmake
yum install -y ncurses-devel
#3、编译安装
cd /root/soft
tar zxvf mysql-5.6.33.tar.gz
cd mysql-5.6.33
cmake \
-DCMAKE_INSTALL_PREFIX/usr/local/mysql \
-DMYSQL_DATADIR/usr/local/mysql/data \
-DSYSCONFDIR/etc \
-DENABLED_LOCAL_INFILE1 \
-DWITH_PARTITION_STORAGE_ENGINE1 \
-DEXTRA_CHARSETSall \
-DDEFAULT_CHARSETutf8mb4 \
-DDEFAULT_COLLATIONutf8mb4_general_ci\
-DWITH_SSLbundled
make make install
#配置文件
rm -rf /etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
#授权并初始化数据库
chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir/usr/local/mysql --datadir/usr/local/mysql/data --usermysql
#配置服务、自启动和环境变量
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
chkconfig --add mysqld
echo PATH/usr/local/mysql/bin:$PATH /etc/profile
#删除匿名用户
#设置root域名的密码
rpm -qa|grep expect
if [ $? -ne 0 ];thenyum -y install expect
fi
#导入环境变量PATH
export PATH/usr/local/mysql/bin:$PATH
#初始化root密码 删除匿名用户
echo #!/usr/bin/expect
set timeout 60
spawn mysql_secure_installation
expect {
enter for none { send \r; exp_continue}
Y/n { send Y\r ; exp_continue}
password { send 123456\r; exp_continue}
Cleaning up { send \r}
}
interact mysql_secure_installation.exp
chmod x mysql_secure_installation.exp
./mysql_secure_installation.exp
}
#脚本开始时间
start_timedate %s
#执行的脚本代码
mysql_install
#脚本结束时间
end_timedate %s
#脚本执行花费时间
const_time$((end_time-start_time))
echo Take time is: $const_times
2、Nginx
2.1、介绍 常见用法 1) web服务器软件 httpd http协议 同类的web服务器软件apache nginx(俄罗斯) IIS(微软 fastcgi) lighttpd(德国) 2)代理服务器 反向代理 3)邮箱代理服务器 IMAP POP3 SMTP 4)负载均衡功能 LB loadblance Nginx架构的特点 ①高可靠稳定性 master进程 管理调度请求分发到哪一个worker worker进程 响应请求 一master多worker ②热部署 1平滑升级 2可以快速重载配置 ③高并发可以同时响应更多的请求 事件 epoll模型 几万 ④响应快尤其在处理静态文件上响应速度很快 sendfile ⑤低消耗cpu和内存 1w个请求 内存2-3MB ⑥分布式支持 反向代理 七层负载均衡 官方网址nginx news
2.2、安装
常见安装方式
①yum安装配置需使用Nginx官方源或者EPEL源
②源码编译 问题编译过程中出现问题 依赖解决 shell yum -y install pcre-devel zlib-devel openssl-devel 安装步骤及其脚本
#!/bin/bash
#编译安装Nginx
nginx_install(){
#创建软件运行用户
id www /dev/null
if [ $? -ne 0 ];thenuseradd -s/sbin/nologin -M www
fi
#安装依赖
yum -y install pcre-devel zlib-devel openssl-devel
#编译安装
cd /root/soft
tar xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix/usr/local/nginx --userwww --groupwww --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module make make install
}
#脚本开始时间
start_timedate %s
#执行的脚本代码
nginx_install
#脚本结束时间
end_timedate %s
#脚本执行花费时间
const_time$((end_time-start_time))
echo Take time is: $const_times
编译参数说明
参数作用--prefix编译安装到的软件目录--userworker进程运行用户--groupworker进程运行用户组--with-http_ssl_module支持https 需要pcel-devel依赖--with-http_stub_status_module基本状态信息显示 查看请求数、连接数等--with-http_realip_module定义客户端地址和端口为header头信息 常用于反向代理后的真实IP获取
###2.3、目录介绍
查看安装目录/usr/local/nginx
目录作用conf配置文件html网站默认目录logs日志sbin可执行文件 [软件的启动 停止 重启等]
###2.4、软件操作参数
查看nginx的二进制可执行文件的相关参数
shell cd /usr/local/nginx/sbin
shell ./nginx -h
执行后显示
nginx version: nginx/1.14.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]Options:
#查看帮助-?,-h : this help
#查看版本并退出-v : show version and exit
#查看版本和配置选项并退出-V : show version and configure options then exit
#检测配置文件语法并退出-t : test configuration and exit
#检测配置文件语法打印它并退出-T : test configuration, dump it and exit
#在配置测试期间禁止显示非错误信息-q : suppress non-error messages during configuration testing
#发送信号给主进程 stop强制退出 quit优雅的退出 reopen重开日志 reload重载配置-s signal : send signal to a master process: stop, quit, reopen, reload
#设置nginx目录 $prefix路径-p prefix : set prefix path (default: /usr/local/nginx/)
#指定启动使用的配置文件-c filename : set configuration file (default: conf/nginx.conf)
#在配置文件之外设置全局指令-g directives : set global directives out of configuration file 一般主要使用 -s参数控制管理nginx服务 -V参数查看nginx开启的模块和编译参数 -t参数检测配置文件是否有错误 2.5、服务配置
①使用社区的服务配置文件
nginx编译包里默认没有服务启动脚本模板可以通过社区获得
Red Hat NGINX Init Script | NGINX
上传脚本到/etc/init.d目录下
shell vim /etc/init.d/nginx
修改软件和配置路径
#执行文件路径 第22行
nginx/usr/local/nginx/sbin/nginx
#配置文件路径 第25行
NGINIX_CONF_FILE/usr/local/nginx/conf/nginx.conf
②添加自启动
shell chmod x /etc/init.d/nginx
shell chkconfig --add nginx
shell chkconfig nginx on
注意在服务脚本中有chkconfig配置开启模式、开启顺序、关闭顺序设置
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
# 开启模式(0-6) 开启顺序 关闭顺序
# chkconfig: - 85 15
3、PHP
3.1、介绍 PHP外文名:PHP: Hypertext Preprocessor中文名“超文本预处理器”是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点利于学习使用广泛主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比PHP是将程序嵌入到HTML标准通用标记语言下的一个应用文档中去执行执行效率比完全生成HTML标记的CGI要高许多PHP还可以执行编译后代码编译可以达到加密和优化代码运行使代码运行更快。 PHP-FPM(FastCGI Process ManagerFastCGI进程管理器)对于PHP 5.3.3之前的php来说是一个补丁包 旨在将FastCGI进程管理整合进PHP包中。 相对Spawn-FCGIPHP-FPM在CPU和内存方面的控制都更胜一筹而且前者很容易崩溃必须用crontab定时进行监控而PHP-FPM则没有这种烦恼。 PHP5.3.3已经集成php-fpm了不再是第三方的包了。PHP-FPM提供了更好的PHP进程管理方式可以有效控制内存和进程、可以平滑重载PHP配置比spawn-fcgi具有更多优点所以被PHP官方收录了。在./configure的时候带 –enable-fpm参数即可开启PHP-FPM。 页面分类
静态页面 一般普通访问到的页面
动态页面 用户可以和服务器进行交互页面
执行动态页面需要和服务器进行交互使用后端语言进行开发
LNMP 使用php进行开发交互 LAMP和LNMP在使用和配置PHP的区别 3.2、安装
解压进入目录
shell tar zxf php-7.2.12.tar.gz
shell cd php-7.2.12
编译参数配置
shell ./configure --prefix/usr/local/php --with-config-file-path/usr/local/php/etc --enable-fpm --with-fpm-userwww --with-fpm-groupwww --with-mysqlimysqlnd --with-pdo-mysqlmysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts --with 代表需要手动开启 可能需要加载第三方模块 第三方模块没有就会error --enable 代表开启php的默认功能 --without 关闭默认加载的模块 解决遇到的依赖软件问题 shell yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
编译并安装到目录
shell make make install
查看PHP的安装目录
shell cd /usr/local/php
shell ls
目录名称作用binphp相关命令目录 php phpize、php-config在源码编译扩展时用etc配置文件目录includephp默认类库libphp第三方扩展类库phpman文档文件sbinphp-fpm执行文件varlog日志目录 run运行目录 保存pid文件
3.3、配置 使用php-fpm进行管理php服务有两个配置文件 ①php.ini #默认php配置文件 ②php-fpm.conf #php-fpm相关的配置 复制配置文件
shell cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
shell cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
shell cp /root/soft/php-7.2.12/php.ini-development /usr/local/php/etc/php.ini
添加启动服务
shell cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
shell chmod x /etc/init.d/php-fpm
shell chkconfig --add php-fpm
添加环境变量方便php、phpize、phpconfig查找使用
shell echo PATH/usr/local/php/bin:$PATH /etc/profile
shell source /etc/profile
php安装脚本及其初始化配置
以下脚本作为编译安装和配置php的参考
#!/bin/bash
php_install(){
#php编译安装
#和nginx使用相同的用户,如果没有就创建
id www /dev/null
[ $? -ne 0 ] useradd -s /sbin/nologin -M www
#解决依赖
yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel openssl-devel
#解压
tar xvf php-7.2.12.tar.gz
cd php-7.2.12
#编译安装php
./configure --prefix/usr/local/php --with-config-file-path/usr/local/php/etc --enable-fpm --with-fpm-userwww --with-fpm-groupwww --with-mysqlimysqlnd --with-pdo-mysqlmysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --with-libzip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts make make install
#配置文件初始化
cp php.ini-development /usr/local/php/etc/php.ini
#php-fpm服务配置文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
#php-fpm服务子配置文件
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#配置服务及其环境变量
cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod x /etc/init.d/php-fpm
service php-fpm start
chkconfig --add php-fpm
echo PATH/usr/local/php/bin:$PATH /etc/profile
}
#脚本开始时间
start_timedate %s
#执行的脚本代码
php_install
#脚本结束时间
end_timedate %s
#脚本执行花费时间
const_time$((end_time-start_time))
echo Take time is: $const_times
3.4、Nginxphp-fpm配置
①编写测试文件
shell vim /usr/local/nginx/html/index.php
文件内容
?phpphpinfo();
②在nginx.conf中配置
修改配置文件告知nginx如果接收到.php结尾的请求交由给php-fpm进行处理
shell vim /usr/local/nginx/conf/nginx.conf
打开location .php 结尾那一段注释并修改script为$document_root
#1、把root变量提升上层
root html;location / {#root html;index index.html index.htm;}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location /50x.html {root html;}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {#2、默认使用上层的root变量# root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;#3、把script修改为$document_root $document_root 就是上面的rootfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}