nginx升级
[root@localhost ~]# nginx -V //-v查看参数
nginx version: nginx/1.12.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
备份旧的版本
[root@localhost sbin]# cp nginx{,-old}
[root@localhost sbin]# ls
nginx nginx-old
重新编译
[root@localhost nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=../echo-nginx-module-master
[root@localhost nginx-1.12.0]# make
覆盖旧版本
[root@localhost objs]# nginx -s stop
[root@localhost objs]# cp nginx /usr/local/nginx/sbin/
cp:是否覆盖"/usr/local/nginx/sbin/nginx"? y
启动nginx
[root@localhost objs]# nginx
location
直接接路径,以指定模式开始
location /abc {
echo 'haha';
}
可以匹配的内容
[root@localhost ~]# curl 192.168.39.133:/abc
haha
[root@localhost ~]# curl 192.168.39.133:/abcdefdsfd
haha
[root@localhost ~]# curl 192.168.39.133:/abc/
haha
精确匹配
location = /abc {
echo 'haha'
}
可以匹配的内容
[root@localhost ~]# curl 192.168.39.133:/abc
haha
[root@localhost ~]# curl 192.168.39.133:/abc?p1=11\&2=22
haha
不能匹配的内容
[root@localhost ~]# curl 192.168.39.133:/abcd
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.0</center>
</body>
</html>
区分大小写
location ~ ^/abc$ {
echo 'haha';
}
可以匹配的内容
[root@localhost ~]# curl 192.168.39.133:/abc
haha
[root@localhost ~]# curl 192.168.39.133:/abc?p1=11\&2=22
haha
不能匹配的内容
[root@localhost ~]# curl 192.168.39.133:/abc/
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.0</center>
</body>
</html>
[root@localhost ~]# curl 192.168.39.133:/ABC
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.0</center>
</body>
</html>
不区分大小写
location ~* ^/abc$ {
echo 'haha';
}
可以匹配
[root@localhost ~]# curl 192.168.39.133:/abc
haha
[root@localhost ~]# curl 192.168.39.133:/ABC
haha
[root@localhost ~]# curl 192.168.39.133:/Abc
haha
不能匹配
[root@localhost ~]# curl 192.168.39.133:/abc/
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.0</center>
</body>
</html>
[root@localhost ~]# curl 192.168.39.133:/abcde
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.0</center>
</body>
</html>
zabbix
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz
[root@localhost src]# tar xf zabbix-4.0.3.tar.gz
[root@localhost ~]# groupadd -r zabbix
[root@localhost ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
//配置zabbix数据库
[root@localhost mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.29 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
[root@localhost ~]# cd /usr/src/zabbix-4.0.3/database/mysql/
[root@localhost mysql]# ls
data.sql images.sql schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
//编译安装zabbix
[root@localhost ~]# cd /usr/src/zabbix-4.0.3
[root@localhost zabbix-4.0.3]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
[root@localhost zabbix-4.0.3]# make install
[root@localhost ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
//修改服务端配置文件
//设置数据库信息
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
....
DBPassword=zabbix123! //设置zabbix数据库连接密码
//启动zabbix_server和zabbix_agentd
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost ~]# cd /usr/src/zabbix-4.0.3
[root@localhost zabbix-4.0.3]# ls
aclocal.m4 ChangeLog config.log configure.ac frontends m4 man README
AUTHORS compile config.status COPYING include Makefile misc sass
bin conf config.sub database INSTALL Makefile.am missing src
build config.guess configure depcomp install-sh Makefile.in NEWS
[root@localhost zabbix-4.0.3]# mkdir /usr/local/nginx/html/zabbix
[root@localhost zabbix-4.0.3]# cp -a frontends/php/* /usr/local/nginx/html/zabbix
[root@localhost zabbix-4.0.3]# chown -R nginx.nginx /usr/local/nginx/html/zabbix
配置nginx的配置文件
[root@localhost ~]# cd /usr/local/nginx/conf/
[root@localhost conf]# vim nginx.conf
server {
listen 80;
server_name zabbix.wangqing.com;
location / {
root html/zabbix;
index zabbix.php index.html;
}
location ~ \.php$ {
root html/zabbix;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index zabbix.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
设置目录的权限
[root@localhost conf]# pwd
/usr/local/nginx/html/zabbix/conf
[root@localhost conf]#
[root@localhost conf]# chmod 777 /usr/local/nginx/html/zabbix/conf
status配置
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
location /status {
stub_status on;
}
[root@localhost ~]# nginx -s reload
zabbix配置
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# cat accepts.sh
#!/binbash
accepts=$(curl http://192.168.90.128/status 2>/dev/null|awk 'NR==3{print $1}')
echo "$accepts"
[root@localhost scripts]# cat requests.sh
#!/bin/bash
requests=$(curl http://192.168.90.128/status 2>/dev/null|awk 'NR==3{print $3}')
echo "$requests"
[root@localhost ~]# ll /scripts/
总用量 8
-rwxr-xr-x. 1 zabbix zabbix 108 1月 2 10:11 accepts.sh
-rwxr-xr-x. 1 zabbix zabbix 111 1月 2 10:10 requests.sh
[root@localhost ~]# ll /scripts/ -d
drwxr-xr-x. 2 zabbix zabbix 43 1月 2 11:44 /scripts/
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=check_accepts, /bin/bash /scripts/accepts.sh
UserParameter=check_requests, /bin/bash /scripts/requests.sh
rewrite
语法:rewrite regex replacement flag;
实例:
原本网页
[root@localhost ~]#vim conf/nginx.conf
location /images {
root html;
}
跳转到别的网页写法
[root@localhost ~]# vim conf/nginx.conf
location /imgs {
rewrite ^/imgs/(.*\.*)$ http://www.baidu.com break;
}
[root@localhost ~]# nginx -s reload
用的域名不同,但是跳转的网页还是相同的
[root@localhost ~]#vim conf/nginx.conf
location /images {
root html;
}
location /imgs {
rewrite ^/imgs/(.*\.*)$ /images/$1 break;
}
[root@localhost ~]# nginx -s reload