joelin109 / blog

0 stars 0 forks source link

Util: How to set up the common tools on Mac M #26

Open joelin109 opened 3 years ago

joelin109 commented 3 years ago

Tools that should install in Mac

1. Homebrew

osx的软件管理工具, z.B. NPM for NodeJS (http://brew.sh/)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

brew --version

brew install 安装软件包 brew uninstall 卸载软件包 brew search 查询软件包 brew update 更新brew brew home 用浏览器打开brew的官方网站 brew info 显示软件信息 brew deps 显示包依赖

brew list 或brew ls 列出已安装的软件包 (/opt/homebrew/Cellar)

joelin109 commented 3 years ago

2. wget

brew install wget
joelin109 commented 3 years ago

3. Git

git --version

brew upgrade git
brew install git
--  Mac系统自带Git
which git

-- 修改Git指向
brew link git

or

vim .bash_profile  添加
export GIT=/usr/local/Cellar/git/2.1.3 #这里写brew下载的git版本地址
export PATH=$GIT/bin:$PATH
joelin109 commented 3 years ago

4. Redis

~ %  brew install redis

~ %  redis-server -v

<br>

- Set [Username] & Password 

-- Test if Redis Server is Running ~ % redis-cli ping

-- Set Password 127.0.0.1:6379> AUTH PASSWORD 127.0.0.1:6379> CONFIG SET requirepass "myredis52" 127.0.0.1:6379> AUTH myredis52

or

opt/homebrew/etc/redis.conf

uncomment line # requirepass foobared, then restart server now password is foobared


<br>

- Add Row  (add records)

~ % redis-cli 127.0.0.1:6379> set 10001 key-value 127.0.0.1:6379> setex 10002 1000 key-value2

127.0.0.1:6379> keys * 127.0.0.1:6379> exit

PS. setex key ttl value, after ttl(seconds), the record will disappear.


<br>
<br>
<br>

## Code
- JavaScript Code

PSUBSCRIBE可以监听键的过期事件. 使用命令监听事件(psubscribe keyevnet@0:expired)

const redis = require('redis'); const client = redis.createClient({host: 127.0.0.1, port: 6379, db: 2}); const subClient = redis.createClient({host: 127.0.0.1, port: 6379, db: 2}); subClient.psubscribe('keyevent@2:expired');

client.set(key, value, 'EX', 60 60 24); client.get(key); client.del(key); client.expire(key, expire_time);

subClient.on("pmessage", function(pattern, channel, expiredKey){ console.log(channel + ': key [' + expiredKey + '] has expired'); });


- Python Code

import redis from embo import app

pool = redis.ConnectionPool( host=app.config["REDIS_HOST"], port=app.config["REDIS_PORT"], db=app.config["REDIS_DATABASE"], password=app.config["REDIS_PASSWORD"], decode_responses=True ) Redis = redis.StrictRedis(connection_pool=pool)

def zadd_compatible(name, *args): if not Redis.exists(name): return try: Redis.zadd(name, dict(zip(args[1::2], args[::2]))) except: Redis.delete(name)


-  Redis的消息发布(publish)/ 订阅(subscribe)

SUBSCRIBE channel [channel …] / 订阅给定的一个或多个频道的信息 PSUBSCRIBE pattern [pattern …] / 订阅一个或多个符合给定模式的频道 PUBSUB subcommand [argument [argument …] / 查看订阅与发布系统状态 PUBLISH channel message / 将消息发送到指定的频道


joelin109 commented 3 years ago

5. ElasticSearch & Kibana

ELK三件套: Elasticsearch & Logstash & Kibana. Logstash: 数据的转换和导入; Kibana: Es的数据显示web界面

Node: 一个ES实例就是一个node. 一机器可有多个实例,大多数情况下每个node运行在一个独立环境或虚拟机上。

Index: 即一系列documents的集合. (Index > Database, document > Row)

Shard: ES是分布式搜索引擎,每个Index 有一个或多个分片,Indices的数据被分配到各个Shard上, Shard有助于横向扩展,Shards 会被尽可能平均地(rebalance)分配在不同的Node上. Shard 是独立的,对于一个Search Request,每个Shard会执行这个Request.

一个分片MAX存放 2,147,483,519 个docs Shards(分片)非常重要,直接和性能挂钩. ES可把一个的索引分成多分片,好处是把一个大的索引拆分成多个,分布到不同的节点上,构成分布式搜索。 分片数量只能在索引创建前指定,并且索引创建后不能更改。ES7.0以上默认1主Shard和1副Shard

Replica: 可理解为备份Shard,相应有primary shard. 主分片和备分片不会出现在同一 Node上(防止单点故障).

容灾:primary分片丢失,replica分片就会被顶上去成为新主分片,同时新主分片创建新的replica,集群数据安然无恙


<br> 

- Install

~ % brew tap elastic/tap

~ % brew install elastic/tap/elasticsearch-full ~ % brew install elastic/tap/kibana-full

~ % elasticsearch --version ~ % kibana --version


<br> 

- Start & Stop

~ % elasticsearch then open http://localhost:9200/

~ % kibana then open http://localhost:5601/

~ % pkill -f elasticsearch ~ % pkill -f kibana


<br>

- Config
`/opt/homebrew/etc/elasticsearch/`
`/opt/homebrew/etc/kibana`

elasticsearch.yml for configuring Elasticsearch jvm.options for configuring Elasticsearch JVM settings log4j2.properties for configuring Elasticsearch logging

Path setting in elasticsearch.yml: path.data: /opt/homebrew/var/lib/elasticsearch/ path.logs: /opt/homebrew/var/log/elasticsearch/


<br>

- ElasticSearch VS DB

Elasticsearch -> Indices(Index) -> Types -> Documents -> Fields Relational DB -> Databases -> Tables -> Rows -> Columns

"_shards" : { "total" : 2, "successful" : 1, "failed" : 0 },


<br>

- DSL(结构化查询) #27 
`DSL(Domain Specific Language ), 以JSON的请求形式, 允许构建更复杂、强大的查询`

<br>

- Code

Javascript:

Python:

joelin109 commented 3 years ago

6. PostgreSQL

3


Step2: sudo vi .zshrc export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/14/bin


<br>
<br>

- Backup
`In Navicat Premium`

Way 1: DataBase - Backups - New Backup

Way 2: DataBase - Backups - Extract SQL From

Way 3: Tools - Data Transfer - Target File



Way 2: Database - Execute SQL File

joelin109 commented 3 years ago

7. MySQL

Alert MySQL installer including temporary password during installing then you will see MySQL pane in System Preferences

joelin109 commented 3 years ago

8. VS Code & Postman

For API Test: Thunder Client vsc-postman (Postman APP is besser)


<br>
<br>

- 代码格式规范
`ESLint & Prettier`

ESLint和Prettier的指责: ESLint负责代码风格定义 Prettier负责根据ESLint定义的风格进行自动格式化

Extensions: Prettier - code formatter.


<br>
<br>

- Terminal  
` Error: listen EADDRINUSE address already in use :::5003`

sudo lsof -i :5003 kill -9 {PID}

joelin109 commented 2 years ago

Customize VSCode

Extensions



joelin109 commented 2 years ago

9. Fastlane


<br>
<br>

- Fastlane
`ESLint & Prettier`
joelin109 commented 2 years ago

Movie Home Page Movie Detail Page