Joyber 发布的文章

deepin默认sshd服务是没有开启22端口的,我们需要手动开启,开启的方法如下:

输入命令查看22端口是否开放

sudo lsof -i:22

查看22端口是否开放,无返回信息,则表示没有开放;

使用vim命令编辑配置文件

sudo vim /etc/ssh/sshd_config

将内容中的如下两行的注释去掉

#Port 22

#ListenAddress 0.0.0.0

保存退出

重启ssh

sudo /etc/init.d/ssh restart

再次使用命令查看端口是否开发

sudo lsof -i:22,

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
sshd    34720 root    3u  IPv4 182647      0t0  TCP *:ssh (LISTEN)

显示上面的信息说明以开放,试试是否可以远程登录

Matplotlib 是 Python 中类似 MATLAB 的绘图工具,但在python3中引入Matplotlib ,我遇到几次报错,在此记录一下。
源码如下:

import pandas as pd
import matplotlib.pyplot as plt

air_quality = pd.read_csv("air_quality_no2.csv", index_col=0, parse_dates=True)
print(f'打印空气质量表:\n {air_quality}')

plt.plot(air_quality)
plt.show()

报错一:Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

解决方案:在引入Matplotlib后加入语句matplotlib.use('TkAgg'),注意要在末尾加,代码如下。

import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('TkAgg')  # 加在末尾

air_quality = pd.read_csv("air_quality_no2.csv", index_col=0, parse_dates=True)
print(f'打印空气质量表:\n {air_quality}')

plt.plot(air_quality)
plt.show()

报错二:如上加上matplotlib.use('TkAgg'),不在报之前的错误了
而是报了另一个错误ModuleNotFoundError: No module named 'tkinter''

解决方案:通常这种报错,只要安装并引入相应的包就能解决问题,但是在PyCharm添加软件包中并没有搜索到tkinter包,在终端使用命令pip3 install tkinter来安装,也提示没有这个软件包。

网络搜索了下发现,可以使用如下方法安装:sudo apt install python3-tk,安装之前可以通过命令sudo apt search python3-tk 进行查询是否已经安装过。

安装完成后,重新执行代码,就能正常生成图形了。

在IP后面直接加上 .nip.io 就可以指向该IP访问了,比如 15.165.175.249.nip.io 就会指向这个IP,绑定域名到网站就可以访问

nip.io
Dead simple wildcard DNS for any IP Address
Stop editing your etc/hosts file with custom hostname and IP address mappings.

nip.io allows you to do that by mapping any IP Address to a hostname using the following formats:

Without a name:

10.0.0.1.nip.io maps to 10.0.0.1
192-168-1-250.nip.io maps to 192.168.1.250
0a000803.nip.io maps to 10.0.8.3
With a name:

app.10.8.0.1.nip.io maps to 10.8.0.1
app-116-203-255-68.nip.io maps to 116.203.255.68
app-c0a801fc.nip.io maps to 192.168.1.252
customer1.app.10.0.0.1.nip.io maps to 10.0.0.1
customer2-app-127-0-0-1.nip.io maps to 127.0.0.1
customer3-app-7f000101.nip.io maps to 127.0.1.1
nip.io maps <anything>[.-]<IP Address>.nip.io in "dot", "dash" or "hexadecimal" notation to the corresponding <IP Address>:

dot notation: magic.127.0.0.1.nip.io
dash notation: magic-127-0-0-1.nip.io
hexadecimal notation: magic-7f000001.nip.io
The "dash" and "hexadecimal" notation is especially useful when using services like LetsEncrypt as it's just a regular sub-domain of nip.io

About this service
nip.io is powered by PowerDNS with a simple, custom PipeBackend written in Python: backend.py

It's open source, licensed under Apache 2.0: https://github.com/exentriquesolutions/nip.io — pull requests are welcome.

This is a free service provided by Exentrique Solutions (the same people who run XP-Dev.com which offer Git, Mercurial and Subversion hosting).

Feedback is appreciated, just raise an issue in GitHub .

Troubleshooting
DNS Rebinding Protection
Some DNS resolvers, forwarders and routers have DNS rebinding protection which may result in failure to resolve local and private IP addresses. This service won't work in those situations.

Related Services
localtls: A DNS server in Python3 to provide TLS to webservices on local addresses. It resolves addresses such as '192-168-0-1.yourdomain.net' to 192.168.0.1 and has a valid TLS certificate for them.
sslip.io: Alternative to this service, supports IPv6 and custom domains.
local.gd: Alternative to this service, where everything is mapped to localhost/127.0.0.1.

<html>
 
<head>
<title>HTML显示json字符串并且进行格式化</title>
</head>
 
<body>
<p id="show_p">{ "name": "Brett", "address":"北京路23号", "email": "123456@qq.com" }</p>
<pre id="out_pre"></pre>
 
</body>
<script type="text/javascript">
 
  var text = document.getElementById('show_p').innerText; //获取json格式内容
  
   var result = JSON.stringify(JSON.parse(text), null, 2);//将字符串转换成json对象
 
   document.getElementById('out_pre').innerText= result ;
  
 
</script>
 
</html>

安装 supervisor

sudo pip2.7 install supervisor

查看 supervisor 的最新版本和文件列表

pip2.7 show -f supervisor

可以看到 Location 是 /usr/local/lib/python2.7/site-packages,和Files的前几个文件

  ../../../bin/echo_supervisord_conf
  ../../../bin/pidproxy
  ../../../bin/supervisorctl
  ../../../bin/supervisord

其中../../../相对路径/usr/local/lib/python2.7/site-packages得到绝对路径是:/usr/local
那前四个文件的绝对路径是:

/usr/local/bin/echo_supervisord_conf
/usr/local/bin/pidproxy
/usr/local/bin/supervisorctl
/usr/local/bin/supervisord

生成 supervisor 的配置文件

echo_supervisord_conf | sudo tee /etc/supervisord.conf

如果是root用户可以用

echo_supervisord_conf > /etc/supervisord.conf

如果提示 -bash: echo_supervisord_conf: command not found说明/usr/local/bin没有添加到visudo的secure_path内,解决方法是:

编辑visudo

sudo visudo

找到 secure_path这一行

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

添加/usr/local/sbin和/usr/local/bin,变成这样

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

保存编辑即可

创建一个配置文件夹,多个服务的配置文件单独放置

sudo mkdir -p /etc/supervisor.d

修改配置文件

sudo vim /etc/supervisord.conf

找到 ;[include]去掉;变成[include]

找到[include]下面的;files去掉;变成files

将files = relative/directory/.ini改成files = /etc/supervisor.d/.conf

其它配置默认即可,保存修改

添加 /etc/init.d/supervisor 开机启动

sudo vim /etc/init.d/supervisord

添加内容:

#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord

# Source init functions
. /etc/rc.d/init.d/functions

prog="supervisord"

prefix="/usr/local"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord"
PIDFILE="/var/run/$prog.pid"
conf="/etc/supervisord.conf"

start()
{
        echo -n $"Starting $prog: "
        daemon $prog_bin --pidfile $PIDFILE -c $conf
        [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
        echo
}

stop()
{
        echo -n $"Shutting down $prog: "
        [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
        echo
}

case "$1" in

  start)
    start
  ;;

  stop)
    stop
  ;;

  status)
        status $prog
  ;;

  restart)
    stop
    start
  ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}"
  ;;

esac

增加可执行权限

sudo chmod +x /etc/init.d/supervisord

centos 添加开机启动

sudo chkconfig --add supervisord
sudo chkconfig --level 2345 supervisord on

启动 supervisord

sudo /etc/init.d/supervisord start