WSL2设置运行级别

sudo bash -c “echo ‘[1] [00053] [~~ ] [runlevel] [~ ] [5.4.91-microsoft-standard-WSL2] [0.0.0.0 ] [2021-04-05T23:10:15,040218+00:00]’ | utmpdump -r > /var/run/utmp” 2> /dev/null

红色字体运行 uname -a 查看

此方案只是消除提示对系统没有任何修正

WSL2中设置自启服务及IP映射

  1. 子系统中编写启动服务脚本

    sudo vim /etc/init.wsl
    例如:
    #! /bin/sh
    # 设置启动服务
    #! /bin/sh
    NUM=`ps -aux | grep mysqld | wc -l`; if [ $NUM -eq 1 ];then service mysql start; fi
    NUM=`ps -aux | grep postgresql | wc -l`; if [ $NUM -eq 1 ];then service postgresql start; fi
    echo ‘ok’

  2. 设置脚本执行权限

    sudo chmod +x /etc/init.wsl

  3. windows中设置(新建wsl2.bat,放在c盘根目录下)

    @echo off
    setlocal enabledelayedexpansionwsl -d Ubuntu-20.04 -u root /etc/init.wsl | findstr “ok” > nul
    if !errorlevel! equ 0 (
    :: set wsl2 ip
    wsl -d Ubuntu-20.04 -u root ip addr | findstr “192.168.169.2” > nul
    if !errorlevel! neq 0 (
    wsl -u root ip addr add 192.168.169.2/28 broadcast 192.168.169.15 dev eth0 label eth0:1
    ):: set windows ip
    ipconfig | findstr “192.168.169.1” > nul
    if !errorlevel! neq 0 (
    netsh interface ip add address “vEthernet (WSL)” 192.168.169.1 255.255.255.240
    )
    )

    window IP:192.168.169.1      wsl2 IP:192.168.169.2

  4. 设置idea编辑器Terminal(设置idea快捷键为管理员启动)

    cmd /k c:\\wsl2.bat && wsl

Debian/Ubuntu安装MariaDB

  1. 安装

    sudo apt update

    sudo apt install mariadb-server

  2. 启动

    sudo service mysql start

  3. 配置

    sudo mysql

    use mysql

    grant all privileges on *.* to ‘root’@’%’ identified by ‘password’;

    flush privileges;

    select user,host,password from user;

     

  4. 修改配置

    sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf

    注释 bind-address            = 127.0.0.1

  5. 重启服务

    sudo service mysql restart

  6. 卸载

    sudo apt-get purge mariadb-*

    选择Yes

  7. 数据库重置

    mysql_secure_installation

Debian/Ubuntu安装PostgreSQL

  1. 安装
    apt-get install postgresql-11
  2. 配置外网访问
    1. 编辑/etc/postgresql/11/main/pg_hba.conf

      # IPv4 local connections:
      host all all 127.0.0.1/32 md5

      修改成

      host all all 0.0.0.0/0 md5

      这个文档上面有介绍,0.0.0.0/0表示允许所有ip

    2. 编辑/etc/postgresql/11/main/postgresql.conf

      #——————————————————————————
      # CONNECTIONS AND AUTHENTICATION
      #——————————————————————————

      # – Connection Settings –

      # listen_addresses = ‘localhost’          # what IP address(es) to listen on;
      # comma-separated list of addresses;
      # defaults to ‘localhost’; use ‘*’ for all
      # (change requires restart)
      修改为

      listen_addresses = ‘*’

      把注释去掉,改localhost为星号。文档已经说了,默认是监听本地,如果需要监听其他连接,改成星号(*),表示监听所有,需要重启服务或系统

  3. 设置管理数据库密码
    #进入postgres默认用户
    sudo su - postgres
    
    #进入数据库
    psql
    
    #修改密码
    \password postgres
  4. 启动

    sudo service postgresql start   或者   sudo pg_ctlcluster 11 main start

  5. 卸载

    sudo apt-get purge postgresql*

puppeteer(chromium)如何安装依赖

centos依赖包

 

sudo yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 ipa-gothic-fonts xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc -y

 

ubuntu依赖包
sudo apt-get install libappindicator1 libappindicator3-1 libasound2 libatk1.0-0 libc6 libcairo2 libcap2 libcups2 libexpat1 libffi6 libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0 libgtk2.0-0 libgtk-3-0 libpam0g libpango1.0-0 libpci3 libpcre3 libpixman-1-0 libspeechd2 libstdc++6 libsqlite3-0 libuuid1 libwayland-egl1-mesa libx11-6 libx11-xcb1 libxau6 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxinerama1 libxrandr2 libxrender1 libxtst6 zlib1g

sshd: no hostkeys available — exiting

在开启SSHD服务时报错.
sshd re-exec requires execution with an absolute path
用绝对路径启动,也报错如下:
Could not load host key: /etc/ssh/ssh_host_key
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Disabling protocol version 1. Could not load host key
Disabling protocol version 2. Could not load host key
sshd: no hostkeys available — exiting
解决过程:

#ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
#ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
#/usr/sbin/sshd

如果上述两个文件存在,仍然出现这个错误,那么试试 chmod 600 上述两个文件。之后应该可以解决。

在CentOS 7系统上安装PHP 7.4版本的方法

一、添加EPEL和REMI存储库
运行以下命令以添加所需的存储库:

sudo yum install epel-release
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

二、在CentOS 7上安装PHP 7.4版本
我们现在可以启用PHP 7.4 Remi存储库并在CentOS 7上安装PHP 7.4:

sudo yum -y install yum-utils
yum repolist all |grep php
sudo yum-config-manager –enable remi-php74

在CentOS 7上安装PHP 7.4 以及扩展:

sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis php-memcached php-pnctl php-posix php-eio php-sockets php-ev

当前的PHP版本应为7.4版,如下所示:

php -v

如果要查看启用的模块,请运行:

php –modules

至此,你已经在CentOS 7上成功安装了PHP 7.4,欢迎使用此版本进行PHP开发/测试。

控制台颜色格式控制符

预设字体颜色控制

none = “\033[0m”
black = “\033[0;30m”
dark_gray = “\033[1;30m”
blue = “\033[0;34m”
light_blue = “\033[1;34m”
green = “\033[0;32m”
light_green -= “\033[1;32m”
cyan = “\033[0;36m”
light_cyan = “\033[1;36m”
red = “\033[0;31m”
light_red = “\033[1;31m”
purple = “\033[0;35m”
light_purple = “\033[1;35m”
brown = “\033[0;33m”
yellow = “\033[1;33m”
light_gray = “\033[0;37m”
white = “\033[1;37m”

字体颜色范围

字颜色: 30–39
30: 黑
31: 红
32: 绿
33: 黄
34: 蓝
35: 紫
36: 深绿
37: 白色

字体背景颜色范围

40–49
40: 黑
41:红
42:绿
43:黄
44:蓝
45:紫
46:深绿
47:白色

特效格式控制

\033[0m 关闭所有属性
\033[1m 设置高亮度
\03[4m 下划线
\033[5m 闪烁
\033[7m 反显
\033[8m 消隐

光标位置等的格式控制

\033[nA 光标上移n行
\03[nB 光标下移n行
\033[nC 光标右移n行
\033[nD 光标左移n行
\033[y;xH设置光标位置
\033[2J 清屏
\033[K 清除从光标到行尾的内容
\033[s 保存光标位置
\033[u 恢复光标位置
\033[?25l 隐藏光标
\33[?25h 显示光标

结束控制符(及重置、none)

\033[0m

配置终端颜色

if [ `whoami` == “root” ];then
PS1=”\[\033[1;31m\]\u@\h: \[\033[0;33m\]\A \[\033[36m\]\w # \[\033[0;38m\]”
else
PS1=”\[\033[1;32m\]\u@\h: \[\033[0;33m\]\A \[\033[36m\]\w > \[\033[0;38m\]”
fi

 

 

Ubuntu安装supervisor及服务配置

1.安装supervisor服务

sudo apt-get install supervisor

2.启动supervisor服务

sudo service supervisor start

3.启用supervisor http服务

sudo vim /etc/supervisor/supervisord.conf

添加一下配置

[inet_http_server]

port=*:9001

username=user

password=123

4.添加自定义服务

 sudo vim /etc/supervisor/conf.d/server.conf

添加服务配置(简介配置)

[program:server]

;启动服务命令
command=/usr/bin/php /server.php start

;启动3秒后没有异常退出,就表示进程正常启动了,默认为1秒
startsecs=3

;启动服务用户
user=root

;在supervisord启动的时候也自动启动
autostart=true

;程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
autorestart=true

;stdout 日志文件大小,默认50MB
stdout_logfile_maxbytes=20MB

; stdout 日志文件备份数,默认是10
stdout_logfile_backups=7

;stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
stdout_logfile=/tmp/supervisor.log

;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
stopasgroup=true

;默认为false,向进程组发送kill信号,包括子进程
killasgroup=true

5.重启supervisor服务

sudo service supervisor restart

6.访问http服务管理进程

http://127.0.0.1:9001

以下为完整配置

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
; – Shell expansion (“~” or “$HOME”) is not supported. Environment
; variables can be expanded using this syntax: “%(ENV_HOME)s”.
; – Quotes around values are not supported, except in the case of
; the environment= options as shown below.
; – Comments must have a leading space: “a=b ;comment” not “a=b;comment”.
; – Command will be truncated if it looks like a config file comment, e.g.
; “command=bash -c ‘foo ; bar'” will truncate to “command=bash -c ‘foo “.
[unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
;chmod=0700 ; socket file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; default is no username (open server)
;password=123 ; default is no password (open server)
;[inet_http_server] ; inet (TCP) server disabled by default
;port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface
;username=user ; default is no username (open server)
;password=123 ; default is no password (open server)
[supervisord]
logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10 ; # of main logfile backups; 0 means none, default 10
loglevel=info ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false ; start in foreground if true; default false
minfds=1024 ; min. avail startup file descriptors; default 1024
minprocs=200 ; min. avail process descriptors;default 200
;umask=022 ; process file creation umask; default 022
;user=chrism ; default is current user, required if root
;identifier=supervisor ; supervisord identifier, default is ‘supervisor’
;directory=/tmp ; default is not to cd during start
;nocleanup=true ; don’t clean up tempfiles at start; default false
;childlogdir=/tmp ; ‘AUTO’ child log dir, default $TEMP
;environment=KEY=”value” ; key value pairs to add to environment
;strip_ansi=false ; strip ansi escape codes in logs; def. false
; The rpcinterface:supervisor section must remain in the config file for
; RPC (supervisorctl/web interface) to work. Additional interfaces may be
; added by defining them in separate [rpcinterface:x] sections.
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
; The supervisorctl section configures how supervisorctl will connect to
; supervisord. configure it match the settings in either the unix_http_server
; or inet_http_server section.
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as in [*_http_server] if set
;password=123 ; should be same as in [*_http_server] if set
;prompt=mysupervisor ; cmd line prompt (default “supervisor”)
;history_file=~/.sc_history ; use readline history if available
; The sample program section below shows all possible program subsection values.
; Create one or more ‘real’ program: sections to be able to control them under
; supervisor.
[program:test123]
command=/usr/bin/python /home/wangzhe/test1.py ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1 ; number of processes copies to start (def 1)
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask=022 ; umask for process (default None)
;priority=999 ; the relative start priority (default 999)
;autostart=true ; start at supervisord start (default: true)
;startsecs=1 ; # of secs prog must stay up to be running (def. 1)
;startretries=3 ; max # of serial start failures when starting (default 3)
;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
;exitcodes=0,2 ; ‘expected’ exit codes used with autorestart (default 0,2)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=true ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
;stdout_capture_maxbytes=1MB ; number of bytes in ‘capturemode’ (default 0)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
;stderr_capture_maxbytes=1MB ; number of bytes in ‘capturemode’ (default 0)
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A=”1″,B=”2″ ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils)
; The sample eventlistener section below shows all possible eventlistener
; subsection values. Create one or more ‘real’ eventlistener: sections to be
; able to handle event notifications sent by supervisord.
;[eventlistener:theeventlistenername]
;command=/bin/eventlistener ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1 ; number of processes copies to start (def 1)
;events=EVENT ; event notif. types to subscribe to (req’d)
;buffer_size=10 ; event buffer queue size (default 10)
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask=022 ; umask for process (default None)
;priority=-1 ; the relative start priority (default -1)
;autostart=true ; start at supervisord start (default: true)
;startsecs=1 ; # of secs prog must stay up to be running (def. 1)
;startretries=3 ; max # of serial start failures when starting (default 3)
;autorestart=unexpected ; autorestart if exited after running (def: unexpected)
;exitcodes=0,2 ; ‘expected’ exit codes used with autorestart (default 0,2)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A=”1″,B=”2″ ; process environment additions
;serverurl=AUTO ; override serverurl computation (childutils)
; The sample group section below shows all possible group values. Create one
; or more ‘real’ group: sections to create “heterogeneous” process groups.
;[group:thegroupname]
;programs=progname1,progname2 ; each refers to ‘x’ in [program:x] definitions
;priority=999 ; the relative start priority (default 999)
; The [include] section can just contain the “files” setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
;[include]
;files = relative/directory/*.ini