使用方法:解压后,其中包含“123.vbs”“批量打开网页.htm”“网页批量打开工具(OpenPage)V6.0.exe”。第一个是将iis中的站点域名全部导出为txt文本格式,第二个是网页版的打开方式,第三个是先安装再使用。
批量查站:点此下载
使用方法:解压后,其中包含“123.vbs”“批量打开网页.htm”“网页批量打开工具(OpenPage)V6.0.exe”。第一个是将iis中的站点域名全部导出为txt文本格式,第二个是网页版的打开方式,第三个是先安装再使用。
批量查站:点此下载
一般负载均衡内容有两种形式,一种是静态,另一种是动态,动态网站内容就可能需要进行交互,那么就涉及到session共享的问题。默认PHP是将session存储在LocalDisk,如果是多台php主机之间进行负载,那么该如何共享session?今天我们就解决这个问题。
session会话共享文件有很多种方式:
分布式文件共享;NFS,NAS文件存储等。
Nginx负载均衡ip_hash模块,固定访客到后端某台服务器。
将session存储到数据库中;例如MySQL,Memcached,Redis,Mongodb等。
我个人比较倾向于将session存储到Redis数据库,用这种方式来同步session共享,不仅不会加大数据库的负担,而且安全性比cookie更高,把session放到内存里面,比从磁盘文件中读取会快很多。“有人认为;那我把所有的缓存软件都安装,速度岂不是更快,那就不是缓存加速了,而演变成了缓存库了”。
php语言脚本默认不支持对Redis的操作,所以需要安装第三方phpRedis扩展模块,让其支持对Redis的操作,至于如何安装使用phpRedis,可以参考我前面写的文章《phpRedis扩展模块安装配置使用》。此外这里还需要一台Redis服务器,请参阅《Linux Centos7 Redis 3.2.9 源码编译安装配置》。
1.修改PHP配置文件php.ini将session存储到Redis中。
# vim /usr/local/php/etc/php.ini session.save_handler = files ;session.save_path = "N;/path"修改为:
session.save_handler = Redis session.save_path = “tcp://10.10.204.66:6379” ;如果Redis有密码连接方式 session.save_path = “tcp://10.10.204.66:6379?auth=password”
2.重启php-fpm服务生效
# systemctl restart php-fpm
以上所有过程均是经过手工测试的,99%可用于生产。
最近做Nginx负载均衡配置,由于我们是交互性网站,必须用到session,尝试了多种方案,最后选择了Redis做为数据库缓存服务器。
Redis官方简介
Redis是一个开源(BSD许可),内存数据结构存储,用作数据库,缓存和消息代理。它支持的数据结构,例如字符串,散列,列表,集合,具有范围查询的排序集,位图,超文本和具有半径查询的地理空间索引。Redis内置复制,Lua脚本,LRU驱逐,事务和不同级别的磁盘持久性,并通过Redis Sentinel提供高可用性,并通过Redis Cluster进行自动分区。
进入正题,无论是物理或虚拟化服务器,Redis安装方法都没有区别,接下来我就开始安装操作。
实验OS:CentOS Linux release 7.3.1611 (Core) x64
1.先决扩展条件
安装扩展包以及依赖包 # yum install epel-release -y # yum install gcc gcc-c++ jemalloc-devel
2.Redis安装
下载解压 将其移动到/usr/local目录,创建目录以及用户和组,并给予目录权限,最后创建软连接。
# wget //download.redis.io/releases/redis-4.0.1.tar.gz # tar zxvf redis-4.0.1.tar.gz # mv redis-4.0.1 /usr/local/ # cd /usr/local/ # mkdir -p /usr/local/redis-4.0.1/logs # mkdir -p /usr/local/redis-4.0.1/rdb # groupadd redis # useradd -g redis -s /sbin/nologin redis # chown -R redis:redis /usr/local/redis-4.0.1/logs # chown -R redis:redis /usr/local/redis-4.0.1/rdb # chown redis:redis /usr/local/redis-4.0.1/redis.conf # make && make install # ln -s redis-4.0.1 redis
3.配置文件
生产环境中以下信息是必须修改的,所以可以根据自己的需求进行修改 /usr/local/redis-4.0.1/redis.conf 此文件
port 6379 #监听端口,默认是6379 daemonize yes #如果需要在后台运行,把该项改为yes requirepass foobared #去掉前边#注释,修改foobared为你想配置的任意密码 bind 10.10.204.65 #默认bind的填写127.0.0.1这样配置是只允许本地访问,想远程访问就改本机网卡配置的ip地址。多个IP 请使用空格隔开 pidfile /usr/local/redis/logs/redis.pid logfile "/usr/local/redis/logs/redis.log" #设置日志文件路径 dir /usr/local/redis-4.0.1/rdb #持久化文件存储路径 supervised systemd #默认为no,由于我们正在运行一个使用systemd init系统的操作系统,所以我们可以将其更改为systemd除了上述几个设置外,还有其他的等一些参数,有需要可以按照配置文件的说明修改。
4.测试redis启动
# /usr/local/redis/src/redis-server /usr/local/redis/redis.conf ... WARNING The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.可以看到存在3条启动警告信息:
第一个错误和第二个错误可以同时解决,第一个错误大概是说somaxconn的值128设置过小,此值受限于系统的somaxconn与tcp_max_syn_backlog这两个值,所以应该把这两个内核参数值调大,第二个错误是过量使用内存设置为0!在低内存环境下,后台保存可能失败。请在/etc/sysctl.conf 添加一项 ‘vm.overcommit_memory = 1′ ,然后重启(或者运行命令’sysctl vm.overcommit_memory=1’ )使其生效。
# vim /etc/sysctl.confnet.core.somaxconn = 20480 #最大队列长度,应付突发的大并发连接请求,默认为128 net.ipv4.tcp_max_syn_backlog = 20480 #半连接队列长度,此值受限于内存大小,默认为1024 vm.overcommit_memory = 1 #过量使用内存设置为0!# sysctl -p第三个警告错误是需要关闭Linux (THP) 透明内存
# vim /etc/rc.local echo never > /sys/kernel/mm/transparent_hugepage/enabled #在开机脚本里追加此命令至此3个错误已经解决,再次启动的时候就不会报警告信息。
5.创建一个Redis系统单元文件
# vim /usr/lib/systemd/system/redis.service[Unit] Description=Redis persistent key-value database After=network.target [Service] User=redis Group=redis ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf --daemonize no ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown Restart=always [Install] WantedBy=multi-user.target
6.启动redis并加入开机启动
# systemctl daemon-reload # systemctl start redis.service # systemctl enable redis.service
7.查看是否启动
# ps -A | grep redis 6167 ? 00:00:00 redis-server
8.加入防火墙
# firewall-cmd --zone=public --add-port=6379/tcp --permanent # firewall-cmd --reload # firewall-cmd --zone=public --list-ports
9.测试连接成功
# redis-cli 127.0.0.1:6379>
到目前为止redis已经完成安装,其实生产环境的安装也是如此,只不过需求不同,redis.conf中的修改内容不同。
phpRedis是什么?phpredis扩展提供了一个用于与Redis键值存储进行通信的API,如果需要使用Redis相关函数就必须安装phpRedis扩展包。看起来很复杂,其实动手操作真没那么难。
环境:
CentOS Linux release 7.3.1611 (Core) x64
Redis server v=3.2.9 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=37db043e44b54a88
1.下载phpRedis扩展并解压,下载地址:
//pecl.php.net/package/redis # cd /tmp # wget //github.com/phpredis/phpredis/archive/develop.zip# unzip develop.zip # cd phpredis-develop/
2.接下来在phpredis-develop目录编译phpize扩展工具,主要作用就是在phpredis-develop目录生成configure文件。
# /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 # ./configure --with-php-config=/usr/local/php/ # make && make install ... Build complete. Don't forget to run 'make test'. Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20160303/最后一行就是编译生成的Redis动态库路径:/usr/local/php/lib/php/extensions/no-debug-zts-20160303/
3.修改php.ini在该文件的底部加上Redis.so路径,之后重启nginx/php-fpm服务生效。
# vim /usr/local/php/etc/php.ini extension="/usr/local/php/lib/php/extensions/no-debug-zts-20160303/redis.so" # systemctl restart nginx # systemctl restart php-fpm
4.是否安装phpRedis成功,可以通过PHP探针进行测试。
<?phpinfo();?>将上述代码保存为phpinfo.php上传到网站根目录进行访问,可查看Redis&Session扩展模块的支持。
redis
Redis Support enabledRedis Version 3.1.2
Available serializers php
session
Session Support enabledRegistered save handlers files user redis rediscluster
Registered serializer handlers php_serialize php php_binary
至此phpRedis的安装配置已经完成,希望对你有帮助。
仅供研究 点此下载
仅供用于学习,点此下载
今天在节点机器上新安装的Zabbix Agent无法启动。
1.查看Zabbix Agent日志文件才究其原因。
# cat /var/log/zabbix/zabbix_agentd.log 63133:20170601:092700.920 ************************** 63133:20170601:092700.920 using configuration file: /etc/zabbix/zabbix_agentd.conf 63133:20170601:092700.920 cannot set resource limit: [13] Permission denied 63133:20170601:092700.920 cannot disable core dump, exiting... 63137:20170601:092711.171 Starting Zabbix Agent [cong171163]. Zabbix 3.2.6 (revision 67849). 63137:20170601:092711.171 **** Enabled features **** 63137:20170601:092711.171 IPv6 support: YES 63137:20170601:092711.171 TLS support: YES 63137:20170601:092711.171 ************************** ......
2.此时只需要关闭Selinux,两种方案;
2.1.临时关闭
# setenforce 0
2.2.永久关闭(reboot host)
# vim /etc/selinux/config SELINUX=enforcing
改
SELINUX=disabled
3.操作完成后,再次启动zabbix-agent服务
# systemctl start zabbix-agent.service
4.查看端口
# ss -tnl 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 80 :::3306 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::10050 :::*
zabbix agent启动成功,10050端口已经运行。
zabbix对中文的支持不是很好,但为了管理方面有时候我们还是会选择中文,在zabbix监控的web界面,图形图标下面的中文会显示一个个小方块,这样是不正确的,需要下载字体。例如“微软雅黑”
“微软雅黑.ttf” 命名为 “msyh.ttf”
将下载的字体上传到/zabbix/fonts/字体下
修改/zabbix/include/defines.inc.php文件中的两处
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); define('ZBX_FONT_NAME', 'DejaVuSans');
改
define('ZBX_GRAPH_FONT_NAME', 'msyh'); define('ZBX_FONT_NAME', 'msyh');
最后重启web服务器即可。
打开数据库在查询语句中插入下面代码,就可以精确查询到哪个库占用CPU资源。
查询分析器运行:
sp_who active
操作系统:CentOS Linux release 7.3.1611 (Core)
数据库:MariaDB-10.2.6-linux-glibc_214-x86_64
MaxScale服务器:10.200.10.55
主服务器:172.16.8.56
从服务器:172.16.8.57
从服务器:172.16.8.58
1.maxscale的安装方式有很多,例如源码安装、rpm、二进制构建等,我选择二进制进行安装。
根据场景需要下载相对应的版本,下载地址;//mariadb.com/downloads/maxscale
[root@localhost ~]# groupadd maxscale [root@localhost ~]# useradd -g maxscale maxscale [root@localhost ~]# cd /usr/local [root@localhost local]# wget //downloads.mariadb.com/MaxScale/2.1.3/centos/7server/x86_64/maxscale-2.1.3.centos.7.tar.gz [root@localhost local]# tar zxvf maxscale-2.1.3.centos.7.tar.gz [root@localhost local]# ln -s maxscale-2.1.3.centos.7 maxscale [root@localhost local]# cd maxscale [root@zhu56 maxscale]# chown -R maxscale var
建议创建软连接,这样有助于以后的版本升级及后期维护。
2.首次安装maxscale需要创建日志相关目录
[root@localhost ~]# mkdir /var/log/maxscale [root@localhost ~]# mkdir /var/lib/maxscale [root@localhost ~]# mkdir /var/run/maxscale [root@localhost ~]# mkdir /var/cache/maxscale
3.以下目录必须具备maxscala用户权限
[root@localhost ~]# chown maxscale /var/log/maxscale [root@localhost ~]# chown maxscale /var/lib/maxscale [root@localhost ~]# chown maxscale /var/run/maxscale [root@localhost ~]# chown maxscale /var/cache/maxscale
4.为了能让Maxscale能顺利启动,还需要创建配置文件,在Maxscale目录下有配置文件模板拷贝到etc下即可。
[root@localhost ~]# cp /usr/local/maxscale/etc/maxscale.cnf.template /etc/maxscale.cnf
5.在修改配置文件之前,需要在主服务器上创建一个用户并给予授权,而这个用户用于MySQL监控、路由功能
MariaDB [(none)]> create user 'jiankongdb'@'%' identified by 'jiankong123'; MariaDB [(none)]> grant SELECT on mysql.user to 'jiankongdb'@'%'; MariaDB [(none)]> GRANT SELECT ON mysql.db TO 'jiankongdb'@'%'; MariaDB [(none)]> GRANT SELECT ON mysql.tables_priv TO 'jiankongdb'@'%'; MariaDB [(none)]> GRANT SHOW DATABASES ON *.* TO 'jiankongdb'@'%'; MariaDB [(none)]> grant REPLICATION CLIENT on *.* to 'jiankongdb'@'%'; MariaDB [(none)]> GRANT replication slave, replication client,SELECT ON *.* TO jiankongdb@'%';
6.查看授权情况
MariaDB [(none)]> SHOW GRANTS FOR'jiankong'@'%';
7.接下来就开始修改maxscale.cnf配置文件,否则无法启动。
[root@localhost ~]# vim /etc/maxscale.cnf # MaxScale documentation on GitHub: # //github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Documentation-Contents.md # Global parameters # # Complete list of configuration options: # //github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Getting-Started/Configuration-Guide.md #全局配置 [maxscale] threads=1 # Server definitions # # Set the address of the server to the network # address of a MySQL server. # [server1] type=server address=172.16.8.56 port=3306 protocol=MySQLBackend serv_weight=1 [server2] type=server address=172.16.8.57 port=3306 protocol=MySQLBackend serv_weight=3 [server3] type=server address=172.16.8.58 port=3306 protocol=MySQLBackend serv_weight=3 # Monitor for the servers # # This will keep MaxScale aware of the state of the servers. # MySQL Monitor documentation: # //github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Monitors/MySQL-Monitor.md #MariaDB状态监控 [MySQL Monitor] type=monitor module=mysqlmon servers=server1,server2,server3 user=jiankong passwd=jiankong123 monitor_interval=10000 detect_stale_master=true #即使从全挂掉,保证主担任读写 # Service definitions # # Service Definition for a read-only service and # a read/write splitting service. # # ReadConnRoute documentation: # //github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadConnRoute.md #读 [Read-Only Service] type=service router=readconnroute servers=server1,server2,server3 user=jiankong passwd=jiankong123 router_options=slave enable_root_user=1 #允许root用户登录执行 weightby=serv_weight #主从权重 # ReadWriteSplit documentation: # //github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadWriteSplit.md #写 [Read-Write Service] type=service router=readwritesplit servers=server1,server2,server3 user=jiankong passwd=jiankong123 max_slave_connections=100% use_sql_variables_in=master #保证会话的一致性 enable_root_user=1 #允许root登录 max_slave_replication_lag=3600 #允许从超出主的同步时间,超出则不路由 # This service enables the use of the MaxAdmin interface # MaxScale administration guide: # //github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Reference/MaxAdmin.md [MaxAdmin Service] type=service router=cli # Listener definitions for the services # # These listeners represent the ports the # services will listen on. # [Read-Only Listener] type=listener service=Read-Only Service protocol=MySQLClient port=4008 [Read-Write Listener] type=listener service=Read-Write Service protocol=MySQLClient port=4006 [MaxAdmin Listener] type=listener service=MaxAdmin Service protocol=maxscaled socket=default
保存并退出。
8.下面创建启动脚本
[root@localhost ~]# cp /usr/local/maxscale-2.1.3.centos.7/share/maxscale.service /usr/lib/systemd/system/ [root@localhost ~]# vim /usr/lib/systemd/system/maxscale.service
9.修改maxscale.service中的ExecStart=///bin/maxscale为ExecStart=/usr/local/maxscale/bin/maxscale
[root@localhost ~]# chmod 755 /usr/lib/systemd/system/maxscale.service [root@localhost ~]# systemctl enable maxscale [root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl start maxscale
10.添加变量值
[root@localhost ~]# vi /etc/profile //最后一行添加以下内容保存退出! PATH=$PATH:/usr/local/maxscale/bin export PATH [root@localhost ~]# source /etc/profile //使其变量立即生效
11.接下来就可以使用MaxAdmin进行管理。MaxAdmin是一个简单的客户端管理界面,可用于与MariaDB MaxScale服务器进行交互,可以显示MariaDB MaxScale内部的统计信息状态以及对MariaDB MaxScale操作的控制。详情:
//mariadb.com/kb/en/mariadb-enterprise/maxadmin-admin-interface/
[root@localhost ~]# maxadmin //回车 MaxScale> list servers Servers. ---------------+--------------+-------+-------------+----------------- Server | Address | Port | Connections | Status ---------------+--------------+-------+-------------+----------------- server1 | 172.16.8.56 | 3306 | 0 | Master, Running server2 | 172.16.8.57 | 3306 | 0 | Slave, Running server2 | 172.16.8.58 | 3306 | 0 | Slave, Running ---------------+--------------+-------+-------------+-----------------
12.至此MaxScale已经配置完成。现在就可以使用客户端连接Maxscale服务器端 端口为4006。