nginx

nginx

系统监控
一 软件包安装
1.二进制:rpm和yum
cd /etc/yum-cron

改donwload_updates = yes 改为no
2.源码安装:
yum groupinstall '开发工具' -y 或者
yum install gcc-* glibc-* make cmake
get test.tar.gz
tar zxvf test.tar.gz -C /bao
cd /bao
./configure
make makeinstall
二 内存

从/proc/meminfo 里 --- free -m
从/proc/cpuinfo里拿信息
flags看到vmx 或svm 说明这台机器支持虚拟化功能
df 硬盘
top
vmstat
iostat
netstat -tunalp
sar

nginx服务
基于tcp协议,可靠传输。

systemctl start nginx
systemctl status nginx
systemctl stop firewalld 关防火墙
systemctl disable firewalld 开机也不启动防火墙
systemctl enable firewalld 开机启动
iptables -F

yum install epel-release nginx

磁盘IO 往磁盘写数据
网络IO

采用epoll模型效率高,处理速度快,抗并发
vim /etc/nginx/nginx.conf
/usr/local/nginx/nginx.conf
ser nginx;
worker_processes auto; ##工作进程(自动):自动查询机器上有几个CPU,有几个CPU开几个进程,一个进程(资源单位)中开多少线程(执行单位),
如果一个CPU同时跑多个进程,用的是多道技术
error_log /var/log/nginx/error.log; ##错误日志
pid /run/nginx.pid; ##PID文件

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; ##nginx模块

events {
worker_connections 1024; ##工作连接数目(一个进程中开多少线程)
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' ##定义日志格式
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main; ##访问日志路径,按照main的格式写的 远程地址(客户端地址),客户端用户,时间,请求,状态

sendfile on; ##优化参数 refer- :请求头,类似123链接,偷别的网站流量。
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf; ##包含的配置文件,可以自定义的

server {
listen 80 default_server; ##监听的默认80端口号
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html; ##网站(web服务)的根目录
或/usr/local/nginx/html
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
}


cd /usr/share/nginx/html 浏览器前端配置
vim index.html 可以自己写


url地址:统一资源定位符 http://IP:端口号
uri:统一地址标识符 http://IP:端口号/a/b/c.txt 客户端提交的请求路径
/usr/share/nginx/html/a/b/c.txt 客户端从服务器端下载的地址

第一段:http:// -----server端是基于http协议给client发数据
第二段:202.102.10.10:80 ---- 定位到全世界范围内唯一一款软件是谁
第三段:/a/b/c.txt ----- /------从软件的根开始算


mkdir -p /usr/share/nginx/html/a/b
echo 'welcome oldboy' > /usr/share/nginx/html/a/b/c.txt

systemctl reload nginx
客户端浏览器查看

http://192.168.16.147:80/a/b/c.txt ----nginx----nginx.conf----/usr/share/nginx/html/a/b/c.txt----http
location 匹配uri地址 读全局地址


server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html; ##软件的根,全局变量

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / { ##位置
root /var/www/html; 局部配置 主要通过这里找配置,没有的话再找全局的
index index.html index.htm index.a; ##默认资源
}


systemctl reload nginx 重新加载生效
mkdir -p /var/www/html
touch /var/www/html/index.html
echo '123' > /var/www/html/index.html
2正常
3开头请求重定向
4开头客户端没权限请求拒接
5开头服务器端出问题

正向代理和反向代理

正:知道自己想访问谁
反:找别人代理去做

lb(负载均衡)
调度算法:
1.round-robin 轮询
2.least-conneted 最小链接调度
3.ip-hash IP哈希 服务端基于客户端IP选择下次的请求
让同一IP一直保持在一台机器上,保证了会话保持
会话保持---- 可以专门拿一台机器保存用户登录信息(memcache)

nginx反向代理:
upstream管理机器
http{
upstream shuikong{
server srv1.example.com

}
server {
listen 80;

location / {
proxy_pass http://shuikong;
}
}
}


weight权重 weight=3加权 先连续访问3次web1

nfs 文件存储

npcbind(通信)+ nfs-utils
通过rpc协议(远程过程调用)

/etc/exports
/share 192.168.3.0/24(rw,sync,fsid=0)


开权限(nfs开启了w权限还不行,others还需要对/share目录有w权限)
chmod -R o+w /share

先为rpcbind和nfs做开机启动:
[root@MiWiFi-R3-srv nginx]# systemctl enable nfs-server.service
[root@MiWiFi-R3-srv nginx]# systemctl enable rpcbind.service

启动(必须先启动rpcbind服务)
[root@MiWiFi-R3-srv nginx]# systemctl start rpcbind.service
[root@MiWiFi-R3-srv nginx]# systemctl start nfs-server.service

块存储 没有文件系统,只提供硬盘
特点:客户端拿到可以自己格式化系统

对象存储:uri地址对应一个唯一的文件,
通过uri地址传上去 存在对象存储服务器上,一个整体不定哪里

文件存储; 好改格式


当前位置: > CentOS入门 > 系统配置 >
修改CentOS7系统默认运行级别
时间:2017-01-15 00:48来源:blog.csdn.net 作者:于车之 举报 点击:498次
CentOS系统有7个运行级别(runlevel)

运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动
运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆
运行级别2:多用户状态(没有NFS)
运行级别3:完全的多用户状态(有NFS),登陆后进入控制台命令行模式
运行级别4:系统未使用,保留
运行级别5:X11控制台,登陆后进入图形GUI模式
运行级别6:系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动

修改运行级别
Centos7中采用target概念来定义运行级别,分为3级、5级,含义如下:

3级->multi-user.target 文本
5级->graphical.target 图形
1)查看当前运行的级别

# runlevel
[root@chezhi chezhi]# runlevel
N 3
[root@chezhi chezhi]#
如果系统当前默认运行级别是图形GUI模式则runlevel 显示结果为: 5 3

2)修改开机默认运行级别

systemd使用链接来指向默认的运行级别,由/etc/systemd/system/default.target文件中决定。
切换到运行级3:
a. 先删除: mv /etc/systemd/system/default.target /etc/systemd/system/default.target_copy5 #将文件重命名即可
b. 创建软连接文件: ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
或者
ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target
再者也可以使用systemctl命令:
systemctl set-default graphical.target
systemctl isolate multi-user.target

最后正常关机并重启系统: init 6

然后系统开机就会自动进入控制台命令模式,如果想切换回默认进入图形GUI模式执行命令:

#先删除文件
[root@chezhi system]# rm -rf /etc/systemd/system/default.target
#重新创建软连接文件
[root@chezhi system]# ln -sf /lib/systemd/system/graphical.target
/etc/systemd/system/default.target


yum有问题,配置/etc/resolv.conf 增加DNS 8.8.8.8
重启网卡 systemctl restart network


/usr/local/nginx/sbin

--without-http-http_rewrite_module