def case1(): # 第一种情况执行的函数
print('This is the case1')
def case2(): # 第二种情况执行的函数
print('This is the case2')
def case3(): # 第三种情况执行的函数
print('This is the case3')
def default(): # 默认情况下执行的函数
print('No such case')
switch = {'case1': case1, # 注意此处不要加括号
'case2': case2, # 注意此处不要加括号
'case3': case3, # 注意此处不要加括号
}
choice = 'case1' # 获取选择
switch.get(choice, default)() # 执行对应的函数,如果没有就执行默认的函数
获取bilibili个人空间里所有视频的链接
随手写得
var linklist = [];$('.small-item').each(function(index,item){linklist.push("https:" + $($(item).find("a")[0]).attr("href"))});var outStr = "";linklist.forEach(function(item){outStr += item + "\n"});console.info(outStr)
HTTP状态码整理
结合我自己日常时间所遇到的一些情况和理解,来整理一下HTTP状态码
1xx 临时相应
100 continue (继续)
这个状态码实际上是对如下场景的一种优化:客户端有一个较大的文件需要上传并保存,但是客户端不知道服务器是否愿意接受这个文件,所以希望在消耗网络资源进行传输之前,先询问一下服务器的意愿。
继续阅读“HTTP状态码整理”python安装cx_Oracle
linux上安装cx_Oracle方法:
1、首先复制instantclinet并解压到/usr/lib/instantclient_12_2
apt-get install libaio1 sudo sh -c "echo /usr/lib/instantclient_12_2/ > /etc/ld.so.conf.d/oracle-instantclient.conf" ldconfig
在CentOS中安装 yum install libaio
动态链接库连接完毕之后,增加一些环境变量
export ORACLE_HOME=/usr/lib/instantclient_12_2 export PATH=$ORACLE_HOME/bin:$PATH export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
可以加入到 .bashrc 中,修改系统全局设定;
source ~/.bashrc 来使它立即生效
修改MySQL数据存储路径
最近新起了个MySQL,服务器上是一个小一点的SSD,搭配一个大容量机械硬盘的方案,默认存储的/var/lib/mysql会在SSD里,所以需要修改MySQL数据库的数据存储路径。当我尝试了修改/etc/mysql/中的配置文件,并将/var/lib/mysql文件夹内文件全部复制之后,重启服务发现,服务起不来了。查看日志发现是Mysql没有新的文件夹的访问权限。
那这就奇怪了,文件权限都是正常的,文件属主也在mysql上,后来才发现,是因为ubuntu系统的apparmor服务导致的。
/etc/apparmor.d/usr.sbin.mysqld 这个文件中,有这两行,规定了mysql使用的数据文件路径权限
/var/lib/mysql/ r, /var/lib/mysql/** rwk,
那么我只需要在下面增加我需要的两个文件夹,就可以顺利开启权限了
/home/base/mysql r, /home/base/mysql/** rwk,
完事之后,记得重启服务
sudo service apparmor restart
这样就OK了
pip中科大源
实际测试了一下,南邮的源还是差一些,这个放在C:/users/XXX/pip/pip.ini
里
[global] index-url = https://mirrors.ustc.edu.cn/pypi/web/simple
或者临时使用
pip install -i https://mirrors.ustc.edu.cn/pypi/web/simple package
ubuntu安装docker
ubuntu系统上安装docker是比较方便的,这里使用软件仓库的方式来安装docker,并安装portainer作为镜像容器的管理。
1) 安装必要的一些系统工具
sudo apt-get update sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common继续阅读“ubuntu安装docker”
Consul+upsync+Nginx 动态负载均衡 方案
Consul服务器
下载consul_1.6.2_linux_amd64.zip,解压至/usr/bin,依赖unzip
mkdir -p /data/consul mkdir /etc/consul.d consul agent -server -bootstrap-expect=1 -data-dir=/data/consul -node=agent-one -bind=192.168.1.95 -enable-script-checks=true -config-dir=/etc/consul.d -client 0.0.0.0 -ui
nohup启动方式
mkdir /var/opt/consul nohup consul agent -server -bootstrap-expect=1 -data-dir=/data/consul -node=agent-one -bind=192.168.1.95 -enable-script-checks=true -config-dir=/etc/consul.d -client 0.0.0.0 -ui >> /var/opt/consul/consul.log 2>&1 &
Nginx服务器
前置依赖
apt-get install -y unzip gcc make
nginx 配置用户和组
groupadd nginx useradd -g nginx -s /sbin/nologin nginx mkdir -p /var/tmp/nginx/client/ mkdir -p /usr/local/nginx
ubuntu编译安装Nginx
apt-get install -y openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --add-module=../nginx-upsync-module-master make && make install
配置upsync
mkdir /usr/local/nginx/conf/servers/
upsync_dump_path指定从consul拉取的上游服务器后持久化到的位置,这样即使consul服务器出问题了,本地还有一个备份。
POSTMAN发包创建upstream
upstream 98apache2{ server 127.0.0.1:11111; upsync 192.168.1.95:8500/v1/kv/upstreams/98apache2 upsync_timeout=6m upsync_interval=500ms upsync_type=consul strong_dependency=off; upsync_dump_path /usr/local/nginx/conf/servers/98apache2.conf; } server { listen 80; server_name localhost; location / { proxy_pass http://98apache2; index index.html index.htm; } }
kv中可配置权重
{"weight":2, "max_fails":2, "fail_timeout":10, "down":0}
Ubuntu18.04创建rc.local
ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service touch /etc/rc.local chmod 755 /etc/rc.local继续阅读“Ubuntu18.04创建rc.local”
Ubuntu查看crontab运行日志
Ubuntu服务器/var/log下没有cron日志,这里记录一下如何ubuntu server如何查看crontab日志
crontab记录日志
修改rsyslog sudo vim /etc/rsyslog.d/50-default.conf cron.* /var/log/cron.log #将cron前面的注释符去掉 重启rsyslog sudo service rsyslog restart sudo service cron restart 查看crontab日志 less /var/log/cron.log