CainChan

  • 首页

  • 归档

Win10开机自动挂载目录到Vmware Linux

发表于 2019-11-01

1.共享目录设置

  1. 查看共享目录,用vmware-hgfsclient命令可以看到你的共享目录,这个命令是你安装了vmwaretools成功后生成的

  2. 默认挂载目录为/mnt/hgfs

  3. 手动挂载目录命令

    1
    sudo /usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o subtype=vmhgfs-fuse,allow_other

2.设置开启自启动虚拟机

  1. 编写startLinuxVM.bat

    1
    "C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" start "E:\VM\Ubuntu\Ubunut1810.vmx" nogui
  1. 将startLinuxVM.bat添加自启动目录

    1
    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

Nginx配置Vue和Laravel

发表于 2019-11-01
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
33
34
upstream laowu {
server 10.9.10.66:9000 fail_timeout=10 max_fails=5 weight=1 ;
server 10.9.10.65:9000 fail_timeout=10 max_fails=5 weight=1 ;
}

server {
listen 9090;
server_name laowu.ifchange.com;
charset utf-8;
root /opt/wwwroot/toh/client/sly-web/dist;

access_log /opt/log/laowu.log main;
error_log /opt/log/laowu_err.log;
index index.html index.htm index.php;

location / {
try_files $uri $uri/ /index.html?$query_string;
}
location /api {
try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
root /opt/wwwroot/toh/service/sly/public;
fastcgi_pass laowu ;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param APP_ENV production;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $DOCUMENT_ROOT$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT/$fastcgi_script_name;
include fastcgi_params;
}
}

使用Logstash实时分析日志

发表于 2018-12-20

Logstash是一个应用程序日志、事件的传输、处理、管理和搜索的平台。你可以用它来统一对应用程序日志进行收集管理,提供 Web 接口用于查询和统计。

一、安装

环境:Centos6

需要java运行环境:java -version

下载并安装公共签名密钥

1
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

然后在/etc/yum.repos.d/目录添加一个以.repo后缀的文件,比如:logstash.repo

1
2
3
4
5
6
[logstash-2.3]
name=Logstash repository for 2.3.x packages
baseurl=https://packages.elastic.co/logstash/2.3/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1

至此资源库添加完成,你可以使用yum安装logstash了

1
yum install logstash

安装完成后,可用以下命令测试是否安装成功

1
bin/logstash -e 'input { stdin { } } output { stdout {} }'

logstash的默认程序路径在:/opt/logstash/

logstash的默认配置文件路径在:/etc/logstash/conf.d/

二、配置

在/etc/logstash/conf.d/新建一个以.conf后缀的文件,比如:nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
input {
file {
path => "/opt/log/pv.ifchange.com/pv.ifchange.com.access.log"
type => "nginx-access"
}
}
output {
http {
format => "form"
http_method => "post"
url => "http://logsystem.dev.ifchange.com/analysislog/clickLog"
mapping => ["Body", '%{message}']
}
stdout {
codec => "rubydebug"
}
}

以上配置代表将文件/opt/log/pv.ifchange.com/pv.ifchange.com.access.log里的日志实时通过HTTP POST的方式提交给http://logsystem.dev.ifchange.com/analysislog/clickLog进行处理。为了方便调试,加了stdout参数,代表输出到屏幕。

##三、启动
为了方便调试可手动启动:

1
/opt/logstash/bin/logstash agent -f /etc/logstash/conf.d/test.conf

也可直接使用服务启动:

1
service logstash start

停止服务:

1
service logstash stop

配置文件测试:

1
service logstash configtest

使用Certbot安装Let's Encrypt免费SSL证书

发表于 2018-12-20

1.安装certbot

1
sudo yum install certbot

2.生成域名证书

1
certbot certonly --standalone -d youdomain.com -d www.youdomain.com

3.配置Nginx SSL站点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server {
listen 80;
server_name www.youdomain.com youdomain.com;
return 301 https://$server_name$request_uri;
}

server{
listen 443 ssl;
server_name www.youdomain.com youdomain.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.youdomain.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/youdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/youdomain.com/privkey.pem;

……
}

其中return 301 https://$server_name$request_uri;是用来实现80端口到443端口的流量跳转的.

4.重启Ningx即可

5.更新证书

因Let’s Encrypt提供的免费证书有效期为90天,所以我们通过以下语句通过续期

1
certbot renew --quiet

更新所有站点证书

参考

  • Certbot
  • Let’s Encrypt

selenium PhantomJS自动登录网站

发表于 2018-12-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
33
34
35
36
37
#!/usr/bin/env python
#coding:utf-8
import re
import sys
import time
import urllib2

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support import ui

#设置user-agent
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0 ")

#设置参数
service_args = ['--proxy=192.168.1.201:7070','--proxy-type=socks5','--ignore-ssl-errors=true']
driver = webdriver.PhantomJS(executable_path='/root/phantomjs2.1.1/bin/phantomjs', desired_capabilities=dcap,service_args=[])
driver.maximize_window()
wait = ui.WebDriverWait(driver, 10)

#登录alivv
url = "http://www.alivv.com"
driver.get(url)
wait.until(lambda dr: dr.find_element_by_css_selector(".login_login").is_displayed())
driver.find_element_by_css_selector(".login_login").click()
driver.find_element_by_css_selector("#email").send_keys("kaychen")
driver.find_element_by_css_selector("#pass").send_keys("0516*****")
driver.find_element_by_css_selector("#jzpass").click()
driver.find_element_by_css_selector("#submitFormBtn").click()
#进入会员中心
driver.find_element_by_css_selector("#sname a").click()
#输出页面源码
print driver.page_source
time.sleep(3)
driver.save_screenshot('/tmp/screen.png')
driver.quit()

升级Node/Npm版本

发表于 2018-12-20

一.升级nodejs

  1. 安装n

    1
    sudo npm install -g n
  2. 使用n来管理版本

    1
    2
    3
    4
    sudo n lts 长期支持
    sudo n stable 稳定版
    sudo n latest 最新版
    sudo n 8.4.0 直接指定版本下载
  3. 查看node版本 node -v

二.升级npm

1
sudo npm install -g npm

ElasticSearch指南

发表于 2018-12-20 | 更新于 2018-12-19

Why?(使用ES目标)

解决根据progress和账号获取订单列表Mysql性能瓶颈

How?

将每个订单的查询条件都存储到ES,进行索引,所有订单支持搜索的条件都添加到索引Mapping字段中去,(如何解决延迟问题?)

一、安装

  1. 依赖

    • Java
    • Node
  2. 下载

    • ElasticSearch官网下载
    • ElasticSearch-Head GitHub下载
  3. 部署ES

    1. 主节点配置文件elasticsearch-master/config/elasticsearch.yml添加

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      # 允许ElasticSearch-Head访问
      http.cors.enabled: true
      http.cors.allow-origin: "*"
      # 设置集群名称
      cluster.name: order
      # 设置节点名称
      node.name: master
      # 设置为主节点
      node.master: true
      # 指定主机IP
      network.host: 127.0.0.1
    2. 从节点配置文件elasticsearch-slave/config/elasticsearch.yml添加

      1
      2
      3
      4
      5
      6
      7
      8
      # 设置集群名称
      cluster.name: order
      # 设置节点名称
      node.name: slave01
      # 指定端口
      http.port: 9201
      # 指定集群主节点IP
      discovery.zen.ping.unicast.hosts: ["127.0.0.1"]
    3. 启动./bin/elasticsearch -d

  4. 部署ES-HEAD

    1
    2
    3
    cd elasticsearch-head
    npm install
    npm run start

访问http://localhost:9100/

二、使用

1.创建索引
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
PUT http://127.0.0.1:9200/chengdan
{
"settings":{
"number_of_shards" : 1
},
"mappings":{
"order":{
"properties":{
"order_id":{
"type":"integer"
},
"toh_account_id":{
"type":"integer"
},
"tob_account_id":{
"type":"integer"
},
"progress":{
"type":"integer"
},
"updated_at":{
"type":"date",
"format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd"
}
}
}
}
}
2.创建文档
1
2
3
4
5
6
7
8
POST http://127.0.0.1:9200/chengdan/order/34756359
{
"order_id":34756359,
"toh_account_id":10000002,
"tob_account_id":1226,
"progress":10,
"updated_at":"2018-03-10 12:10:10"
}
3.查询文档
1
2
3
4
5
6
7
8
9
10
11
12
13
14
POST http://127.0.0.1:9200/chengdan/order/_search
{
"query":{
"bool":{
"must":[
{"terms":{"toh_account_id":[10000001,10000001]}},
{"terms":{"progress":[10,11,20]}}
]
}
},
"sort":[
{"updated_at":{"order":"desc"}}
]
}
4.修改文档
1
2
3
4
5
6
7
POST http://127.0.0.1:9200/chengdan/order/34756359/_update
{
"doc":{
"progress":20,
"updated_at":"2018-03-12 20:00:00"
}
}

Ubuntu18.04部署Shadowsocks

发表于 2018-12-19 | 更新于 2018-12-20 | 分类于 Internet

一.Server部署

  1. 更新源 sudo apt-get update

  2. 安装python-pip sudo apt-get install python-pip

  3. 安装shadowsocks sudo pip install shadowsocks

  4. 编写配置文件sudo vim /etc/shadowsocks.json

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    {
    "server": "0.0.0.0",
    "server_port": 9999,
    "local_address": "127.0.0.1",
    "local_port": 5555,
    "password": "******",
    "method": "aes-256-cfb",
    "fast_open": true,
    "timeout":300
    }
  5. 启动服务 sudo ssserver -c /etc/shadowsocks.json -d start

二.客户端下载

Client下载

三.备注

  • Ubuntu18.04需修正openssl版本问题,替换EVP_CIPHER_CTX_cleanup为EVP_CIPHER_CTX_reset

    sudo sed -i 's/EVP_CIPHER_CTX_cleanup/EVP_CIPHER_CTX_reset/g' /usr/local/lib/python2.7/dist-packages/shadowsocks/crypto/openssl.py

pip使用国内源

发表于 2018-02-20 | 更新于 2018-12-20

对于Python开发用户来讲,PIP安装软件包是家常便饭。但国外的源下载速度实在太慢,浪费时间。而且经常出现下载后安装出错问题。所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成功率。

国内源

  • 清华:https://pypi.tuna.tsinghua.edu.cn/simple
  • 阿里云:http://mirrors.aliyun.com/pypi/simple/
  • 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
  • 华中理工大学:http://pypi.hustunique.com/
  • 山东理工大学:http://pypi.sdutlinux.org/
  • 豆瓣:http://pypi.douban.com/simple/

    临时使用

    可以在使用pip的时候加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple
    例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider

这样就会从清华这边的镜像去安装pyspider库

永久修改,一劳永逸

Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)

1
2
3
4
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com

windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini。内容同上。

iptables笔记

发表于 2018-01-01 | 更新于 2018-12-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
iptables -P INPUT ACCEPT/DROP
iptables -P OUTPUT ACCEPT/DROP
iptables -P FORWARD ACCEPT/DROP

iptables -F #清除预设表filter中的所有规则链的规则
iptables -X #清除预设表filter中使用者自定链中的规则
iptables -Z #清除预设表filter中使用者自定链中的规则
iptables -L -n #查看
iptables-save #预览规则内容
service iptables save #保存到默认文件
service iptables restart #重启


#接纳属於现存及相关连接的压缩
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#允许icmp包通过,也就是允许ping
iptables -A INPUT -p icmp -j ACCEPT
#允许loopback(不然会导致DNS无法正常关闭等问题)
iptables -A INPUT -i lo -j ACCEPT
#添加必要端口
iptables -A INPUT -s 192.168.0.0/16 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -j REJECT #拒绝其他
iptables -A FORWARD -j REJECT #拒绝转发


iptables -L --line-numbers #显示行号
iptables -D INPUT 8 #删除INPUT的第8条规则
123

CainChan

29 日志
2 分类
31 标签
© 2020 CainChan
由 Hexo 强力驱动 v3.8.0
|
主题 – NexT.Gemini v6.6.0