首页 文章 精选 留言 我的

精选列表

搜索[服务器],共10000篇文章
优秀的个人博客,低调大师

CentOS 7 yum在线安装Java Web服务器环境(OpenJDK+Tomcat+MariaDB)

本篇教程采用yum在线安装的方式,对于不刻意要求工具版本的情况,采用yum安装的方式将方便快捷很多。 打开网络 在VMware中成功安装CentOS 7.4后,首先需要将网络设置为开机自动启动: cd /etc/sysconfig/network-scripts vi ifcfg-ens33 将ONBOOT由no改为yes :wq systemctl restart network重启网络 Xshell连接 ip addr查看ip,根据ip连接xshell 安装OpenJDK 搜索JDK有哪些可安装的版本 yum search jdk 选择版本进行安装,这里选择OpenJDK Runtime Environment,例如: yum -y install java-1.8.0-openjdk.x86_64 查看是否安装成功 java -version 安装Tomcat 搜索Tomcat有哪些可安装的版本 yum search tomcat 选择版本进行安装,这里选择tomcat.noarch: yum -y install tomcat.noarch 启动Tomcat systemctl start tomcat 设置开机自启: systemctl enable tomcat 检查状态: systemctl status tomcat -l 这时主机无法访问到VMware中Tomcat的主页,原因在于CentOS启用了防火墙,我们需要将8080端口开放出来,注意CentOS 7防火墙采用了firewall而不是之前版本的iptables,命令如下: firewall-cmd --zone=public --add-port=8080/tcp --permanent systemctl restart firewalld重启防火墙 安装MariaDB 搜索MariaDB有哪些可安装的版本 yum search mariadb 选择版本进行安装,这里选择mariadb-server.x86_64: yum -y install mariadb-server.x86_64 开启数据库: systemctl start mariadb 设置开机启动: systemctl enable mariadb 检查状态: systemctl status mariadb -l 进入安全配置向导 mysql_secure_installation Enter current password for root (enter for none): 没有密码,直接回车 Set root password? [Y/n] 输入y,设置root密码 New password: 输入密码 Re-enter new password: 再次输入 Remove anonymous users? [Y/n] 输入y,移除匿名用户 Disallow root login remotely? [Y/n] 输入n,可以使用root用户远程连接 Remove test database and access to it? [Y/n] 输入y,删除test数据库 Reload privilege tables now? [Y/n] 输入y,立即刷新权限表 登录数据库: mysql -u root -p 输入root密码,然后设置远程主机登录,注意下面的password改成你的root密码: GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES;刷新权限表 \q退出数据库 这里我们需要开放3306端口,才能远程主机进行登录: firewall-cmd --zone=public --add-port=3306/tcp --permanent systemctl restart firewalld重启防火墙

优秀的个人博客,低调大师

使用Python模拟设备接入阿里云物联网的MQTT服务器

前言 由于阿里云物联网套件关于设备认证的文档不够详细,笔者差不多摸索了几天才连接上MQTT。下面是使用Python模拟设备接入阿里云的MQTT。 概述 阿里云物联网套件提供两种接入方式: MQTT客户端域名直连(资源受限设备推荐) 先HTTPS发送授权后再连接MQTT(一些特殊增值服务,比如设备级别的引流) 本文主要介绍第一种接入方式,TCP直连,并提供Python代码示例。 主要参数 连接域名 <ProductKey>.iot-as-mqtt.cn-shanghai.aliyuncs.com:1883 MQTT Connect报文参数 1、mqttClientId mqttClientId = "<ClientId>"+"|securemode=3,signmethod=hmacsha1,timestamp=132323232|" 2、mqttUsername 使用&拼接<DeviceName>和<ProductKey>。 mqttUsername = "<DeviceName>&<ProductKey>" 3、mqttPassword 把以下参数按字典键名排序,再把键名都拼接起来(没有分隔符)生成content,然后以DeviceSecret为盐,对content进行hma_sha1加密,最后二进制转为十六进制字符串表示。 clientId deviceName productKey timestamp mqttPassword = hmac_sha1(DeviceSecret, content).toHexString(); 示例 假设 clientId = 12345 deviceName = device productKey = pk timestamp = 789 signmethod = hmacsha1 content拼接结果:clientId12345deviceNamedeviceproductKeypktimestamp789 注意:不用拼接signmethod参数。 对content以DeviceSecret为盐进行hmacsha1加签后,再转为十六进制字符串,最后结果:FAFD82A3D602B37FB0FA8B7892F24A477F851A14 注意:不需要base64。 最后总结一下生成的参数: mqttHost = pk.iot-as-mqtt.cn-shanghai.aliyuncs.com mqttPort = 1883 mqttClientId = 12345|securemode=3,signmethod=hmacsha1,timestamp=789| mqttUsername = device&pk mqttPassword = FAFD82A3D602B37FB0FA8B7892F24A477F851A14 参数说明 参数 描述 ProductKey 产品Key。从iot套件控制台获取 DeviceName 设备名称。从iot套件控制台获取 DeviceSecret 设别密码,从iot套件控制台获取 signmethod 算法类型,hmacmd5或hmacsha1 clientId 客户端自表示id,建议mac或sn timestamp 当前时间毫秒值,可选 securemode 目前安全模式,可选值有2 (TLS直连模式)、3(TCP直连模式) 示例代码 填写自己的ProductKey、ClientId、DeviceName、DeviceSecret。 # coding=utf-8 # !/usr/bin/python3 import datetime import time import hmac import hashlib import math TEST = 0 ProductKey = "" ClientId = "12345" # 自定义clientId DeviceName = "" DeviceSecret = "" # signmethod signmethod = "hmacsha1" # signmethod = "hmacmd5" # 当前时间毫秒值 us = math.modf(time.time())[0] ms = int(round(us * 1000)) timestamp = str(ms) data = "".join(("clientId", ClientId, "deviceName", DeviceName, "productKey", ProductKey, "timestamp", timestamp )) # print(round((time.time() * 1000))) print("data:", data) if "hmacsha1" == signmethod: ret = hmac.new(bytes(DeviceSecret, encoding="utf-8"), bytes(data, encoding="utf-8"), hashlib.sha1).hexdigest() elif "hmacmd5" == signmethod: ret = hmac.new(bytes(DeviceSecret, encoding="utf-8"), bytes(data, encoding="utf-8"), hashlib.md5).hexdigest() else: raise ValueError sign = ret print("sign:", sign) # ====================================================== strBroker = ProductKey + ".iot-as-mqtt.cn-shanghai.aliyuncs.com" port = 1883 client_id = "".join((ClientId, "|securemode=3", ",signmethod=", signmethod, ",timestamp=", timestamp, "|")) username = "".join((DeviceName, "&", ProductKey)) password = sign print("="*30) print("client_id:", client_id) print("username:", username) print("password:", password) print("="*30) def secret_test(): DeviceSecret = "secret" data = "clientId12345deviceNamedeviceproductKeypktimestamp789" ret = hmac.new(bytes(DeviceSecret, encoding="utf-8"), bytes(data, encoding="utf-8"), hashlib.sha1).hexdigest() print("test:", ret) # ====================================================== # MQTT Initialize.-------------------------------------- try: import paho.mqtt.client as mqtt except ImportError: print("MQTT client not find. Please install as follow:") print("git clone http://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.python.git") print("cd org.eclipse.paho.mqtt.python") print("sudo python setup.py install") # ====================================================== def on_connect(mqttc, obj, rc): print("OnConnetc, rc: " + str(rc)) mqttc.subscribe("test", 0) def on_publish(mqttc, obj, mid): print("OnPublish, mid: " + str(mid)) def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: " + str(mid) + " " + str(granted_qos)) def on_log(mqttc, obj, level, string): print("Log:" + string) def on_message(mqttc, obj, msg): curtime = datetime.datetime.now() strcurtime = curtime.strftime("%Y-%m-%d %H:%M:%S") print(strcurtime + ": " + msg.topic + " " + str(msg.qos) + " " + str(msg.payload)) on_exec(str(msg.payload)) def on_exec(strcmd): print("Exec:", strcmd) strExec = strcmd # ===================================================== if __name__ == '__main__': if TEST: secret_test() exit(0) mqttc = mqtt.Client(client_id) mqttc.username_pw_set(username, password) mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe mqttc.on_log = on_log mqttc.connect(strBroker, port, 120) mqttc.loop_forever() 参考资料 阿里云物联网套件 > 设备端接入手册 > 设备基于MQTT接入 > 设备认证 终于知道之前为什么总是连接不上了!!!之前文档对password加密的字段是多了「signmethodhmacsha1」字符串!

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册