Heartsuit's Simple Blog

A place to hold mainly reading notes, and some technical stuff occasionally. 这里主要是一些读书笔记、感悟;还有部分技术相关的内容。


Project maintained by heartsuit Hosted on GitHub Pages — Theme by mattgraham

服务器运维相关问题

目录[-]


2018-08-27

TypeError: Cannot assign to read only property ‘exports’ of object ‘#

module.exports = {
^
TypeError: Cannot assign to read only property 'exports' of object '#<Object>'

需要引入插件 babel-plugin-transform-es2015-modules-commonjs
然后在 .babelrc中配置 { "plugins": ["transform-es2015-modules-commonjs"] }

Mysql ERROR 1040 (HY000): Too many connections

修改my.cnf配置文件添加并需要重启:
[mysqld] 
wait_timeout = 600
interactive_timeout = 600
即:10分钟内该连接没有请求就断开

MySQL批量插入主键重复

insert into 改为 insert ignore into

SVN服务器迁移 svnadmin: E000002: Can’t open file ‘/opt/svn/fireweb/format’: No such file or directory

1. 导出:
svnadmin dump F:/workspace/Shanfeng/fireweb >fireweb
2. 创建新目录:
svnadmin create ./opt/svn/fireweb
3. 导入:
svnadmin load /opt/svn/fireweb </opt/fireweb
4. 重新定位svn地址到新地址

启动svn服务:
svnserve -d -r /opt/svn
停止svn服务:
killall svnserve

2018-09-17

spring 开发环境与生产环境配置

1.开发、生产配置文件

将已有的resources.properties拆分为resources-dev.propertiesresources-prod.properties,分别存放开发与生产环境下的DB连接、MQ连接;

2.在spring配置文件中设置profile,引入对应的beans

<!-- 开发环境配置文件 -->
<beans profile="dev">
    <context:property-placeholder location="classpath:conf/resources-dev.properties"/>
</beans>

<!-- 生产环境配置文件 -->
<beans profile="prod">
    <context:property-placeholder location="classpath:conf/resources-prod.properties"/>
</beans>

Note: 必须放在配置文件xml的最下面(包括import),否则xml报错,无法启动。

3.激活profile

Method1. web.xml配置

<!-- 激活指定的profile -->
<context-param> 
    <param-name>spring.profiles.active</param-name> 
    <param-value>dev</param-value> 
</context-param>

Method2. 修改 Tomcat 启动脚本 catalina.bat

set JAVA_OPTS="-Dspring.profiles.active=prod"

2018-09-29

node.js 安装nodejieba报错

node-gyp rebuild
if not defined npm_config_node_gyp (node "E:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "E:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "E:\Anaconda3\python.EXE", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (E:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:483:19)
gyp ERR! stack     at PythonFinder.<anonymous> (E:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack     at E:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 6.1.7601

MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。

需要安装windows环境构建工具:`npm install --global --production windows-build-tools`
其中包含python 2.7与vs_BuildTools.exe

2018-10-12

MySQL 保存微信昵称(含表情等特殊字符)报错

ALTER TABLE b_wx CHANGE nickname nickname varchar(30) character set utf8mb4 collate utf8mb4_unicode_ci;

这样,可以将包含表情的微信昵称保存至数据表,不过表中仍然无法显示,在Web页面可以显示相应的表情。

2018-10-12-WXNickName.jpg

PS:一个有趣的发现:昵称中的表情在FireFox中显示为彩色,Chrome中显示为灰色;


2018-11-02

https下使用WebSocket

小程序要求服务器必须为https的,将阿里云的http升级为https后,发现客户端的WebSocket无法与服务器建立连接了:DOMException: “The operation is insecure.”

`ws://127.0.0.1:8080/websocket` 改为 `wss://127.0.0.1:8080/websocket`

vue-cli, axios 参数使用URLSearchParams,在IE中报错: ReferenceError: “URLSearchParams”未定义

1 npm i url-search-params-polyfill --save
2 在main.js `import 'url-search-params-polyfill';`

然后又报 ReferenceError:“Promise”未定义 1 npm i babel-polyfill –save 2 在main.js import 'babel-polyfill';

Spring Boot配置HTTP2

需要做的是,在pom.xml中移除Tomcat的依赖,增加Undertow的依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

在application-prod.yml

server:
    port: 443
    http2:
        enabled: true
    ssl:
        key-store: classpath:yours.pfx
        key-store-password: yours
        keyStoreType: PKCS12
    undertow:
        io-threads: 2
        worker-threads: 20
        buffer-size: 1024
        direct-buffers: true

Note: 首先需要有证书,采用HTTPS; HTTP默认端口号:80,HTTPS默认端口号:443;


持续更新……


If you have any questions or any bugs are found, please feel free to contact me.

Your comments and suggestions are welcome!


「说点什么吧😊~~😊」: