宝塔面板下 mysql 数据库密码错误

宝塔下的mysql安装后,用ssh工具连接之后使用myql -uroot 登录会报错”ERROR 1045 (28000): Access denied for user ‘root‘@’localhost’ (using password: NO)”,后来在宝塔使用phpmyadmin登录之后,手贱的修改了密码,之后不知道怎么操作就出错了.phpMyAdmin也登录不上了,之后所有的mysql操作也不行.

  • 百度后找到的原文地址为: https://www.cnblogs.com/ivictor/p/9243259.html

  • 进入一个目录.vim创建一个init.sql文件.写入修改密码的sql语句,:wq 保存退出

    1
    2
    3
    cd /
    vim init.sql
    alter user 'root'@'localhost' identified by '123456';
  • 使用–init-file参数

    1
    2
    3
    /www/server/mysql/bin/mysqld_safe --init-file=/init.sql &

    service mysqld restart
  • 可以用比较简单的一步实现

    1
    service mysqld restart --init-file=/init.sql
  • 然后就可以用宝塔后台的修改新的mysql密码

linux 安装oh my zsh

  • 查看linux系统支持的shell

    1
    cat /etc/shells
  • 没有zsh 就先安装zsh

    1
    yum install zsh
  • 切换默认shell为zsh

    1
    chsh -s /bin/zsh 
  • 安装oh my zsh

    1
    wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh
  • 使用zsh

    1
    zsh

php 删除字符串中的汉字,保留数字和字母

需要从爬虫爬取的n多字符串中获取微信号

微信号规则:

  • 微信号是微信的唯一凭证,只能设置1次
  • 可使用6-20个字母,数字,下划线和减号
  • 必须以字母开头(字母不区分大小写)
  • 不支持设置中文
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$Model = new Wechat(); 
$data = $Model->select();

$new_data_arr = [];
foreach ($data as $v) {
$temp = [];
$result = preg_replace('/([\x80-\xff]*)/i', '', $v['data']); //删除汉字
$result = trim($result);//删除空格
$result = str_replace('~', '', $result);
$result = str_replace('?', '', $result);
$result = str_replace('.', '', $result);
$result = str_replace(':', '', $result);
$result = str_replace('/', '', $result);
$result = str_replace('\\', '', $result);
$result = str_replace(';', '', $result);
$result = str_replace('+', '', $result);
$result = str_replace('(', '', $result);
$result = str_replace(')', '', $result);
$result = str_replace('*', '', $result);
$result = str_replace(',', '', $result);
$result = str_replace('%', '', $result);
$result = str_replace(' ', '', $result);

if ($result && mb_strlen($result, 'utf-8') > 5 && mb_strlen($result, 'utf-8') < 21) {
$temp['id'] = $v['id'];
$temp['data1'] = trim($result);
$new_data_arr[] = $temp;
}
}

set_time_limit(0);
$result = $Model->saveAll($new_data_arr);

这样处理这后还是会有遗漏,会有不符合要求的微信号,还需要改进.

Maximum execution time of 30 seconds exceeded

今天用tp5框架处理使用八爪鱼爬的数据的时候 ,将数据处理然后savaAll保存数据库的时候,由于数据太多执行时间太长 ,报错..
如图

刚开始以为是mysql数据库的执行时间问题

1
2
3
4
;SHOW VARIABLES  WHERE Variable_name LIKE '%max_execution_time%'         #查询当前的max_execution_time,默认位0

;SET GLOBAL MAX_EXECUTION_TIME=1000 #重新设置时间
;SET SESSION max_execution_time=10000 #重新设置时间

再次尝试还是不行,最后发现是php的最大执行时间为30s,执行超时

可以修改php.ini 文件,我这里直接在php代码里,数据库操作前加一句,设置最大执行时间为不限时.

1
set_time_limit(0);

linux 删除文件夹报错 ‘rm: cannot remove ‘www.justseven.cn/.user.ini’: Operation not permitted’

想要删除一个不用的网站目录文件夹,使用rm -rf www.justseven.cn ,结果出现报错‘rm: cannot remove ‘www.justseven.cn/.user.ini’: Operation not permitted’。

百度获取的解决方案地址:
https://blog.csdn.net/sinat_35861727/article/details/79040755

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd www.justseven.cn  ##进入文件夹

ls -a ##显示所有包括隐藏的文件

lsattr -a ##显示文件属性

chattr -i .user.ini ##修改文件属性,去除 ‘不得任意更动文件或目录 ’属性

ls attr -a

cd ..

rm -rf www.justseven.cn ##再次删除文件夹

centos服务器安装php swoole扩展

官方编译安装地址 https://github.com/swoole/swoole-wiki/blob/master/doc/1.2%20-%20%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85.md

从github获取最新发行版本地址 https://github.com/swoole/swoole-src/releases
获取到的链接地址为:https://github.com/swoole/swoole-src/archive/v4.4.5.tar.gz

  • ssh登录服务器

  • 下载swoole包

    1
    wget https://github.com/swoole/swoole-src/archive/v4.4.5.tar.gz
  • 解压

1
tar -zxvf  v4.4.5.tar.gz
  • 进入文件夹 修改文件夹名字
1
2
cd swoole-src-4.4.5
mv swoole-src-4.4.5 swoole-src
  • 使用phpize来生成编译检测脚本
1
2
phpize  

  • 编译 ,这里需要注意,我的服务器安装了宝塔面板,所以php的安装路径不一样,需要用–with-php-config 指定php-config的路径
1
2
3
4
5
6
7
8
./configure \
--enable-coroutine \
--enable-openssl \
--enable-http2 \
--enable-async-redis \
--enable-sockets \
--enable-mysqlnd \
--with-php-config=/www/server/php/73/bin/php-config
  • 编译 安装
1
make clean && make && make install
  • 修改配置文件,添加扩展
1
2
3
cd /www/server/php/73/etc

vim ./php.ini

在php.ini 末尾添加 extension=swoole.so ,保存退出

  • 检查是否安装成功

显示php安装的模块

1
php -m

或者
获取php扩展的配置信息

1
php --ri swoole

hexo+github.io搭建的静态博客 'jQuery is not defined' 问题解决

我的这个博客就是hexo+github.io搭建的,加载会很慢,F12发现cosole报错 ‘jQuery is not defined, 发现是因为有query.min.js文件加载失败。因为用的是googleapis.com的域名,可能是被和谐了,查了下,然后修改juery的引用地址,解决问题。

微信图片_20190828112750

  • 在主题下搜索juqery的地址,找到是引用地址在 ‘themes/landscape/layout/_partial/after-footer.ejs ’文件下

微信图片_201908281127501

微信图片_201908281127502

  • 登录 https://www.bootcdn.cn/,搜索jquery.获取一个最新版本的jqury.min.js文件地址
    微信图片_201908281127503

  • 修改之前的after-footer.ejs文件下的jQuery地址,这里需要注意不能使用http的地址,因为在https下面的文件是访问http需要解决跨域问题。默认是https,所以直接填写为‘//cdn.bootcss.com/jquery/3.4.1/jquery.min.js’
    微信图片_201908281127504

  • 然后hexo clean ,hexo g 之后,你会发现pulic下的其它文件的jquery地址已经修改

微信图片_201908281127505

  • 接着 hexo d 提交部署。再打开网站,会发现jquery地址已经更新,而且不会报错了。
    微信图片_201908281127506

宝塔面板下 使用的Let’s Encrypts 安装免费SSL证书 使网站支持https

登录lets encrypts 网站

1.1 登录lets encrypts网站 点击get started

微信图片_201908271606402

1.2 选择中文

微信图片_201908271606402

1.3 我们有服务器权限 点击链接使用certbot

微信图片_201908271606404

安装certbot

2.1 选择当前http网站的linux服务器和web服务器类型

微信图片_201908271606405

当前我选择nginx和CentOS

1566954842(1)

2.2 根据提示安装certbot

微信图片_201908271606406

2.2.1 ssh链接服务器
2.2.2 开启epel。当前为centos 直接

1
yum install epel-release

微信图片_201908271606407

2.2.3 开启 optional channel

1
2
yum -y install yum-utils
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

2.2.4 安装 certbot

1
sudo yum install certbot python2-certbot-nginx

使用certbot 安装证书

3.1 使用命令安装

1
sudo certbot --nginx

因为安装了宝塔界面,会出现报错,按默认的目录没有找到nginx的配置文件

b5ddb3f1c454ca8dc6c6f5dc96b93e7

通过查询知道,应该用下面的指令,–nginx-server-root后面带上正确的nginx配置文件路径

1
2
certbot --nginx-server-root /www/server/nginx/conf 

微信图片_201908271606401

按数字选择你要安装的网站的域名

选择是否自动从http跳转到https

然后就会完成

证书安装的过程中,可能会让你输入邮箱,可以跳过邮箱:

1
certbot --nginx-server-root /www/server/nginx/conf --register-unsafely-without-email

安装完成之后,就可以测试自己的网站是否支持https

如果不能访问,可能是云服务器安全组没有开启443端口,linux服务器的443端口也需要打开

卸载证书

certbot revoke –cert-path 加证书地址

1
certbot revoke  --cert-path /etc/letsencrypt/live/www.test.com/cert.pem 

微信图片_20190827160640

安装中可能出现的问题

1.cryptography TypeError: from_buffer() cannot return the address……..

解决:

1
2
3
4
5
pip uninstall cryptography -y && \
yum -y remove python-cryptography && \
yum -y autoremove && \
pip install --upgrade cryptography

  1. UnicodeDecodeError: ‘ascii’ codec can`t decode byte 0xe7 in position 14 ……

4e179ff3a1ffaae42560f34528adb37

修改 /usr/lib64/python2.7 下的 mimetypes.py 文件 在文件前面添加下面的代码

1
if sys.getdefaultencoding() != 'utf-8': reload(sys) sys.setdefaultencoding('utf-8')
  1. ImportError: ‘pyOpenSSL’ module missing required functionality. Try upgrading to v0.14 or newer.

php项目搭建问题记录

1

环境:

php7.2 ,nginx

错误:

require_once(): Failed opening required '../fun/extend.php' (include_path='.:/www/server/php/72/lib/php') in #####/index.php on line 8" while reading response header from upstream

解决:


(图片保存在github)

2

php文件加密问题:

sg_load()函数

https://www.cnblogs.com/tangxuliang/p/9401122.html(解决方案地址)

安装sourceguardian加密php扩展:
https://www.sourceguardian.com/loaders/download.php