分类 其它分类 下的文章

Install:
apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
apt update
apt install mosquitto
service mosquitto status
service mosquitto start

Client install:
apt install mosquitto-clients

【基本配置】
vim /etc/mosquitto/mosquitto.conf
allow_anonymous false #不允许匿名
password_file /etc/mosquitto/passwd #配置用户密码文件
acl_file /etc/mosquitto/acl #配置topic和用户 (这个就是配置特权用户访问某主题,如果不配置则使用password_file文件中的用户密码进行访问)

用htpasswd配置passwd文件
mosquitto_passwd -c /etc/mosquitto/passwd pub_client password1
mosquitto_passwd /etc/mosquitto/passwd sub_client password2

[root@sparkVM mosquitto]# cat /etc/mosquitto/passwd
sub_client:$6$lHiPm6dLpaqsdfQb$SETYv2TthcgK388atPA7jNTSQYlWZzz8HxRzOVeZMx5iVNAAViuHhIgYzayl5BmzjNo8C0Cf4CH6ss6LdWtW8Q==
pub_client:$6$NDYKXj+h1wb5rIsz$Mf1Hq+EEsmXXy1Y377Rt8S4oVfm3S06R6Km3rqzzOQYIKCIDz8z5vVFh8CHGx4zPnBRMWObNnFvOYVjnOe2Sdw==

配置acl,topic和用户的关系
[root@sparkVM mosquitto]# cat /etc/mosquitto/acl

pub_client 用户可读可写

user pub_client
topic bell/#

sub_client 只可读

user sub_client
topic read bell/#

【测试验证】
服务端:
Linux代码 收藏代码
[root@sparkVM mosquitto]# mosquitto_pub -t mtopic -m "test"
1416301592: New connection from ::1 on port 1883.
Connection Refused: not authorised.

[root@sparkVM mosquitto]# mosquitto_pub -t mtopic -u pub_client -P test -m "test"
1416301643: New connection from ::1 on port 1883.
1416301643: New client connected from ::1 as mosqpub/4113-sparkVM (c1, k60, upub_client).

客户端:
Linux代码 收藏代码
[root@pandaVM html]# mosquitto_sub -h 192.168.197.128 -t mtopic
Connection Refused: not authorised.

[root@pandaVM html]# mosquitto_sub -h 192.168.197.128 -t mtopic -u sub_client -P sub_client
test

客户端:
https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho.ui.app/1.1.1/org.eclipse.paho.ui.app-1.1.1-win32.win32.x86_64.zip

  1. MQTT中的QoS等级
    MQTT设计了一套保证消息稳定传输的机制,包括消息应答、存储和重传。在这套机制下,提供了三种不同层次QoS(Quality of Service):

QoS0,At most once,至多一次;
QoS1,At least once,至少一次;
QoS2,Exactly once,确保只有一次。

信任所有来源:
sudo spctl --master-disable

访达中显示隐藏文件:Win+Shift+.

安装 cocoapods:
sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods
或:sudo gem install cocoapods
或 Brew 安装:brew install cocoapods

安装 Brew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
国内镜像:
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
如果卡在:
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
或其它安装失败或者卡住的问题,解决方法也是一样,请Control + C中断脚本执行如下命令:
cd "$(brew --repo)/Library/Taps/"
mkdir homebrew && cd homebrew
git clone git://mirrors.ustc.edu.cn/homebrew-core.git
/bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh)"
最后看到==> Installation successful!就说明安装成功了。
最后更新下:brew update
设置镜像(清华大学源)
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update

添加环境变量:
/Users/user/.bash_profile
export PATH="$PATH:/Applications/flutter/bin"
source $HOME/.bash_profile

终端下使用Proxy:
bash(mac osx系统默认命令行)配置:
vim ~/.bash_profile
#proxy
alias proxy='export all_proxy=socks5://127.0.0.1:1080'
alias unproxy='unset all_proxy'
source ~/.bash_profile #使配置生效

zsh命令行配置:
vim ~/.zshrc
#proxy
alias proxy='export all_proxy=socks5://127.0.0.1:1080'
alias unproxy='unset all_proxy'
source ~/.zshrc #使配置生效

查开放端口(netstat)
sudo lsof -i -P | grep LISTEN | grep :$PORT
sudo lsof -iTCP -sTCP:LISTEN -n -P

目标权限问题(OS Error: Permission denied, errno = 13),修改目录所有者:
sudo chown -R xiongfei ./

取消系统更新提示
先进入设置取消自动检查,然后进终端执行:
defaults write com.apple.systempreferences AttentionPrefBundleIDs 0
killall Dock

下载服务器端

git clone https://github.com/Coolpy7/Coolpy7.git && cd Coolpy7

解压文件

unzip go_build_Coolpy7_go_linux.zip

提权

chmod -R 777 go_build_Coolpy7_go_linux

启动Coolpy7

./go_build_Coolpy7_go_linux

后台运行:
(/home/Coolpy7/go_build_Coolpy7_go_linux &)
(/home/Coolpy7/go_build_Coolpy7_ws_go_linux &)

启动成功后会打印如下信息,即说明服务端已正常启动,host于1883端口,请确保相关防火墙配置可用

2018/10/29 12:59:55 Coolpy7 tcp is listening on [::]:1883

测试:
https://github.com/Coolpy7/coolpy7_benchmark
git clone https://github.com/Coolpy7/coolpy7_benchmark.git
cd coolpy7_benchmark/bin

//sub test
./go_build_cp7_bench_sub_go_linux -workers=4000000 -cid=tqy -topic=null -qos=0 -url=tcp://103.196.127.19:1883 -keepalive=60000s -clear=true

//pub test
./go_build_cp7_bench_pub_go_linux -cid=cp7 -clear=true -keepalive=300s -qos=0 -s=256 -topic=a/b/c -url=tcp://103.196.127.19:1883 -workers=500

本应用示例使用Coolpy7作为Mqtt服务器并启用Websocket代理完美支持高并发大流量即时通过能力,本示以即时通信聊天为为例。还可以应用到其他软件应用如:网页客服系统、网站信息通知、网页即时通信系统、网页游戏等等

MQTT服务端程序(Coolpy7)
WebSocket代理服务端 (Coolpy7_ws)
Html5聊天室前端

Coolpy7核心服务运行后会自行构当前目录下的data文件夹,此文件夹存放MQTT运行期所需求持久化的数据信息,使用的是开源项目 https://github.com/jacoblai/yiyidb,支持10亿级秒op的高性能数据库,数据库内核使用的是Leveldb技术。

下载服务器端

git clone https://github.com/Coolpy7/Coolpy7.git && cd Coolpy7

解压文件

unzip go_build_Coolpy7_go_linux.zip

提权

chmod -R 777 go_build_Coolpy7_go_linux

启动Coolpy7 启动参数

l 当前服务Host地址 (默认为:1883即本地1883端口,此参数一般默认即可,无需配置)

a 连接接入调度器最大线程,此值可防止暴力连接攻击,对已连接客户端进行优先保护 (默认值128)

./go_build_Coolpy7_go_linux

启动成功后会打印如下信息,即说明服务端已正常启动,host于1883端口,请确保相关防火墙配置可用

2018/10/29 12:59:55 Coolpy7 tcp is listening on [::]:1883
一般需为程序提权才可以运行Linux服务,指令:chmod -R 777 go_build_Coolpy7_go_linux

运行Coolpy7 WS代理服务

此功能即为Coolpy7核心服务提供WebSocket接入功能。通过ssh进入服务器192.168.200.203,并确保你已经按照 https://coolpy7.gitbook.io/coolpy7book/kai-shi-shi-yong/start 配置服务器操作系统的网络优化配置。

千万级WebSocket代理服务器
支持防爆力攻击

下载服务器端

git clone https://github.com/Coolpy7/Coolpy7.git && cd Coolpy7

解压文件

unzip go_build_Coolpy7_ws_go_linux.zip

提权

chmod -R 777 go_build_Coolpy7_ws_go_linux

启动Coolpy7 WS Poxy

r启动参数 CP7核心服务器所在ip或域名 (例:core.coolpy.net:1883 or 192.168.200.201:1883)

l启动参数 当前服务Host地址 (默认为:8083即本地8083端口,此参数一般默认即可,无需配置)

./go_build_Coolpy7_ws_go_linux

启动成功后会打印如下信息,即说明服务端已正常启动,host于8083端口,请确保相关防火墙配置可用

2018/10/29 12:59:55 upstream 192.168.200.201:1883 ok
2018/10/29 12:59:55 Coolpy7 ws is listening on [::]:8083
运行Html5前端聊天室应用示例

下载开源项目:https://github.com/Coolpy7/Cp7Chat
修改连接地址为上一步服务器端ip和端口(具体ip和端口按阁下真实环境,全套程序运行于本机可统一使用127.0.0.1为连接地址)
通过Webstorm等web调试工具运行代码
以WebStorm为例

1.下载源代码
填写git地址下载源代码

2.修改连接信息本示例以本机运行整套系统为例输入127.0.0.1,端口号8083,假设把服务器端Coolpy7和Coolpy7-ws已经运行于阿里云之类的云服务器上改写为服务器的公网IP地址和端口即可,如果已绑定域名可直接填写域名如: test.coolpy.net
代码位于chat.html第55行

3.修改完毕后选中工程中的index.html点击
至此已完成运行部署。以下是测试运行演示

项目开源信息
服务器端开源地址: https://github.com/Coolpy7
聊天室前端开源地址:https://github.com/Coolpy7/Cp7Chat

1、安装 java sdk
https://www.oracle.com/java/technologies/downloads/#java8-windows

2、服务端安装 gitblit:
2.1 http://gitblit.github.io/gitblit/ 下载最新版本
2.2 修改配置 data\defaults.properties,其中目录配置时注意用正斜杠!

  • git.repositoriesFolder = C:/GitRepository
  • server.httpsPort = 8821
  • server.httpBindInterface = 0.0.0.0
    // - server.certificateAlias = domain.com
  • git.sshPort = 8822

2.3 修改服务配置 installService.cmd

  • SET ARCH=amd64
  • SET CD=D:\tools\gitblit-1.9.1
  • 清空启动参数:--StartParams="" ^

2.4 以管理员身份运行 installService.cmd 安装服务,并到服务中启动服务。

3、windows 客户端:

git clone ssh://admin@domain.com:8822/proj.git

如果出现证书问题报错 SSL certificate problem: self signed certificate in certificate chain,可以设置不认证:

git config --global http.sslVerify false 

如果 ssh 错误提示 no matching host key type found. Their offer: ssh-rsa,是因为 .ssh/known_hosts 下面没有相关信息,使用命令行执行一次点接受即可:

ssh admin@domain.com -p 8822

如果还不行,则 C:\Users\用户名.ssh\ 目录下增加文件:config

Host office.belltrip.net
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa

恢复本地被删除的文件
git reset --hard HEAD

修改忽略列表,改完后:

git rm -r --cached . 
git add .
git commit -am "Remove ignored files"
git pull origin master
git push origin master

查看所有配置:git config -l

分支:

git checkout -b branch    #创建分支
git checkout branch    #切换分支
git merge master    #将master合并到当前分支

合并时忽略部分文件:
建立 .gitattributes 文件,写入需要忽略的文件列表,支持通配符,跟 .gitignore 一样,只是每一行后面可以加“ merge=ours",表示 出現衝突時永遠使用我的版本,“ merge=theirs" 使用别人版本

git config --global merge.ours.driver true    #开启功能