Apache的三种MPM模式比较:prefork,worker,event
如何查看当前apache的工作模式prefork worker还是event模式?
知识图谱
相关文章
内存优化总结:ptmalloc、tcmalloc和jemalloc
支持的软件
Redis,默认使用jemalloc
Mysql
LD_PRELOAD=/usr/local/lib/libjemalloc.so@
MariaDB
LD_PRELOAD=/usr/local/lib/libjemalloc.so@
Jemalloc
LD_PRELOAD=/usr/local/lib/libjemalloc.so@
Nginx
--with-ld-opt='-ljemalloc'
Openrestry
--with-ld-opt='-ljemalloc -Wl,-u,pcre_version'
Tengine
--with-jemalloc
接手一个laravel项目,使用ftp上传报错如下
`ftp_rawlist(): php_connect_nonb() failed: Operation now in progress (115)`
原因配置文件中选项没有写全
'driver' => 'ftp',
'host' => '*******',
'port' => 21,
'username' => '*******',
'password' => '*******',
'passive' => false, //此选项需要加
'ignorePassiveAddress' => true, //此选项需要加
参考文章
How to fix `ftp_rawlist(): php_connect_nonb() failed: Operation now in progress (115)`
原理解析
有时间补充
报错如下
500 Illegal PORT command.
配置项改为true
'passive' => true,
计算机科学领域的任何问题都可以通过增加一个间接的中间层来解决,遗憾的是,这句经典的名言出处无从考证
参考文章
计算机科学领域的任何问题都可以通过增加一个间接的中间层来解决
现实例子
各种中间件,比如分库分表中间件
重启可以解决计算机系统99%的问题
现实例子
比如iphone系统卡死
运行在用户空间的应用软件,通过控制Linux内核netfilter模块,来管理网络数据包的处理和转发。iptables 支持内核2.4以上版本,旧版内核环境下则使用ipchains(于2.2版内核)或 ipwadm(于2.0版内核)完成类似的功能。2014年1月19日起发行的Linux内核3.13版则使用nftables取而代之,但仍然提供 iptables 命令做为兼容接口
CentOS 7.0默认使用的是firewall作为防火墙,启用iptable,
iptable需要先关闭firewall并禁止开启自启
service firewalld stop
systemctl disable firewalld.service #禁止firewall开机启动
#安装iptable
yum install iptables-services
service iptables start #开启
systemctl enable iptables.service #设置防火墙开机启动
应用场景
指令选项
iptables -L -F -A -D # list flush append delete
场景一
开放 tcp 10-22/80 端口 开放 icmp 其他未被允许的端口禁止访问
iptables -I INPUT -p tcp --dport 80 -j ACCEPT # 允许 tcp 80 端口
iptables -I INPUT -p tcp --dport 10:22 -j ACCEPT # 允许 tcp 10-22 端口
iptables -I INPUT -p icmp -j ACCEPT # 允许 icmp
iptables -A INPUT -j REJECT # 添加一条规则, 不允许所有
场景二
ftp: 默认被动模式(服务器产生随机端口告诉客户端, 客户端主动连接这个端口拉取数据) vsftpd: 使 ftp 支持主动模式(客户端产生随机端口通知服务器, 服务器主动连接这个端口发送数据)
iptables -I INPUT -i lo -j ACCEPT # 允许本机访问
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # 允许访问外网
iptables -I INPUT -p tcp --dport 80 -s 10.10.188.233 -j ACCEPT # 只允许固定ip访问80
场景三
允许外网访问: web http -> 80/tcp; https -> 443/tcp mail smtp -> 25/tcp; smtps -> 465/tcp pop3 -> 110/tcp; pop3s -> 995/tcp imap -> 143/tcp
iptables -I INPUT -i lo -j ACCEPT # 允许本机访问
iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # 允许访问外网
iptables -I INPUT -s 10.10.155.0/24 -j ACCEPT # 允许内网访问
iptables -I INPUT -p tcp -m multiport --dports 80,1723 -j ACCEPT # 允许端口, 80 -> http, 1723 -> vpn
iptables -A INPUT -j REJECT # 添加一条规则, 不允许所有
iptables-save # 保存设置到配置文件
场景四
nat 转发
iptables -t nat -L # 查看 nat 配置
iptables -t nat -A POST_ROUTING -s 10.10.177.0/24 -j SNAT --to 10.10.188.232 # SNAT
vi /etc/sysconfig/network # 配置网关
iptables -t nat -A POST_ROUTING -d 10.10.188.232 -p tcp --dport 80 -j DNAT --to 10.10.177.232:80 # DNAT
场景五
防CC攻击
iptables -I INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 100 -j REJECT # 限制并发连接访问数
iptables -I INPUT -m limit --limit 3/hour --limit-burst 10 -j ACCEPT # limit模块; --limit-burst 默认为5
相关文章
众所周知,在RHEL7系统中,firewalld防火墙取代了iptables防火墙。我们都知道iptables的防火墙策略是交由内核层面的netfilter网络过滤器来处理的,而firewalld则是交由内核层面的nftables包过滤框架来处理。
下面一张图,让大家明确的了解防火墙 Firewall 与 iptables 之间的关系与区别。
相较于iptables防火墙而言,firewalld支持动态更新技术并加入了区域(zone)的概念。简单来说,区域就是firewalld预先准备了几套防火墙策略集合(策略模板),用户可以根据生产场景的不同而选择合适的策略集合,从而实现防火墙策略之间的快速切换。
firewalld跟iptables比起来至少有两大好处:
相关文章
相关文章
官方文档描述比较全面,但是不够简洁以及没有操作流程,所以记录一下备忘。
本文是简单实用的快捷配置方式,使用smtp服务,具体需求看官方文档。
申请发件邮箱,开启SMTP服务
以qq邮箱为例,授权码即使邮箱发送时验证的密码
网易163邮箱配置
以客户留言接收邮件通知为例 markdown邮件文档
//生成Mailables Markdown 邮件
php artisan make:mail CustomerFeedbackMail --markdown=emails.customer.feedback
如图会生成两个文件,然后编写代码
配置在浏览器中预览邮件 文档
//添加路由
Route::get('mailable', 'Pc\PageController@mailable');//预览mark邮件
//控制器方法
public function mailable(Request $request)
{
return new CustomerFeedbackMail();
}
//简单编辑邮件模板feedback.blade.php
@component('mail::message')
# 邮件通知
The body of your message.
@component('mail::button', ['url' => ''])
进入官网后台管理
@endcomponent
@endcomponent
引入通知用到模型数据 文档
//预览页面控制器
class PageController extends Controller
{
public function mailable(Request $request)
{
$message = Message::find(1);
return new CustomerFeedbackMail($message);
}
}
//邮件mailable
class CustomerFeedbackMail extends Mailable
{
use Queueable, SerializesModels;
public $message;
public function __construct(Message $message)
{
$this->message = $message;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
//emails.customer.feedback是视图文件目录和文件
return $this->markdown('emails.customer.feedback', ['feedback' => $this->message])->subject('邮件标题');
}
}
//邮件视图文件markdown
@component('mail::message')
# 客户留言通知
## 姓名:{{$feedback->name}},
## 电话:{{$feedback->mobile}},
## 留言:{{$feedback->content}},
## 提交终端:{{$feedback->terminal}},
## 提交页面名称:{{$feedback->page_name}},
@component('mail::button', ['url' => ''])
进入官网后台管理
@endcomponent
@endcomponent
发送到指定邮箱 遍历收件人列表
//修改config/mail.php 配置,增加默认收件邮箱
'to' => [
'address' => explode(',', env('MAIL_DEFAULT_TO_ADDRESS', '')),
'name' => env('MAIL_TO_NAME', ''),
],
//修改env配置
MAIL_MAILER=smtp
MAIL_HOST=smtp.qq.com
MAIL_PORT=465
MAIL_USERNAME=xxxx@qq.com
MAIL_PASSWORD=xxxx
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=xxx@qq.com
MAIL_FROM_NAME=xxx
MAIL_DEFAULT_TO_ADDRESS=xxx@foxmail.com
MAIL_TO_NAME=留言通知
//发送代码,此处使用terminable中间件延时发送
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use App\Mail\CustomerFeedbackMail;
use App\Models\Message;
class SendFeedbackMailTerminable
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request);
}
public function terminate($request, $response)
{
$response_data = json_decode($response->getContent(), true);
if (!isset($response_data['data']['message_id']) || empty($response_data['data']['message_id'])) {
return;
}
Log::info('留言id=>'.$response_data['data']['message_id']);
$message = Message::find($response_data['data']['message_id']);
if (!$message instanceof Message) {
return;
}
$toAddress = config('mail.to.address');
foreach ($toAddress as $value) {
try {
Mail::to($value)->send(new CustomerFeedbackMail($message));
} catch (\Throwable $th) {
Log::channel('sendmail')->info('发送邮件失败'.$th->getMessage());
continue;
}
Log::channel('sendmail')->info('[官网留言邮件通知记录]:', ['email' => $value, 'message_id' => $response_data['data']['message_id']]);
}
}
}