King's blog


  • 分类

  • 标签

  • 归档

  • 关于

  • 搜索

ElasticSearch可视化工具Dejavu安装使用

发表于 2020-09-09 | 更新于: 2021-04-20

Dejavu 是一个 ElasticSearch 的 Web UI 工具,支持通过 JSON 和 CSV 文件导入数据,支持可视化定义 Mapping (字段映射)等。

相关描述在 https://github.com/appbaseio/dejavu/ 上都有详细描述,这里只是做个简单的记录。

1、安装 Docker 环境

这里就不细述了,网上有很多相关的资料。

  • CentOS Docker 安装
  • Ubuntu Docker 安装
  • Docker 镜像加速

也可以不使用 Docker ,会比较麻烦一点。

2、运行 ElasticSearch 服务

如果已经存在 ElasticSearch 服务,那么只需要确保其启用了 CORS (跨域)设置即可。

启用方式为,在 elasticsearch.yml 配置文件中添加以下几行:

1
2
3
4
5
http.port: 9200
http.cors.allow-origin: 'http://localhost:1358'
http.cors.enabled: true
http.cors.allow-headers: X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
http.cors.allow-credentials: true

如果不存在 ElasticSearch 服务的情况下,则可运行下面命令运行一个 ElasticSearch 的 docker 容器

ElasticSearch 2.x

1
docker run --name elasticsearch -p 9200:9200 -d elasticsearch:2 -Des.http.port=9200 -Des.http.cors.allow-origin="http://localhost:1358" -Des.http.cors.enabled=true -Des.http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -Des.http.cors.allow-credentials=true

ElasticsSarch 5.x

1
docker run --name elasticsearch -p 9200:9200 -d elasticsearch:5 -E http.port=9200 -E http.cors.allow-origin="http://localhost:1358" -E http.cors.enabled=true -E http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -E http.cors.allow-credentials=true

ElasticSearch 6.x

1
docker run -p 9200:9200 -d elasticsearch docker.elastic.co/elasticsearch/elasticsearch-oss:6.5.4 -Ehttp.port=9200 -Ehttp.cors.enabled=true -Ehttp.cors.allow-origin=http://localhost:1358 -Ehttp.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization -Ehttp.cors.allow-credentials=true

ElasticSearch 7.x

1
docker run -d --rm --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "http.cors.enabled=true" -e "http.cors.allow-origin=*" -e "http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization" -e "http.cors.allow-credentials=true" docker.elastic.co/elasticsearch/elasticsearch-oss:7.0.1

安装完成后可以使用下面命令创建一个新索引

1
curl -X PUT http://ip:9200/test

3、安装运行 Dejavu 服务

使用 docker 安装 Dejavu 服务

1
docker run -p 1358:1358 -d appbaseio/dejavu

安装完成后可以使用浏览器打开 http://ip:1358 使用。

VSCode新建vue模版

发表于 2020-09-03 | 更新于: 2021-04-20

前言

每次新建一个vue文件!都要重行敲打一遍template。script。style。神烦!有没有和别的编辑器一样!设置自己默认的模板!

一、安装vscode

官网下载地址

1
https://code.visualstudio.com/

二、安装一个插件,识别vue文件

1
插件库中搜索Vetur,下图中的第一个,点击安装,安装完成之后点击重新加载

三、新建代码片段

1
文件-->首选项-->用户代码片段-->点击新建代码片段--取名vue.json 确定

四、粘入自己写的.vue模板

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
"Print to console": {
"prefix": "vue",
"body": [
"<!-- $1 -->",
"<template>",
"<div class='$2'>$5</div>",
"</template>",
"",
"<script>",
"// 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)",
"// 例如:import 《组件名称》 from '《组件路径》';",
"",
"export default {",
"// import引入的组件需要注入到对象中才能使用",
"components: {},",
"data() {",
"// 这里存放数据",
"return {",
"",
"};",
"},",
"// 监听属性 类似于data概念",
"computed: {},",
"// 监控data中的数据变化",
"watch: {},",
"// 方法集合",
"methods: {",
"",
"},",
"// 生命周期 - 创建完成(可以访问当前this实例)",
"created() {",
"",
"},",
"// 生命周期 - 挂载完成(可以访问DOM元素)",
"mounted() {",
"",
"},",
"beforeCreate() {}, // 生命周期 - 创建之前",
"beforeMount() {}, // 生命周期 - 挂载之前",
"beforeUpdate() {}, // 生命周期 - 更新之前",
"updated() {}, // 生命周期 - 更新之后",
"beforeDestroy() {}, // 生命周期 - 销毁之前",
"destroyed() {}, // 生命周期 - 销毁完成",
"activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发",
"}",
"</script>",
"<style lang='scss' scoped>",
"// @import url($3); 引入公共css类",
"$4",
"</style>"
],
"description": "Log output to console"
}
}

上面代码中的 "prefix": "vue", 就是快捷键;保存好之后,新建.vue结尾的文件试试

1
输入vue 按键盘的tab就行

模板创建完毕。

vue模块化开发

发表于 2020-09-02 | 更新于: 2021-04-20

设置npm淘宝镜像地址

1
npm config set registry http://registry.npm.taobao.org

Vue安装

1) 初始化项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ npm init -y
Wrote to D:\wwwroot\npwh-vue-electron\package.json:
{
"name": "npwh-vue-electron",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

2) 安装vue

1
2
3
4
5
6
7
$ npm install vue
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN npwh-vue-electron@1.0.0 No description
npm WARN npwh-vue-electron@1.0.0 No repository field.

+ vue@2.6.12
added 1 package from 1 contributor in 0.617s

Vue模块化安装

1)全局安装webpack

1
$ npm install webpack -g

webpack 是一个用于现代 JavaScript 应用程序的静态模块打包工具。当 webpack 处理应用程序时,它会在内部构建一个 依赖图(dependency graph),此依赖图对应映射到项目所需的每个模块,并生成一个或多个 bundle。

2)全局安装Vue脚手架

1
$ npm install -g @vue/cli-init

CLI ( @vue/cli ) 是一个全局安装的npm 包,提供了终端里的 vue 命令。 它可以通过 vue create 快速搭建一个新项目,或者直接通过 vue serve 构建新想法的原型。 你也可以通过 vue ui 通过一套图形化界面管理你的所有项目。

3)初始化Vue项目

1
$ vue init webpack `appname`

vue脚手架使用webpack模板初始化一个appname项目

4)启动项目

项目的package.json中有scripts,代表我们能运行的命令

npm start = npm run dev 启动项目

npm run build 将项目打包

Docker安装Redis

发表于 2020-08-19 | 更新于: 2021-04-20

Docker安装Redis

Redis 是一个开源的使用 ANSI C 语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value 的 NoSQL 数据库,并提供多种语言的 API。

一、下载镜像

1
$ docker pull redis:6.0.6

二、创建文件夹以及配置文件

1
2
$ mkdir -p /data/redis/conf
$ touch /data/redis/conf/redis.conf

三、创建实例并启动

1
2
3
4
5
$ docker run -p 6379:6379 --name redis606 \
-v /data/redis/conf/redis.conf:/etc/redis/redis.conf \
-d redis:6.0.6 \
redis-server \
/etc/redis/redis.conf

四、接着我们通过 redis-cli 连接测试使用 redis 服务。

1
$ docker exec -it redis606 /bin/bash

五、设置Redis容器在docker启动的时候启动

1
$ docker update redis --restart=always

安装完毕。

Vagrant安装Linux虚拟机

发表于 2020-08-19 | 更新于: 2021-04-20

下载装vagrant

vagrant官方镜像仓库

https://app.vagrantup.com/boxes/search

vagrant下载

https://www.vagrantup.com/downloads.html

初始化一个CentOS7系统

打开命令行窗口,运行

1
vagrant init centos/7

启动虚拟机

1
vagrant up # 系统root用户的密码是vagrant

vagrant其他常用命令

1
2
vagrant ssh # 自动使用vagrant用户连接虚拟机
vagrant upload source [description] [name|id] # 上传文件

https://www.vagrantup.com/docs/cli/init.html Vagrant命令行

https://www.vagrantup.com/docs/cli/box#box-remove

网络配置

默认虚拟机的IP地址不是固定IP,修改Vagrantfile文件

1
2
3
config.vm.network "private_network", ip:"192.168.58.10"

vagrant up # 重新启动机器,然后重新vagrant连接机器

这里的ip需要在物理机下使用ipconfig命令找到

密码登录

vagrant ssh进入系统

1
2
3
4
5
6
$ vim /etc/ssh/sshd config
# 修改
PasswordAuthentication yes/no

# 重启服务
$ service sshd restart

vagrant up下载box慢的解决办法

即在运行vagrant up时得到其的下载路径,如:

1
https://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box

然后直接在浏览器上访问该网址来下载该box

先查看本地安装的box:

1
$ vagrant box list

再将得到的box文件手动添加进去:

1
2
3
$ vagrant box add --name centos/7 /c/Users/Kings/Downloads/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box

$ vagrant box remove centos/7 $ 从box中移除指定镜像

然后再查看本地果然多了一个新的box:

1
2
3
4
$ vagrant box list
centos/7 (virtualbox, 0)
laravel/homestead (virtualbox, 9.5.1)
laravel/homestead (vmware_desktop, 9.2.0)

然后再在相应vagrantfile对应的目录下运行vagrant up即可运行起来了:

1
$ vagrant up

然后使用vagrant ssh即可进入:

1
$ vagrant ssh

vagrant up 启动报错 拆坑记录 之编码设置

在 Vagrantfile 文件下加入

1
2
3
4
5
config.vm.provider "virtualbox" do | vb |
..............
# Encoding.default_external = 'GBK'
Encoding.default_external = 'UTF-8'
end

alpine使用的避坑指南

发表于 2020-08-18 | 更新于: 2021-04-20

alpine使用的避坑指南

alpine,是一个重量仅为5 MB的最小Linux发行版。它还有基本的linux工具和一个不错的包管理器APK。APK非常稳定,有相当数量的包。由于体积小,在容器中很受欢迎,但是使用上坑也很多,大部分可能是我们的无知吧。

坑1 : 下载慢

解决:

1
2
3
echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main" > /etc/apk/repositories \
&& echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community" >> /etc/apk/repositories \
&& echo "https://mirror.tuna.tsinghua.edu.cn/alpine/edge/testing" >> /etc/apk/repositories

坑2: 找不到包

解决: 搜索 https://pkgs.alpinelinux.org/packages ,加入指定的“Branch”和“Repository”的源到/etc/apk/repositories,就可以apk add

坑3: 安装失败

1
2
3
4
5
ERROR: https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/community: Bad file descriptor
WARNING: Ignoring APKINDEX.79f426e4.tar.gz: Bad file descriptor
ERROR: unsatisfiable constraints:
openssh (missing):
required by: world[openssh]

解决:

1
apk add  openssh --no-cache #加--no-cache, 另外,还能减少镜像体积

坑4:镜像体积大,想删除不再使用的包

apk add 加 -t 参数

-t, --virtual NAME Instead of adding all the packages to 'world', create a new virtual package with the listed dependencies and add that to 'world'; the actions of the command are easily reverted by deleting the virtual package 这意味着当您安装软件包时,这些软件包不会添加到全局软件包中。这种变化可以很容易地回滚/删除。所以,如果我需要gcc来编译程序,但是一旦程序被编译,我就不再需要gcc了。

我可以在虚拟包中安装gcc和其他必需的包,并且可以删除所有依赖项,并删除此虚拟包名称。以下是示例用法

apk add --virtual mypacks gcc vim apk del mypacks 使用第一个命令安装的所有18个软件包将被下一个命令删除。

注意:同一个-t参数会覆盖之前的所有安装包,所有对动态链接库最好不使用-t ,或者保证此参数不重复。

坑5:时间不同步

1
2
3
4
echo "Asia/Shanghai" > /etc/timezone
apk add –no-cache tzdata
TZ=Asia/Shanghai
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

坑6:用户(组)和宿主机不兼容

解决:

1
2
addgroup -g 1200 -S www \
&& adduser -u 1200 -D -S -G www www

坑7:不兼容glibc

解决: 使用最新稳定版本的alpine,

1
2
3
4
5
6
7
8
#再安装编译环境
apk add --virtual .build-base --no-cache \
autoconf \
automake \
g++ \
make \
linux-headers \
bsd-compat-headers

alpine使用的避坑指南

发表于 2020-08-18 | 更新于: 2021-04-20

配置ssh免密登录

https://gitee.com/help/articles/4181#article-header0

CentOS7-firewalld

发表于 2020-08-18 | 更新于: 2021-04-20 | 分类于 CentOS

查看防火墙状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost /]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2020-08-18 17:32:56 CST; 56s ago
Docs: man:firewalld(1)
Main PID: 1607 (firewalld)
Tasks: 2
Memory: 28.1M
CGroup: /system.slice/firewalld.service
└─1607 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

Aug 18 17:32:56 localhost systemd[1]: Starting firewalld - dynamic firewall daemon...
Aug 18 17:32:56 localhost systemd[1]: Started firewalld - dynamic firewall daemon.
Aug 18 17:32:57 localhost firewalld[1607]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configur...t now.
Hint: Some lines were ellipsized, use -l to show in full.

开启防火墙

1
[root@localhost /]# systemctl start firewalld

关闭防火墙

1
[root@localhost /]# systemctl stop firewalld

查看已开放端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@localhost /]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

防火墙开放端口:(开放端口后需重载防火墙)

1
2
3
4
5
6
7
8
9
10
[root@localhost /]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost /]# firewall-cmd --reload
success

# 命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
firewall-cmd --reload # 重载防火墙

移除开放的端口

1
[root@localhost /]# firewall-cmd --zone=public --remove-port=80/tcp --permanent

firewalld 基本使用

1
2
3
4
5
6
7
firewalld的基本使用

启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewall

systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

1
2
3
4
5
6
7
8
9
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

配置firewalld-cmd

1
2
3
4
5
6
7
8
9
10
查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic

CentOS7常见问题

发表于 2020-08-18 | 更新于: 2021-04-20

ifconfig command not found解决和netstat -an

1
2
# 没有 ifconfig 和netstat -an 的话安装 net-tools package
$ yum install net-tools

检查端口被哪个进程占用

1
netstat -lnp | grep 8000

查看进程的详细信息

1
ps 11100

杀掉进程

1
kill -9 11100

Docker安装MySQL

发表于 2020-08-18 | 更新于: 2021-06-04

前言

为了更好的管理,打算把MySQL、Redis等服务放在虚拟机中统一部署,这样不会因为这些服务的问题影响到系统本身。前段时间正好在看docker相关的内容,打算在虚拟机中通过docker来使用MySQL等服务。

一、下载镜像文件

1
$ docker pull mysql:5.7

二、查看镜像

1
$ docker images

三、创建实例并启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ docker run -p 3306:3306 --name=mysql57 \
-v /data/mysql/log:/var/log/mysql \
-v /data/mysql/data:/var/lib/mysql \
-v /data/mysql/conf/:/etc/mysql \
-e TZ=Asia/Shanghai \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7

# 参数说明
--restart=always # 当docker重启时,该容器自动重启
--name mysql # 将容器命名为mysql,后面可以用这个name进行容器的启动暂停等操作
-e MYSQL_ROOT_PASSWORD=123456 # 设置MySQL密码为123456
-d # 此容器在后台运行,并且返回容器的ID
-i # 以交互模式运行容器
-p 3306:3306 # 将容器的3306端口映射到主机的3306端口
-v /data/mysql/log:/var/log/mysql # 将配置文件夹挂载到主机
-v /data/mysql/data:/var/lib/mysql # 将日志文件夹挂载到主机
-v /data/mysql/conf/:/etc/mysql # 将配置文件夹挂载到主机
-e TZ=Asia/Shanghai # 时区设置

四、修改配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 进入配置目录
$ cd /data/mysql/conf

# 修改数据库配置
$ vim my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

# 重启 mysql57 容器
$ docker restart mysql57

五、设置启动docker时,即运行mysql

1
$ docker update mysql --restart=always

六、启动docker容器的时候报错

1
2
3
$ docker start mysql57
Error response from daemon: driver failed programming external connectivity on endpoint mysql57
Error: failed to start containers: mysql57

解决方法:重启docker

1
$ systemctl restart docker

本地客户端设置远程访问账号

1
2
3
$ docker exec -it mysql bash
$ mysql -uroot -p123456
mysql> grant all privileges on *.* to root@'%' identified by "password";

防火墙设置

1
2
3
4
5
6
# 开放端口:
$ systemctl status firewalld
$ firewall-cmd --zone=public --add-port=3306/tcp -permanent
$ firewall-cmd --reload
# 关闭防火墙:
$ sudo systemctl stop firewalld
1…456
King's

King's

53 日志
13 分类
31 标签
RSS
© 2020 — 2022 King's
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.2