Write the Code. Change the World.

分类目录
5月 31

不走 nginx 的代理,请求连接 websocket,总需要带上端口号。比如 new WebSocket("wss://www.xxx.com:9958"),通过 nginx 的代理就可以实现这样的请求,比如 new WebSocket("wss://www.xxx.com/wss")

一波操作

vim www.xxx.com.conf

upstream websocket {
    # wss 配置代理到 127.0.0.1:9958
    server 127.0.0.1:9958;
}

server
{
    listen 80;
    server_name xxx.com www.xxx.com;

    return 301 https://www.xxx.com$request_uri;
}

server
{
    listen 443 ssl http2;
    server_name xxx.com www.xxx.com;

    if ($host = 'xxx.com' ){
        return 301 https://www.xxx.com$request_uri;
    }

    ssl_certificate         /service/nginx/conf/ssl/www.xxx.com.pem;
    ssl_certificate_key     /service/nginx/conf/ssl/www.xxx.com.key;

    location /wss {
        # 代理到上边的自定义的地址
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    …

重启, nginx。

其实,在 proxy_pass 这里,可以直接设置为 127.0.0.1:9958

还有请求的时候,域名后一定要带上 wss 。

5月 31

Client does not support authentication protocol requested by server; conside 新旧版本密码算法不同引起的错误,只需要设置下密码方式为 mysql_native_password 就可。还是 navicat 做的好,新旧密码都支持。

操作一波

mysql -u root -p

xxxx

use mysql;

show tables;

# 查看已经有的用户
select user, host from user;

# 重新设置下密码,并使之生效
# 之前是 'xxx'@'%' IDENTIFIED BY 'xxxxxx'
'xxx'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxxxx'

flush privileges;
5月 30

使用 redis 客户端是比较有必要的,这个时候就需要远程登录 redis 了。不过,redis 默认是无密码,只允许服务端登录。修改下配置,重启 redis 即可实现想要的目的。

一波操作

修改 redis.conf 文件。

  1. 设置密码。因为密码是在配置文件里的 ,所以尽可能的设置长一点,也不怕忘记哈。

修改 # requirepass foobared 为你自己想要的密码 requirepass Safb0xafNabaf!fEfaWfs@#$a4afsdfw8ay

  1. 设置 protected-modeno

  2. 去掉 bind 或 设置为 bind 0.0.0.0

  3. 重启 redis 。

# 使用 conf 启动 redis
./redis-server redis.conf

# 登录客户端
./redis-cli 

auth 密码

# 查看所有配置
config get *

# 查看单独一个的
config get bind

其他

如果发现重启没啥鬼用,可以直接杀死进程,然后以 conf 启动。

ps -ef | grep redis

kill -9 xxxx

./redis-server redis.conf

还有 dump 文件需要注意,默认是 dump.rdb 文件。

5月 12

当你的的 nginx 中设置 Content-Security-Policy,就有可能会遇到: script in the following Content Security Policy directive: "script-src * 'unsafe-inline'"

Content-Security-Policy 策略

最快的解决办法,注释掉 Content-Security-Policy,并重启 nginx

vim xxx.conf

../../sbin/nginx -s reload

参考这里

https://www.cnblogs.com/Hwangzhiyoung/p/9146740.html

5月 06

在 win 中,在终端中使用 git 都会显示分支名,这样很清晰,也很安全。知道当前处于哪个分支。而 linux 下,默认是不显示这些的。这个就得想办法去实现。办法有好几种,这里就来一个简单好用的。

操作来一波

# 如果权限不够 sudo 提升权限

sudo vim ~/.bashrc

# 在末尾追求以下内容
# Show git branch name
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt

# source 使生效
source ~/.bashrc

到这里,已经看到效果了。

4月 06

nginx 新增模块缺失,

nginx: [emerg] unknown directive "more_clear_headers"

https://blog.csdn.net/chunyuan314/article/details/81737303

安装

https://github.com/openresty/headers-more-nginx-module

cd /usr/local/src

wget https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz

tar -xzvf v0.33.tar.gz

cd headers-more-nginx-module-0.33

新增模块

# 先准备曾经的配置,找到 configure arguments 后边的配置。

nginx -V

# 找到曾经的包文件
cd /usr /local/src/nginx 

# 再配置后追加 add-module 指向headers-more-nginx-module-0.33

./configure --user=nginx --group=nginx --prefix=/alidata/service/nginx --pid-path=/alidata/service/nginx/run/nginx.pid --with-http_stub_status_module --with-threads --with-file-aio --with-pcre-jit --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_realip_module --with-http_addition_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-stream_realip_module --with-http_slice_module --with-pcre --with-openssl=/usr/local/src/base/1-openssl/openssl-1.1.1f --with-openssl-opt=enable-tls1_3 --add-module=/opt/ngx_brotli/ --add-module=/usr/local/src/nginx/headers-more-nginx-module-0.33

# 再make (千万不要 make install)

make

# 然后复制 nginx 文件覆盖之前安装包里的 nginx 文件,覆盖安装之前 ,先备份一个
nginx stop

cp /alidata/service/nginx/sbin/nginx  /alidata/service/nginx/sbin/nginx.back
cp -r objs/nginx /alidata/service/nginx/sbin/nginx

# 启动
/alidata/service/nginx/sbin/nginx

参考

https://segmentfault.com/a/1190000018418253?utm_source=coffeephp.com

4月 06

官网: https://redis.io/

可参考:
https://blog.vini123.com/107

###

wget http://download.redis.io/releases/redis-5.0.8.tar.gz

tar -xzvf  redis-5.0.8.tar.gz

cd redis-5.0.8

# 安装依赖
yum install tcl

# 继续

make

make test

# 没有问题就安装
make install PREFIX=/alidata/service/redis 

# 配置并启动redis
mkdir /alidata/service/redis/etc/

cp  /usr/local/src/redis/redis-5.0.8/redis.conf /alidata/service/redis/etc/

vim /alidata/service/redis/etc/redis.conf   #编辑redis.conf

daemonize yes   #将此行对应的no改成yes。

# 启动
/alidata/service/redis/bin/redis-server /alidata/service/redis/etc/redis.conf

# 连接 redis
/alidata/service/redis/bin/redis-cli

配置开机自启动

# 开机自启动

cp /usr/local/src/redis/redis-5.0.8/utils/redis_init_script /etc/init.d/redis

vim /etc/init.d/redis

# 然后修改EXEC、REDIS_CLI、CONF对应的值。分别对应服务端位置、客户端位置、配置文件位置。保存,退出。修改后的脚本如下;
# 修改

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/alidata/service/redis/bin/redis-server
CLIEXEC=/alidata/service/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF=/alidata/service/redis/etc/redis.conf

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

执行权限,并开启服务重启自启动

chmod +x /etc/init.d/redis   #执行权限
chkconfig redis on   #系统服务中启动redis服务
chkconfig --list   #系统服务启动列表
/etc/init.d/redis start   #启动redis

安装 php redis 扩展

cd /usr/local/src

mkdir php-redis

cd php-redis

wget http://pecl.php.net/get/redis-5.2.1.tgz

tar -xizvf redis-5.2.1.tgz

cd redis-5.2.1 

# 编译安装
phpize

./configure 

make && make install

# 配置
vim /alidata/service/php/etc/php.ini

在末尾加上 extension=redis.so 保存。

# 重启
/etc/init.d/php-fpm restart

# 查看
php -m | grep redis
4月 06

mysql8忘记密码有点不一样。其实很坑的,明明密码没错误,偏偏说错误。就算错误了,使用 skip-grant-tables 这玩意也进不去 mysql。那现在使用一个简单的方法来搞定这个问题。

这里使用 --init-file 方式重启 mysql 可以设置 root 用户的密码。亲测有效。

--init-file 干啥子的呢。就是 mysql 启动的时候,执行 --init-file对应的文件里的语句。

那么操作吧。

vim /usr/local/temp/resetPd.txt

# 加入下边命令,重新设置 root 密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '@¥#abcd1234';

:wq 保存

# 然后重启 mysql
service mysqld restart --init-file=/usr/local/temp/resetPd.txt --console 

# 再用新密码登录 mysql
mysql -u root -p 

# 发现果然好使,果然可以登录上去了
4月 06

mysql 设置 root 用户密码以及禁用远程登录 root 用户后,需要设置一些其他账户密码使用。

mysql 常见的用户密码权限类型:

  1. 本地用户访问。
  2. 外网用户任意ip访问。
  3. 外网特定ip访问。
  4. 指定访问数据库。
  5. 指定数据库表的增删改查权限。

创建用户

创建本地用户

create user shenqi@localhost identified by '33441314';  

# 这样就会在 mysql 库的 user 表中,就插入了一条用户数据。退出 root 用户,使用该账户就可以登录进来了。但进来只有一个数据库 information_schema  。因此需要给用户分配数据库权限以及刷新权限。

https://www.jianshu.com/p/5903e8c002ed

创建外网访问的用户

create user shenqi@'%' identified by '33441314';  

设置本地服务器对数据库的全部权限

grant all privileges on dbname.* to shenqi@localhost;

设置外网服务器对数据库的全部权限

grant all privileges on dbname.* to shenqi@'%';

如果想要指定的外网ip 才可以访问,可以将 % 改成允许访问的 ip,也就是外网其他 ip 是不可以访问的。

设置用户访问所有的数据库

grant all on *.* to 'shenqi'@'%';

使得更改生效

flush privileges;

例子:

create user feipool@'%' identified by '_Sq123456';  

grant all on feipool.* to feipool@'%';

ALTER USER feipool@'%' IDENTIFIED WITH mysql_native_password BY '_Sq123456';

flush privileges;

其他操作

# 删除用户
drop user 'shenqi';

# 修改用户账号名
rename user 'shenqi' to 'vini';

# 修改用户密码
alter user 'shenqi'@'%' identified by '98589958';

# 显示某个用户的权限
show grants for shenqi;

# 设置单独的权限
grant EXECUTE,INSERT,SELECT,UPDATE, DELETE on dbname.* to shenqi@'%';

# execute  执行存储过程的权限
# insert 插入
# select 查询
# update 修改
# delete 删除
# dbname.* 是所有的表的权限,也可以具体某个表

# 权限回收
revoke update on dbname.* from shenqi;

# revoke取消的意思,后面跟权限,多个权限的时候使用逗号隔开,on 后面跟对象,from 后面跟用户,前面赋权的时候跟to,现在取消使用from,不要搞错了,全部权限的话可以使用all

测试

create database shenqi

grant all on shenqi.* to 'shenqi'@'%';

flush privileges;

# shenqi 用户登录, 看看 database;
show databases;

还可以建立角色,设置角色权限,将用户和角色绑定在一起就可以。这种在数据库账号多的情况下实在好用。

4月 05

在CentOS8下编译安装MySQL8可能会出现Could not find rpcgen错误,而CentOS8默认的yum源下不提供rpcgen的安装包。所以需要到rpcgen的GitHub仓库上找,地址如下:

https://github.com/thkukuk/rpcsvc-proto/releases

参考:
http://www.linuxfromscratch.org/blfs/view/svn/basicnet/rpcsvc-proto.html

下载安装

wget https://github.com/thkukuk/rpcsvc-proto/archive/v1.4.1.tar.gz

tar -xzvf v1.4.1.tar.gz

./configure --sysconfdir=/etc