邢栋博客
邢栋博客,Action博客,记录工作和生活中的点点滴滴
关于nginx启动、停止、重启命令总结
标签:
nginx
nginx启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx停止
1.从容停止
ps aux|grep nginx //master进程号,例如是 1480
kill -QUIT 1480
2.快速停止
kill -TERM 1480 或 kill INT 1480
3.强制停止
pkill -9 nginx 或 killall nginx
nginx重启
检测配置文件是否正确
nginx -t
然后
nginx -s reload 或者 kill -HUP 1480
linux下通过postfix发送邮件以及shell监控报警脚本
postfix安装
首先查看本机有没有安装 sendmail
rpm -qa|grep sendmail 或者 alternatives --display mta
如果存在则删除或者停止
yum remove sendmail
安装postfix
yum -y install postfix*
vim /etc/postfix/main.cf
修改
myhostname = mail.flycoder.cn
mydomain = flycoder.cn
myorigin = $mydomain
inet_protocols = ipv4
启动服务
service postfix restart
chkconfig postfix on
alternatives --set mta /usr/sbin/sendmail.postfix 或者 alternatives --config mta 选择对应的/usr/sbin/sendmail.postfix
测试邮件
echo 'Hello world!' | mail -s 'Test Email' youremail@domain.com
监控脚本
nginx监控脚本,php mysql redis和此类似
vim nginx.sh
#!/bin/bash
#nginx.sh
nc -w2 localhost 80
if [ $? -ne 0 ]
then
echo 'Nginx is down' | mail -s 'Nginx is down' youremail@domain.com
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
fi
disk监控脚本
vim dish.sh
#!/bin/bash
#disk.sh awk后面的具体跟随自身服务器显示的内容来写
num=`df |awk 'NR==2{print int($5)}'`
if [ $num -gt 80 ]
then
echo "disk space is ${num}%" | mail -s 'disk space > 80' youremail@domain.com
fi
首先查看本机有没有安装 sendmail
rpm -qa|grep sendmail 或者 alternatives --display mta
如果存在则删除或者停止
yum remove sendmail
安装postfix
yum -y install postfix*
vim /etc/postfix/main.cf
修改
myhostname = mail.flycoder.cn
mydomain = flycoder.cn
myorigin = $mydomain
inet_protocols = ipv4
启动服务
service postfix restart
chkconfig postfix on
alternatives --set mta /usr/sbin/sendmail.postfix 或者 alternatives --config mta 选择对应的/usr/sbin/sendmail.postfix
测试邮件
echo 'Hello world!' | mail -s 'Test Email' youremail@domain.com
监控脚本
nginx监控脚本,php mysql redis和此类似
vim nginx.sh
#!/bin/bash
#nginx.sh
nc -w2 localhost 80
if [ $? -ne 0 ]
then
echo 'Nginx is down' | mail -s 'Nginx is down' youremail@domain.com
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
fi
disk监控脚本
vim dish.sh
#!/bin/bash
#disk.sh awk后面的具体跟随自身服务器显示的内容来写
num=`df |awk 'NR==2{print int($5)}'`
if [ $num -gt 80 ]
then
echo "disk space is ${num}%" | mail -s 'disk space > 80' youremail@domain.com
fi
php设计模式之策略模式简单事例
<?php //策略模式 interface OutputInterface { public function load($arrayOfData); } class SerializedArrayOutput implements OutputInterface { public function load($arrayOfData) { return serialize($arrayOfData); } } class JsonStringOutput implements OutputInterface { public function load($arrayOfData) { return json_encode($arrayOfData); } } class ArrayOutput implements OutputInterface { public function load($arrayOfData) { return $arrayOfData; } } class SomeClient { private $output; public function setOutput(OutputInterface $outputType) { $this->output = $outputType; } public function loadOutput($arrayOfData) { return $this->output->load($arrayOfData); } } $client = new SomeClient(); $arrayOfData = array('name'=>'action','age'=>'28'); // Want an array? $client->setOutput(new ArrayOutput()); $data = $client->loadOutput($arrayOfData); var_dump($data); echo "<hr>"; // Want some JSON? $client->setOutput(new JsonStringOutput()); $data = $client->loadOutput($arrayOfData); var_dump($data); echo "<hr>"; // Want some Serialized? $client->setOutput(new SerializedArrayOutput()); $data = $client->loadOutput($arrayOfData); var_dump($data);
php设计模式之单例模式简单事例
<?php //单例模式 class Singleton { /** * @var 这个类的"单例" */ private static $instance; /** * 防止在这个类之外new这个类 */ private function __construct() { } /** * @return 返回这个类的单例 */ public static function getInstance() { if(self::$instance === null){ self::$instance == new self(); } return self::$instance; } /** * @return void 把 clone 方法声明为 private,防止克隆单例 */ private function __clone() { } /** * @return void 把反序列化方法声明为 private,防止反序列化单例 */ private function __wakeup() { } } class SingletonChild extends Singleton { } $obj = Singleton::getInstance(); var_dump($obj === Singleton::getInstance()); // bool(true) $anotherObj = SingletonChild::getInstance(); var_dump($anotherObj === Singleton::getInstance()); // bool(true) var_dump($anotherObj === SingletonChild::getInstance()); // bool(true) ?>
单例模式是非常有用的,特别是我们需要确保在整个请求的声明周期内只有一个实例存在。 典型的应用场景是,当我们有一个全局的对象(比如配置类)或一个共享的资源(比如事件队列)时。
php设计模式之工厂模式简单事例
<?php //工厂模式 class Automobile { private $vehicleMake; private $vehicleModle; public function __construct($make,$model) { $this->vehicleMake = $make; $this->vehicleModle = $model; } public function getMakeAndModel() { return $this->vehicleMake.' '.$this->vehicleModle; } } class AutomobileFactory { public static function create($make,$model) { return new Automobile($make,$model); } } $veyron = AutomobileFactory::create('Bugatti','Veyron'); print_r($veyron->getMakeAndModel()); ?>
上面的代码用来一个工厂来创建 Automobile 对象。用这种方式创建对象有两个好处: 首先,如果你后续需要更改,重命名或替换 Automobile 类,你只需要更改工厂类中的代码,而不是在每一个用到 Automobile 类的地方修改; 其次,如果创建对象的过程很复杂,你也只需要在工厂类中写,而不是在每个创建实例的地方重复地写。
shell脚本下执行sql语句
标签:
shell
vim mysql.sh
#!/bin/bash
host='127.0.0.1'user='root'
passwd='root'
dbname='test'
test_sql='select count(*) from test'
num=$(mysql -s -h$host -u$user -p$passwd $dbname -e "$test_sql")
echo $num
php-fpm重启、启动、停止命令
启动php-fpm:
/usr/local/php/sbin/php-fpm
php-fpm需要使用信号控制,master进程可以理解以下信号
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
重启方法1
先查看php-fpm的master进程号
ps aux|grep php-fpm
然后
kill -USR2 进程号
重启方法2
cat /usr/local/php/etc/php-fpm.conf
找到对应的php-fpm.pid
kill -USR2 'cat /usr/local/php/var/run/php-fpm.pid'
关闭
kill INT 'cat /usr/local/php/var/run/php-fpm.pid'
/usr/local/php/sbin/php-fpm
php-fpm需要使用信号控制,master进程可以理解以下信号
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
重启方法1
先查看php-fpm的master进程号
ps aux|grep php-fpm
然后
kill -USR2 进程号
重启方法2
cat /usr/local/php/etc/php-fpm.conf
找到对应的php-fpm.pid
kill -USR2 'cat /usr/local/php/var/run/php-fpm.pid'
关闭
kill INT 'cat /usr/local/php/var/run/php-fpm.pid'
使用shell脚本每秒执行一次php程序
标签:
shell
vim test.sh
#!/bin/bash
step=1 #间隔的秒数,不能大于60for (( i = 0; i < 60; i=(i+step) )); do
$(/work/software/php/bin/php '/work/www/live/test.php')
sleep $step
done
exit 0