SED编辑器修改文本,在匹配内容后追加
- 最近使用宝塔建站,网址比较多的时候修改起来比较费时间,搞个shell脚本批量处理,实现功能 access_log /path/abc/file.log; 指定日志格式
sed -i 's#access_log.*\.log#& ngx_log#g' /path/abc/file.log
- 知识点: &用来表示模式匹配(正则表达式匹配)的范围
sed -i 's#access_log.*\.log#& ngx_log#g' /path/abc/file.log
同步加载cssjs资源文件造成阻塞,网页打开慢
var myCSS = document.createElement( "link" );
myCSS.rel = "stylesheet";
myCSS.href = "mystyles.css";
document.head.insertBefore( myCSS, document.head.childNodes[ document.head.childNodes.length - 1 ].nextSibling );
onload="this.media='all'
<link rel="stylesheet" href="path/cssfile.css" media="jscourse" media="css-async" onload="if(media!='all')media='all'" rel="stylesheet">
使用新规范rel="preload"
,例子如下
onload
修改rel
<link rel="preload" href="cssfile.css" as="style" onload="this.rel='stylesheet'">
<link rel="preload" href="scriptfile.js" as="script">
audio
document
embed
fetch
font
image
object
script
style
track
worker
video
使用 SSH 连接工具,如堡塔SSH终端连接到您的 Linux 服务器后,挂载磁盘,根据系统执行相应命令开始安装(大约2分钟完成面板安装):
Centos安装脚本 yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
Ubuntu/Deepin安装脚本 wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
Debian安装脚本 wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && bash install.sh
Fedora安装脚本 wget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh
/www/server/panel/BTPanel/static/js/index.js
,将function show_force_bind()
取消即可top
发现是mysql异常,show processlist
查看发现是大量的慢SQL到账的SELECT COUNT(*) FROM idmaps WHERE typeid=8 AND keyid=1085287221 AND showtype=0
, 查下表数据千万量级,ibd文件20几个G,数据不小呀,盘它show create table idmaps;
CREATE TABLE `idmaps` (
`typeid` tinyint(3) unsigned NOT NULL DEFAULT '0',
`keyid` int(10) unsigned NOT NULL DEFAULT '0',
`myid` int(10) unsigned NOT NULL DEFAULT '0',
`showtype` tinyint(3) unsigned NOT NULL DEFAULT '0',
`exttype` int(10) unsigned NOT NULL DEFAULT '0',
`sortnum` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`typeid`,`myid`,`keyid`),
KEY `idx_list` (`typeid`,`keyid`,`showtype`,`sortnum`),
KEY `idx_list2` (`typeid`,`keyid`,`showtype`,`exttype`,`sortnum`) USING BTREE,
KEY `idx_ids` (`typeid`,`keyid`),
KEY `typeid` (`typeid`),
KEY `keyid` (`keyid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
explain SELECT COUNT(*) FROM idmaps WHERE typeid=8 AND keyid=275787765 AND showtype=0;
+----+-------------+--------+------+-------------------------------------------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+-------------------------------------------------+---------+---------+-------+------+-------------+
| 1 | SIMPLE | idmaps | ref | PRIMARY,idx_list,idx_list2,idx_ids,typeid,keyid | PRIMARY | 1 | const | 1 | Using where |
+----+-------------+--------+------+-------------------------------------------------+---------+---------+-------+------+-------------+
mysql> SELECT COUNT(*) FROM idmaps WHERE typeid=8 AND keyid=275787765 AND showtype=0;
+----------+
| COUNT(*) |
+----------+
| 2 |
+----------+
1 row in set (21.80 sec)
force index
mysql> SELECT COUNT(*) FROM idmaps force index(idx_ids) WHERE typeid=8 AND keyid=275785755 AND showtype=0;
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
mysql> explain SELECT COUNT(*) FROM idmaps force index(idx_list) WHERE typeid=8 AND keyid=275787765 AND showtype=0;
+----+-------------+--------+------+---------------+----------+---------+-------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+------+---------------+----------+---------+-------------------+------+-------------+
| 1 | SIMPLE | idmaps | ref | idx_list | idx_list | 6 | const,const,const | 2 | Using index |
+----+-------------+--------+------+---------------+----------+---------+-------------------+------+-------------+
1 row in set (0.00 sec)
mysql> SELECT COUNT(*) FROM idmaps force index(keyid) WHERE typeid=8 AND keyid=275785755 AND showtype=0;
+----------+
| COUNT(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
PRIMARY KEY
基本无用,尝试调整索引解决alter table idmaps drop PRIMARY KEY;
。 成功解决此慢查询问题,且不影响其它SQL预计。删除主键
ALTER TABLE TABLENAME(表名) DRROP PRIMARY KEY
增加主键
ALTER TABLE TABLENAME(表名) ADD PRIMARY KEY (字段1)
增加复合主键
ALTER TABLE TABLENAME(表名) ADD PRIMARY KEY (字段1,字段2......)