无法访问raw.githubusercontent.com的解决

我们难免不会访问raw.githubusercontent.com,但因种种因素,国内很难访问这个站点,以下方法可能帮助到你:
https://ip.cn/ip/raw.githubusercontent.com.html
查找到ip为185.199.108.133
sudo nano /etc/hosts
添加
185.199.110.133 raw.githubusercontent.com

注:

如果是windows系统,则修改

C:\Windows\System32\drivers\etc
hosts文件

python图像边缘检测并生成svg图像

https://zhuanlan.zhihu.com/p/398237689

from typing import Iterable, List, Tuple, Union
import cv2
import matplotlib.pyplot as plt
import numpy as np
from xml.dom import minidom as md
from queue import Queue
import warnings
def look_shape(a : Iterable) -> Tuple:
    # for debug
    return np.array(a).shape
def length_within_points(a : Iterable, empty_value : Union[int, float] = 0) -> int:
    """
        a simple instance:
            array : [empty_value, empty_value, empty_value, 1, empty_value, 0, 1, 2, empty_value]
            Then length_within_points(array) will return index diff between 1 and 2, which is 5
    """
    a = list(a)
    l_pivot, r_pivot = -1, -2
    for index, (l_val, r_val) in enumerate(zip(a[::1], a[::-1])):
        if l_val != empty_value and l_pivot == -1:
            l_pivot = index
        if r_val != empty_value and r_pivot == -2:
            r_pivot = len(a) - index
    return r_pivot - l_pivot + 1
def dump_rings_from_image(image : np.ndarray, output_path : str, plot_dict : dict = {"color" : "k", "linewidth" : 0.3}, default_height : float = 8) -> List[np.ndarray]:
    # regular operation, no more explainations
    blur = cv2.GaussianBlur(image, (3, 3), 0)
    gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
    edge = cv2.Canny(gray, 50, 150)
    # get ratio between width and height to adjust the final output
    valid_width = length_within_points(edge.sum(axis=0))
    valid_height = length_within_points(edge.sum(axis=1))
    true_ratio = valid_width / valid_height
    # get contour of the edge image
    contour_tuple = cv2.findContours(edge, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
    contours = contour_tuple[0]
    rings = [np.array(c).reshape([-1, 2]) for c in contours]
    # adjust coordinate system to the image coordinate system
    max_x, max_y, min_x, min_y = 0, 0, 0, 0
    for ring in rings:
        max_x = max(max_x, ring.max(axis=0)[0])
        max_y = max(max_y, ring.max(axis=0)[1])
        min_x = max(min_x, ring.min(axis=0)[0])
        min_y = max(min_y, ring.min(axis=0)[1])
    # adjust ratio
    plt.figure(figsize=[default_height * true_ratio, default_height])
    # plot to the matplotlib
    for _, ring in enumerate(rings):
        close_ring = np.vstack((ring, ring[0]))
        xx = close_ring[..., 0]
        yy = max_y - close_ring[..., 1]
        plt.plot(xx, yy, **plot_dict)
    plt.axis("off")
    plt.savefig(output_path)
def remove_matplotlib_background(svg_file : str, bg_node_name : str = "patch_1") -> None:
    dom_tree : md.Document = md.parse(svg_file)
    svg_node = None
    # select the svg tag
    for node in dom_tree.childNodes:
        if node.nodeName == "svg":
            svg_node : md.Element = node
    if svg_node is None:
        raise ValueError("not find a svg node in {}".format(svg_file))
    # bfs svg node to find the background node
    q = Queue()
    q.put(svg_node)
    target_node = None  # we will remove the target node
    while not q.empty():
        cur : md.Node = q.get()
        if cur.hasChildNodes():
            for node in cur.childNodes:
                q.put(node)
        if hasattr(cur, "getAttribute"):
            # this is the id of the background node
            if cur.getAttribute("id") == bg_node_name:
                target_node = cur
    if target_node is None:
        warnings.warn("background node is not found, please ensure whether bg_node_name is correct")
    else:       # remove and write
        target_node.parentNode.removeChild(target_node)
        with open(svg_file, "w", encoding="utf-8") as fp:
            dom_tree.writexml(
                writer=fp,
                indent="\t"
            )
def bitmap_to_contour_svg(input_bitmap_path : str, output_svg_path : str):
    img = cv2.imread(input_bitmap_path)
    dump_rings_from_image(img, output_path=output_svg_path)
    remove_matplotlib_background(output_svg_path)
if __name__ == '__main__':
    bitmap_to_contour_svg(
        input_bitmap_path="555.png",
        output_svg_path="abc.svg"
    )

一个简单方式

from PIL import Image, ImageFilter
img = Image.open('abc.jpg')  # 打开图片文件
newimg = img.filter(ImageFilter.CONTOUR)  # 设置图片轮廓筛选器
newimg.save('轮廓效果.png', 'png')  # 保存轮廓效果的图片

数据清洗、筛选、去重、排序、提取

Mexicans were there enveloped5 in their sarapes; Chinamen in their large-sleeved tunics6, pointed7 shoes, and conical hats; one or two Kanucks from the coast; and even a sprinkling of Black Feet, Grosventres, or Flatheads, from the banks of the Trinity river.
The scene is in San Francisco, the capital of California, but not at the period when the placer-mining fever was raging—from 1849 to 1852. San Francisco was no longer what it had been then, a caravanserai, a terminus, an inn, where for a night there slept the busy men who were hastening to the gold-fields west of the Sierra Nevada. At the end of some twenty years the old unknown Yerba-Buena had given place to a town unique of its kind, peopled by 100,000 inhabitants, built under the shelter of a couple of hills, away from the shore, but stretching off to the farthest heights in the background—a city in short which has dethroned Lima, Santiago, Valparaiso, and every other rival, and which the Americans have made the queen of the Pacific, the "glory of the western coast!"
It was the 15th of May, and the weather was still cold. In California, subject as it is to the direct action of the polar currents, the first weeks of this month are somewhat similar to the last weeks of March in Central Europe. But the cold was hardly noticeable in the thick of the auction crowd. The bell with its incessant8 clangour had[Pg 3] brought together an enormous throng9, and quite a summer temperature caused the drops of perspiration10 to glisten11 on the foreheads of the spectators which the cold outside would have soon solidified12.
Do not imagine that all these folks had come to the auction-room with the intention of buying. I might say that all of them had but come to see. Who was going to be mad enough, even if he were rich enough, to purchase an isle13 of the Pacific, which the government had in some eccentric moment decided14 to sell? Would the reserve price ever be reached? Could anybody be found to work up the bidding? If not, it would scarcely be the fault of the public crier, who tried his best to tempt15 buyers by his shoutings and gestures, and the flowery metaphors16 of his harangue17. People laughed at him, but they did not seem much influenced by him.
"An island! an isle to sell!" repeated Gingrass.
"But not to buy!" answered an Irishman, whose pocket did not hold enough to pay for a single pebble18.
"An island which at the valuation will not fetch six dollars an acre!" said the auctioneer.
"And which won't pay an eighth per cent.!" replied a big farmer, who was well acquainted with agricultural speculations19.
"An isle which measures quite sixty-four miles round[Pg 4] and has an area of two hundred and twenty-five thousand acres!"
"Is it solid on its foundation?" asked a Mexican, an old customer at the liquor-bars, whose personal solidity seemed rather doubtful at the moment.
"An isle with forests still virgin20!" repeated the crier, "with prairies, hills, watercourses—"
"Warranted?" asked a Frenchman, who seemed rather inclined to nibble21.
"Yes! warranted!" added Felporg, much too old at his trade to be moved by the chaff22 of the public.
"For two years?"
"To the end of the world!"
"Beyond that?"
"A freehold island!" repeated the crier, "an island without a single noxious23 animal, no wild beasts, no reptiles24!—"
"No birds?" added a wag.
"No insects?" inquired another.
"An island for the highest bidder!" said Dean Felporg, beginning again. "Come, gentlemen, come! Have a little courage in your pockets! Who wants an island in perfect state of repair, never been used, an island in the Pacific, that ocean of oceans? The valuation is a mere25 nothing! It is put at eleven hundred thousand dollars, is there any[Pg 5] one will bid? Who speaks first? You, sir?—you, over there nodding your head like a porcelain26 mandarin27? Here is an island! a really good island! Who says an island?"
"Pass it round!" said a voice as if they were dealing28 with a picture or a vase.
And the room shouted with laughter, but not a half-dollar was bid.
However, if the lot could not be passed round, the map of the island was at the public disposal. The whereabouts of the portion of the globe under consideration could be accurately29 ascertained30. There was neither surprise nor disappointment to be feared in that respect. Situation, orientation31, outline, altitudes, levels, hydrography, climatology, lines of communication, all these were easily to be verified in advance. People were not buying a pig in a poke32, and most undoubtedly33 there could be no mistake as to the nature of the goods on sale. Moreover, the innumerable journals of the United States, especially those of California, with their dailies, bi-weeklies, weeklies, bi-monthlies, monthlies, their reviews, magazines, bulletins, &c., had been for several months directing constant attention to the island whose sale by auction had been authorized34 by Act of Congress.
The island was Spencer Island, which lies in the [Pg 6]west-south-west of the Bay of San Francisco, about 460 miles from the Californian coast, in 32° 15' north latitude35, and 145° 18' west longitude36, reckoning from Greenwich. It would be impossible to imagine a more isolated37 position, quite out of the way of all maritime38 or commercial traffic, although Spencer Island was relatively39, not very far off, and situated40 practically in American waters. But thereabouts the regular currents diverging41 to the north and south have formed a kind of lake of calms, which is sometimes known as the "Whirlpool of Fleurieu."
It is in the centre of this enormous eddy42, which has hardly an appreciable43 movement, that Spencer Island is situated. And so it is sighted by very few ships. The main routes of the Pacific, which join the new to the old continent, and lead away to China or Japan, run in a more southerly direction. Sailing-vessels would meet with endless calms in the Whirlpool of Fleurieu; and steamers, which always take the shortest road, would gain no advantage by crossing it. Hence ships of neither class know anything of Spencer Island, which rises above the waters like the isolated summit of one of the submarine mountains of the Pacific. Truly, for a man wishing to flee from the noise of the world, seeking quiet in solitude44, what could be better than this island, lost within a few hundred miles of the coast? For a voluntary Robinson Crusoe, it would[Pg 7] be the very ideal of its kind! Only of course he must pay for it.
And now, why did the United States desire to part with the island? Was it for some whim45? No! A great nation cannot act on caprice in any matter, however simple. The truth was this: situated as it was, Spencer Island had for a long time been known as a station perfectly46 useless. There could be no practical result from settling there. In a military point of view it was of no importance, for it only commanded an absolutely deserted47 portion of the Pacific. In a commercial point of view there was a similar want of importance, for the products would not pay the freight either inwards or outwards48. For a criminal colony it was too far from the coast. And to occupy it in any way, would be a very expensive undertaking49. So it had remained deserted from time immemorial, and Congress, composed of "eminently50 practical" men, had resolved to put it up for sale—on one condition only, and that was, that its purchaser should be a free American citizen. There was no intention of giving away the island for nothing, and so the reserve price had been fixed51 at $1,100,000. This amount for a financial society dealing with such matters was a mere bagatelle52, if the transaction could offer any advantages; but as we need hardly repeat, it offered none, and competent men[Pg 8] attached no more value to this detached portion of the United States, than to one of the islands lost beneath the glaciers53 of the Pole.
In one sense, however, the amount was considerable. A man must be rich to pay for this hobby, for in any case it would not return him a halfpenny per cent. He would even have to be immensely rich for the transaction was to be a "cash" one, and even in the United States it is as yet rare to find citizens with $1,100,000 in their pockets, who would care to throw them into the water without hope of return.
And Congress had decided not to sell the island under the price. Eleven hundred thousand dollars, not a cent less, or Spencer Island would remain the property of the union.
It was hardly likely that any one would be mad enough to buy it on the terms.
Besides, it was expressly reserved that the proprietor54, if one offered, should not become king of Spencer Island, but president of a republic. He would gain no right to have subjects, but only fellow-citizens, who could elect him for a fixed time, and would be free from re-electing him indefinitely. Under any circumstances he was forbidden to play at monarchy55. The union could never tolerate the foundation of a kingdom, no matter how small, in American waters.
[Pg 9]
This reservation was enough to keep off many an ambitious millionaire, many an aged56 nabob, who might like to compete with the kings of the Sandwich, the Marquesas, and the other archipelagoes of the Pacific.
In short, for one reason or other, nobody presented himself. Time was getting on, the crier was out of breath in his efforts to secure a buyer, the auctioneer orated without obtaining a single specimen57 of those nods which his estimable fraternity are so quick to discover; and the reserve price was not even mentioned.
However, if the hammer was not wearied with oscillating above the rostrum, the crowd was not wearied with waiting around it. The joking continued to increase, and the chaff never ceased for a moment. One individual offered two dollars for the island, costs included. Another said that a man ought to be paid that for taking it.
And all the time the crier was heard with,—
"An island to sell! an island for sale!"

数据清洗、筛选、去重、排序、提取


import re
#a='Beautiful, is; better*than\nugly'
a='Mexicans were there enveloped5 in their sarapes; Chinamen in their large-sleeved tunics6, pointed7 shoes, and conical hats; one or two Kanucks from the coast; and even a sprinkling of Black Feet, Grosventres, or Flatheads, from the banks of the Trinity river.The scene is in San Francisco, the capital of California, but not at the period when the placer-mining fever was raging—from 1849 to 1852. San Francisco was no longer what it had been then, a caravanserai, a terminus, an inn, where for a night there slept the busy men who were hastening to the gold-fields west of the Sierra Nevada. At the end of some twenty years the old unknown Yerba-Buena had given place to a town unique of its kind, peopled by 100,000 inhabitants, built under the shelter of a couple of hills, away from the shore, but stretching off to the farthest heights in the background—a city in short which has dethroned Lima, Santiago, Valparaiso, and every other rival, and which the Americans have made the queen of the Pacific, the "glory of the western coast!"It was the 15th of May, and the weather was still cold. In California, subject as it is to the direct action of the polar currents, the first weeks of this month are somewhat similar to the last weeks of March in Central Europe. But the cold was hardly noticeable in the thick of the auction crowd. The bell with its incessant8 clangour had[Pg 3] brought together an enormous throng9, and quite a summer temperature caused the drops of perspiration10 to glisten11 on the foreheads of the spectators which the cold outside would have soon solidified12.Do not imagine '
# 四个分隔符为:,  ;  *  \n
x= re.split(' |,|; |\*|\n',a)
for t in x:
    print(t)

去重、排序

import re
#a='Beautiful, is; better*than\nugly'
a='Mexicans were there enveloped5 in their sarapes; Chinamen in their large-sleeved tunics6, pointed7 shoes, and conical hats; one or two Kanucks from the coast; and even a sprinkling of Black Feet, Grosventres, or Flatheads, from the banks of the Trinity river.The scene is in San Francisco, the capital of California, but not at the period when the placer-mining fever was raging—from 1849 to 1852. San Francisco was no longer what it had been then, a caravanserai, a terminus, an inn, where for a night there slept the busy men who were hastening to the gold-fields west of the Sierra Nevada. At the end of some twenty years the old unknown Yerba-Buena had given place to a town unique of its kind, peopled by 100,000 inhabitants, built under the shelter of a couple of hills, away from the shore, but stretching off to the farthest heights in the background—a city in short which has dethroned Lima, Santiago, Valparaiso, and every other rival, and which the Americans have made the queen of the Pacific, the "glory of the western coast!"It was the 15th of May, and the weather was still cold. In California, subject as it is to the direct action of the polar currents, the first weeks of this month are somewhat similar to the last weeks of March in Central Europe. But the cold was hardly noticeable in the thick of the auction crowd. The bell with its incessant8 clangour had[Pg 3] brought together an enormous throng9, and quite a summer temperature caused the drops of perspiration10 to glisten11 on the foreheads of the spectators which the cold outside would have soon solidified12.Do not imagine '
# 四个分隔符为:,  ;  *  \n
x= re.split(' |,|; |\*|\n',a)
lista=list(set(x))
lista.sort(key=len)
for t in sorted(lista,key = len):
    print(t)

朋途-putug

http域名:uza3jlgx.hk.wknwct.top:80(绑定内网80端口,用于建站)

面板域名:uza3jlgxmb.hk.wknwct.top:80(绑定内网8888端口,用于访问面板)

Https域名:uza3jlgxs.hk.wknwct.top:443(需要开启并部署证书,未开启默认http端口)

Phpmyadmin:uza3jlgxsql.hk.wknwct.top:80/phpmyadmin_ba74697dda5af6e2 (绑定内网888端口,用于数据库管理)

SSH端口:8613(默认绑定内网22端口,用于远程链接服务器,地址为赠送或绑定的域名)

数据库端口:38613(默认绑定内网3306端口,用于远程数据库链接,地址为赠送或绑定的域名)

提示信息:请绑定自己的域名。香港线路,三网双程直连 国内访问速度飞快, 无防机房,被攻击封一小时IP

再Centos7上安装python3

第一步:安装相关依赖包和编译环境

$>yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc

(注意:这一步很重要,如果不安装相关依赖包,在使用pip安装python包时会报找不到SSL错误!)

第二步:下载python3.8.0安装包

$>wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz

第三步:解压安装包并创建安装目录

$>xz -d Python-3.8.0.tar.xz

$>tar -xvf Python-3.8.0.tar

$>mkdir /usr/local/python3.8.0

第四步:编译安装

$>cd Python-3.8.0

$>./configure –with-ssl –prefix=/usr/local/python3.8.0

(注意:prefix后面配置第三步中创建的路径,且等号两边不能有空格,不然会报错)

$>make && make install

第五步:创建python3.6.5软链接

$>ln -s /usr/local/python3.8.0/bin/python3.8 /usr/bin/python3

$>ln -s /usr/local/python3.8.0/bin/pip3.8 /usr/bin/pip3

$>pip3 install –upgrade pip(升级pip3)

第六步:修改python2.7.5软链接(这一步可有可无)

$>mv /usr/bin/python /usr/bin/python2

第七步:验证,使用python3进入python3.8.0命令行

$>python3

Centos7系统编译安装PHP7.4

最近买了个盒子,拆开一看是用了一家已经倒闭的某公司的产品,拆了板子重新烧录了Centos7系统装了宝塔再加了个新壳子,首先应该肯定的是卖家会做生意,不敢苟同的是里面一堆坑要踩,当然想买这种板子的人都是爱折腾的,估计卖家也是吃准了这一点。我一个centos新手(拿到这个盒子之前从来没摸过centos)被折腾的够呛,本来买盒子就一个目的,架一个个人博客(当然选wordpress),结果盒子自带的php版本太低,wordpress直接警告,随后按卖家文档升级,于是坑一个接一个。。。。。说说多了,最后总结,这玩意只能编译安装,步骤如下:
安装依赖包
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel
下载安装包
wget https://www.php.net/distributions/php-7.4.10.tar.gz
解压
tar -xf php-7.4.10.tar.gz
进入目录
cd php-7.4.10
安装配置
./configure \
--prefix=/usr/local/php7.1.33 \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
编译安装
make && make install

Centos8 编译安装 PHP 8.1.0 – 简书 (jianshu.com)

如果是源码安装,先运行./configure,生成makefile,再执行make,即可正常运行

Centos8 编译安装 PHP 8.1.0

安装工具包

yum -y install libtool automake libzip-devel epel-release libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel uuid libuuid-devel gcc bzip2 bzip2-devel gmp-devel  readline-devel libxslt-devel autoconf bison gcc gcc-c++ sqlite-devel cmake

下载安装 oniguruma

wget -c https://github.com/kkos/oniguruma/archive/refs/tags/v6.9.7.1.tar.gz
tar -zxvf v6.9.7.1.tar.gz
cd oniguruma-6.9.7.1
./autogen.sh && ./configure --prefix=/usr
make && make install

下载安装 php 8.1.0

wget -c  https://www.php.net/distributions/php-8.1.0.tar.gz
tar -zxvf php-8.1.0.tar.gz
cd php-8.1.0
./configure \
--prefix=/opt/php/8.1.0 \
--with-config-file-path=/opt/php/8.1.0/etc \
--with-config-file-scan-dir=/opt/php/8.1.0/etc/conf.d \
--enable-fpm \
--enable-soap \
--with-openssl \
--with-openssl-dir \
--with-zlib \
--with-iconv \
--with-bz2 \
--enable-gd \
--with-jpeg \
--with-freetype \
--with-curl \
--enable-dom \
--with-xml \
--with-zip \
--enable-mbstring \
--enable-pdo \
--with-pdo-mysql \
--with-zlib-dir \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-xsl \
--enable-mysqlnd \
--with-mysqli \
--without-pear \
--disable-short-tags
make && make install
Installing shared extensions:     /opt/php/8.1.0/lib/php/extensions/no-debug-non-zts-20210902/
Installing PHP CLI binary:        /opt/php/8.1.0/bin/
Installing PHP CLI man page:      /opt/php/8.1.0/php/man/man1/
Installing PHP FPM binary:        /opt/php/8.1.0/sbin/
Installing PHP FPM defconfig:     /opt/php/8.1.0/etc/
Installing PHP FPM man page:      /opt/php/8.1.0/php/man/man8/
Installing PHP FPM status page:   /opt/php/8.1.0/php/php/fpm/
Installing phpdbg binary:         /opt/php/8.1.0/bin/
Installing phpdbg man page:       /opt/php/8.1.0/php/man/man1/
Installing PHP CGI binary:        /opt/php/8.1.0/bin/
Installing PHP CGI man page:      /opt/php/8.1.0/php/man/man1/
Installing build environment:     /opt/php/8.1.0/lib/php/build/
Installing header files:          /opt/php/8.1.0/include/php/
Installing helper programs:       /opt/php/8.1.0/bin/
  program: phpize
  program: php-config
Installing man pages:             /opt/php/8.1.0/php/man/man1/
  page: phpize.1
  page: php-config.1
/home/centos/php-8.1.0/build/shtool install -c ext/phar/phar.phar /opt/php/8.1.0/bin/phar.phar
ln -s -f phar.phar /opt/php/8.1.0/bin/phar
Installing PDO headers:           /opt/php/8.1.0/include/php/ext/pdo/

启动和后续配件可以参考这里
Centos7 编译 PHP7.4.16 – 简书 (jianshu.com)


增加扩展

进入刚才的解压目录

#安装GD库示例
cd php-8.1.0/ext/gd
/opt/php/8.1.0/bin/phpize
Configuring for:
PHP Api Version:         20210902
Zend Module Api No:      20210902
Zend Extension Api No:   420210902
./configure --with-php-config=/opt/php/8.1.0/bin/php-config
make && make install

完成后记得在 php.ini 里加入 extension=gd.so

PHP8 主要不向后兼容的变更

  • 字符串与数字的比较
    数字与非数字形式的字符串之间的非严格比较现在将首先将数字转为字符串,然后比较这两个字符串。
    数字与数字形式的字符串之间的比较仍然像之前那样进行。

请注意,这意味着 0 == “not-a-number” 现在将被认为是 false 。

ComparisonBeforeAfter
0 == “0”truetrue
0 == “0.0”truetrue
0 == “foo”truefalse
0 == “”truefalse
42 == ” 42″truetrue
42 == “42foo”truefalse
  • match 现在是一个保留字。
  • 断言(Assertion)失败现在默认抛出异常。如果想要改回之前的行为,可以在 INI 设置中设置 assert.exception=0
  • 与类名相同的方法名将不再被当做构造方法。应该使用__construct() 来取代它。
  • 不再允许通过静态调用的方式去调用非静态方法。因此is_callable()在检查一个类名与非静态方法 时将返回失败(应当检查一个类的实例)。
  • (real)(unset) 转换已被移除

PHP8 主要新特性

命名参数

新增命名参数的功能。

注解(Attributes)

新增注解的功能。

构造器属性提升(Constructor Property Promotion)

新增构造器属性提升功能 在构造函数中声明类的属性)。

联合类型

新增 联合类型

Match 表达式

新增 match 表达式

Nullsafe 运算符

新增Nullsafe 运算符(?->)。

其他新特性

  • 新增 WeakMap 类。
  • 新增 ValueError 类。
  • 现在,只要类型兼容,任意数量的函数参数都可以用一个可变参数替换。 例如允许编写下面的代码:

<?php class A {
         public function method(int $many, string $parameters, $here) {}
    }
    class B extends A {
         public function method(...$everything) {}
    } ?>
  • static (“后期静态绑定”中) 可以作为返回类型:

    <?php class Test {
         public function create(): static {
              return new static();
         }
    } ?>
  • 现在可以通过 $object::class 获取类名,返回的结果和 get_class($object) 一致。
  • newinstanceof 可用于任何表达式, 用法为 new (expression)(...$args)$obj instanceof (expression)
  • 添加对一些变量语法一致性的修复,例如现在能够编写 Foo::BAR::$baz
  • 添加 Stringable interface, 当一个类定义 __toString() 方法后会自动实现该接口。
  • Trait 可以定义私有抽象方法(abstract private method)。 类必须实现 trait 定义的该方法。
  • 可作为表达式使用 throw。 使得可以编写以下用法:

    <?php
    $fn = fn() => throw new Exception('Exception in arrow function'); $user = $session->user ?? throw new Exception('Must have user');
  • 参数列表中的末尾逗号为可选。

    <?php function functionWithLongSignature(
        Type1 $parameter1,
        Type2 $parameter2, // <-- 这个逗号也被允许了 ) {
    }
  • 现在允许 catch (Exception) 一个 exception 而无需捕获到变量中。
  • 支持 mixed 类型。

开启树莓派看门狗

树莓派内核默认没有启用看门狗功能,当内核挂死时将进入“死机”状态或kgdb调试状态,并不会自动重启系统。本文为树莓派开启看门狗功能并通过内核线程周期性喂狗,当出现系统崩溃时会自动重启Linux系统。

加载看门狗模块

sudo modprobe bcm2835_wdt

/etc/modules里添加信息

bcm2835_wdt

启用硬件看门狗

sudo su
echo 'dtparam=watchdog=on' >> /boot/config.txt
reboot

安装看门狗系统服务

sudo apt-get update
sudo apt-get install watchdog

如果安装过程报错,请看我的这篇文章对你是否有帮助
看门狗安装报错解决办法

配置看门狗服务

sudo su
echo 'watchdog-device = /dev/watchdog' >> /etc/watchdog.conf
echo 'watchdog-timeout = 15' >> /etc/watchdog.conf
echo 'max-load-1 = 24' >> /etc/watchdog.conf

启用服务

su pi
sudo systemctl enable watchdog
sudo systemctl start watchdog
sudo systemctl status watchdog

如果启用正常,会得到以下结果
在这里插入图片描述
如果要对此进行测试,可以尝试在shell上运行fork炸弹,模拟系统卡死情况:

sudo bash -c ':(){ :|:& };:'

https://diode.io/raspberry%20pi/running-forever-with-the-raspberry-pi-hardware-watchdog-20202/


启用bcm2835_wdt模块:

sudo modprobe bcm2835_wdt
在/etc/modules文件末尾添加一行:(sudo nano /etc/modules Linux下nano编辑器的使用 )

bcm2835_wdt
安装watchdog模块

sudo apt-get install watchdog
编辑/etc/watchdog.conf文件进行编辑配置看门狗: (sudo /etc/watchdog.conf Linux下nano编辑器的使用 )

#ping                   = 172.31.14.1
#ping                   = 172.26.1.255
#interface              = eth0
#file                   = /var/log/messages
#change                 = 1407
# 如果要使能,请去掉行前的注释标号,设置其中一个的值为0来禁用
# 这些值应设定为在正常使用期间不会重启你的设备的值
# (如果你的机器真的死机了,平均载入进程量应该超过25)
#max-load-m=n表示在m分钟内开超过n个进程的时候重启
max-load-1              = 24
#max-load-5             = 18
#max-load-15            = 12
# 注意这是内存分页的数量
# 请检查你的机器的分页大小以获取真实的大小
#最小剩余内存
#min-memory             = 1
#最小可分配内存
#allocatable-memory     = 1
#repair-binary          = /usr/sbin/repair
#repair-timeout         =
#test-binary            =
#test-timeout           =
#选择看门狗设备,这里用默认值
watchdog-device = /dev/watchdog
# 已经编译进二进制文件的默认值
#这个文件里面的内容就是CPU温度(摄氏温标)的一千倍
temperature-device      = /sys/class/thermal/thermal_zone0/temp
#设定为重置温度的一千倍
max-temperature = 75000
# 已经编译进二进制文件的默认值
#admin                  = root
#interval               = 1
#logtick                = 1
#log-dir                = /var/log/watchdog
# 这极大地减少了在你的机器真正加载完成前看门狗不被列入进程表的几率
realtime                = yes
priority                = 1
# 使能下面这行来检查rsyslogd是否仍然在运行
#pidfile                = /var/run/rsyslogd.pid

使看门狗服务开机自动启动:

sudo systemctl enable watchdog.service


测试看门狗:

sudo bash -c ':(){ :|:& };:'

所谓看门狗就是检测功能性软件是否还在运转的软件或硬件模块。当它检测到软件没有在工作时,就会重启机器,使得软件在重启之后能够继续工作。它的检测方式很简单,就让功能性软件定时的发信号给它(所谓的喂狗),一旦一定时间内没有接收到信号,那么就认为软件已经停止运行了,系统就需要重启了。在树莓派的硬件中就有看门狗的功能。下面我们就来玩玩这条狗。

教程目的:

用脚本的方式来喂狗,并试验当脚本停止喂狗后,树莓派会重启。(网上大量流传着下载watchdog这个软件来进行喂狗工作,本教程是自己写shell来喂狗的。当然,也是很简单的。)

教程器材及软件:

树莓派的板子。
SD卡(已经有镜像刷入)。
电源线及USB充电器。
U盘或USB硬盘
putty和psftp。
有DHCP的网线。
步骤:

先打开内核模块中的看门狗功能:
sudo modprobe bcm2708_wdog
(如果,你要在树莓派启动的时候,就启动看门狗功能。那么你需要在/etc/modules文件中加入,一行:bcm2708_wdog)
开启这个之后,你就可以在/dev目录下看到一个叫watchdog的文件。
执行完上面的命令,狗还不需要喂。但是一旦,你打开了这个文件(所谓,打开一种是c语言里的fopen,另一种就是等价的在shell中使用读写该文件的命令),就需要开始喂狗。喂狗的方式就是输入任何字符后数字除了V以外。此时,哪怕你关闭了文件,狗还是需要喂的。知道你输入V,才可以停止喂狗。有了这样子的原理,写一个喂狗的脚本就容易了。

!/bin/bash

while((1))
do
sleep 3
echo “Feed the dog”
echo “Feed the dog!” > /dev/watchdog
done
然后,运行这个脚本一段时间,一直喂狗,然后中断他。(Ctrl+C)
过了一会,树莓派就重启了。

树莓派 config.txt 文件解析

由于树莓派并没有传统意义上的BIOS, 所以现在各种系统配置参数通常被存在”config.txt”这个文本文件中.

树莓派的config.txt文件会在ARM内核初始化之前被GPU读取.

这个文件存在引导分区上的.对于Linux, 路径通常是/boot/config.txt, 如果是Windows (或者OS X) 它会被识别为SD卡中可访问部分的一个普通文件.

如果想要编辑配置文件, 请查看介绍编辑树莓派配置文件.

你可以使用下列命令去获取当前激活的设置:

- 列出指定的配置参数.
- 例如: vcgencmd get_config arm_freq
vcgencmd get_config 
- 列出所有已设置的整形配置参数(非零)
vcgencmd get_config int
- 列出所有已设置的字符型配置参数(非零)
vcgencmd get_config str

文件格式

当值是整形时格式为”属性=值”. 每行只指定一个参数. 注释使用’#’井号作为一行开头.

注意: 在新版的树莓派里每行都有#注释, 要想使用该行参数只需移除#.

下面是示例文件
# Set stdv mode to PAL (as used in Europe) sdtv_mode=2
# Force the monitor to HDMI mode so that sound will be sent over HDMI cable
hdmi_drive=2
# Set monitor mode to DMT
hdmi_group=2
# Set monitor resolution to 1024x768 XGA 60Hz (HDMI_DMT_XGA_60)
hdmi_mode=16
# Make display smaller to stop text spilling off the screen
overscan_left=20
overscan_right=12
overscan_top=10
overscan_bottom=10

这是另一个示例文件, 包含了各种功能的扩展文档.

内存

disable_l2cache 禁止ARM访问GPU的二级缓存. 相应的需要在内核中关闭二级缓存. 默认为0
gpu_mem GPU内存以兆为单位. 设置ARM和GPU之间的内存分配. ARM会获得剩余所有内存. 最小设为16. 默认为64
gpu_mem_256 对于有256MB内存的树莓派的GPU内存设置. 512MB的派请忽略. 会覆盖gpu_mem. 最大设为192. 默认不设置
gpu_mem_512 对于有512MB内存的树莓派的GPU内存设置. 256MB的派请忽略.  会覆盖gpu_mem. 最大设为448. 默认不设置
disable_pvt 禁止每500毫秒调整一次RAM的刷新率 (RAM温度测量).

CMA – 动态内存分配

自2012年11月19号, 固件和内核开始支持CMA, 这意味运行时可以动态管理ARM和GPU之间的内存分配. 这儿有相关config.txt示例.
cma_lwm 当GPU可用内存低于cma_lwm所设值, 将会向ARM请求一些内存.
cma_hwm 当GPU可用内存高于cma_hwm所设值, 将会向ARM释放一些内存.
要启用CMA,下面的参数需要添加到cmdline.txt文件里:
coherent_pool=6M smsc95xx.turbo_mode=N

视频

视频模式选项
sdtv_mode 为复合信号输出设置视频制式(默认为0)
sdtv_mode=0    NTSC
sdtv_mode=1    日本版NTSC – 无基座
sdtv_mode=2    PAL
sdtv_mode=3    巴西版PAL – 副载波为525/60而不是625/50

sdtv_aspect 为复合信号输出设置宽高比(默认为1)
sdtv_aspect=1  4:3
sdtv_aspect=2  14:9
sdtv_aspect=3  16:9

sdtv_disable_colourburst 禁止复合信号输出彩色副载波群. 图片会显示为单色, 但是可能会更清晰
sdtv_disable_colourburst=1  禁止输出彩色副载波群
hdmi_safe 使用”安全模式”的设置去尝试用HDMI最大兼容性启动. 这和下面的组合是一个意思: hdmi_force_hotplug=1, config_hdmi_boost=4, hdmi_group=2, hdmi_mode=4, disable_overscan=0
hdmi_safe=1
hdmi_ignore_edid 如果你的显示器是天朝产的垃圾货, 允许系统忽略EDID显示数据
hdmi_ignore_edid=0xa5000080
hdmi_edid_file 当设为1时, 将会从edid.dat文件中读取EDID数据,而不是从显示器.
hdmi_edid_file=1
hdmi_force_edid_audio 伪装成支持所有音频格式播放, 即便报告不支持也允许通过DTS/AC3.
hdmi_force_edid_audio=1
hdmi_force_edid_3d 伪装成全部CEA模式都支持3D, 即便EDID并不支持.
hdmi_force_edid_3d=1
avoid_edid_fuzzy_match 禁止去模糊匹配EDID中描述的模式. 即便遮蔽错误, 也选用匹配分辨率和最接近帧率的标准模式.
avoid_edid_fuzzy_match=1
hdmi_ignore_cec_init 不发送初始化激活源消息. 避免在重启时使(启用CEC)TV结束待机并切换频道.
hdmi_ignore_cec_init=1
hdmi_ignore_cec 伪装成TV不支持CEC. 将不会支持任何CEC功能.
hdmi_ignore_cec=1
hdmi_force_hotplug 伪装成HDMI热插拔信号被检测到, 出现HDMI显示器被接入
hdmi_force_hotplug=1 即便没有检测到HDMI显示器也要使用HDMI模式
hdmi_ignore_hotplug 伪装成HDMI热插拔信号没有被检测到, 出现HDMI显示器未接入
hdmi_ignore_hotplug=1 即便检测到HDMI显示器也要使用混合模式
hdmi_pixel_encoding 强制像素编码模式. 默认情况下会使用EDID请求的模式, 所以不需要修改.
hdmi_pixel_encoding=0 default       (limited for CEA, full for DMT)
hdmi_pixel_encoding=1 RGB limited   (16-235)
hdmi_pixel_encoding=2 RGB full      ( 0-255)
hdmi_pixel_encoding=3 YCbCr limited (16-235)
hdmi_pixel_encoding=4 YCbCr limited ( 0-255)

hdmi_drive 选择HDMI还是DVI模式
hdmi_drive=1 DVI模式 (没声音)
hdmi_drive=2 HDMI模式 (如果支持并已启用将有声音输出)

hdmi_group 设置HDMI类型
不指定组, 或者设为0, 将会使用EDID报告的首选组.
hdmi_group=1   CEA
hdmi_group=2   DMT

hdmi_mode 设置在CEA或DMT格式下的屏幕分辨率
当hdmi_group=1 (CEA)时,下列值有效
hdmi_mode=1    VGA
hdmi_mode=2    480p  60Hz
hdmi_mode=3    480p  60Hz  H
hdmi_mode=4    720p  60Hz
hdmi_mode=5    1080i 60Hz
hdmi_mode=6    480i  60Hz
hdmi_mode=7    480i  60Hz  H
hdmi_mode=8    240p  60Hz
hdmi_mode=9    240p  60Hz  H
hdmi_mode=10   480i  60Hz  4x
hdmi_mode=11   480i  60Hz  4x H
hdmi_mode=12   240p  60Hz  4x
hdmi_mode=13   240p  60Hz  4x H
hdmi_mode=14   480p  60Hz  2x
hdmi_mode=15   480p  60Hz  2x H
hdmi_mode=16   1080p 60Hz
hdmi_mode=17   576p  50Hz
hdmi_mode=18   576p  50Hz  H
hdmi_mode=19   720p  50Hz
hdmi_mode=20   1080i 50Hz
hdmi_mode=21   576i  50Hz
hdmi_mode=22   576i  50Hz  H
hdmi_mode=23   288p  50Hz
hdmi_mode=24   288p  50Hz  H
hdmi_mode=25   576i  50Hz  4x
hdmi_mode=26   576i  50Hz  4x H
hdmi_mode=27   288p  50Hz  4x
hdmi_mode=28   288p  50Hz  4x H
hdmi_mode=29   576p  50Hz  2x
hdmi_mode=30   576p  50Hz  2x H
hdmi_mode=31   1080p 50Hz
hdmi_mode=32   1080p 24Hz
hdmi_mode=33   1080p 25Hz
hdmi_mode=34   1080p 30Hz
hdmi_mode=35   480p  60Hz  4x
hdmi_mode=36   480p  60Hz  4xH
hdmi_mode=37   576p  50Hz  4x
hdmi_mode=38   576p  50Hz  4x H
hdmi_mode=39   1080i 50Hz  reduced blanking
hdmi_mode=40   1080i 100Hz
hdmi_mode=41   720p  100Hz
hdmi_mode=42   576p  100Hz
hdmi_mode=43   576p  100Hz H
hdmi_mode=44   576i  100Hz
hdmi_mode=45   576i  100Hz H
hdmi_mode=46   1080i 120Hz
hdmi_mode=47   720p  120Hz
hdmi_mode=48   480p  120Hz
hdmi_mode=49   480p  120Hz H
hdmi_mode=50   480i  120Hz
hdmi_mode=51   480i  120Hz H
hdmi_mode=52   576p  200Hz
hdmi_mode=53   576p  200Hz H
hdmi_mode=54   576i  200Hz
hdmi_mode=55   576i  200Hz H
hdmi_mode=56   480p  240Hz
hdmi_mode=57   480p  240Hz H
hdmi_mode=58   480i  240Hz
hdmi_mode=59   480i  240Hz H
H表示16:9比例(正常是4:3).
2x表示双倍像素(即更高的像素时脉, 每个像素重复两次)
4x表示四倍像素(即更高的像素时脉, 每个像素重复四次)

当hdmi_group=2 (DMT)时,下列值有效
警告: 根据这篇帖子所述
像素时脉是有限制的, 最高支持的模式是1920x1200 @60Hz with reduced blanking.
hdmi_mode=1    640x350   85Hz
hdmi_mode=2    640x400   85Hz
hdmi_mode=3    720x400   85Hz
hdmi_mode=4    640x480   60Hz
hdmi_mode=5    640x480   72Hz
hdmi_mode=6    640x480   75Hz
hdmi_mode=7    640x480   85Hz
hdmi_mode=8    800x600   56Hz
hdmi_mode=9    800x600   60Hz
hdmi_mode=10   800x600   72Hz
hdmi_mode=11   800x600   75Hz
hdmi_mode=12   800x600   85Hz
hdmi_mode=13   800x600   120Hz
hdmi_mode=14   848x480   60Hz
hdmi_mode=15   1024x768  43Hz  DO NOT USE
hdmi_mode=16   1024x768  60Hz
hdmi_mode=17   1024x768  70Hz
hdmi_mode=18   1024x768  75Hz
hdmi_mode=19   1024x768  85Hz
hdmi_mode=20   1024x768  120Hz
hdmi_mode=21   1152x864  75Hz
hdmi_mode=22   1280x768        reduced blanking
hdmi_mode=23   1280x768  60Hz
hdmi_mode=24   1280x768  75Hz
hdmi_mode=25   1280x768  85Hz
hdmi_mode=26   1280x768  120Hz reduced blanking
hdmi_mode=27   1280x800        reduced blanking
hdmi_mode=28   1280x800  60Hz
hdmi_mode=29   1280x800  75Hz
hdmi_mode=30   1280x800  85Hz
hdmi_mode=31   1280x800  120Hz reduced blanking
hdmi_mode=32   1280x960  60Hz
hdmi_mode=33   1280x960  85Hz
hdmi_mode=34   1280x960  120Hz reduced blanking
hdmi_mode=35   1280x1024 60Hz
hdmi_mode=36   1280x1024 75Hz
hdmi_mode=37   1280x1024 85Hz
hdmi_mode=38   1280x1024 120Hz reduced blanking
hdmi_mode=39   1360x768  60Hz
hdmi_mode=40   1360x768  120Hz reduced blanking
hdmi_mode=41   1400x1050       reduced blanking
hdmi_mode=42   1400x1050 60Hz
hdmi_mode=43   1400x1050 75Hz
hdmi_mode=44   1400x1050 85Hz
hdmi_mode=45   1400x1050 120Hz reduced blanking
hdmi_mode=46   1440x900        reduced blanking
hdmi_mode=47   1440x900  60Hz
hdmi_mode=48   1440x900  75Hz
hdmi_mode=49   1440x900  85Hz
hdmi_mode=50   1440x900  120Hz reduced blanking
hdmi_mode=51   1600x1200 60Hz
hdmi_mode=52   1600x1200 65Hz
hdmi_mode=53   1600x1200 70Hz
hdmi_mode=54   1600x1200 75Hz
hdmi_mode=55   1600x1200 85Hz
hdmi_mode=56   1600x1200 120Hz reduced blanking
hdmi_mode=57   1680x1050       reduced blanking
hdmi_mode=58   1680x1050 60Hz
hdmi_mode=59   1680x1050 75Hz
hdmi_mode=60   1680x1050 85Hz
hdmi_mode=61   1680x1050 120Hz reduced blanking
hdmi_mode=62   1792x1344 60Hz
hdmi_mode=63   1792x1344 75Hz
hdmi_mode=64   1792x1344 120Hz reduced blanking
hdmi_mode=65   1856x1392 60Hz
hdmi_mode=66   1856x1392 75Hz
hdmi_mode=67   1856x1392 120Hz reduced blanking
hdmi_mode=68   1920x1200       reduced blanking
hdmi_mode=69   1920x1200 60Hz
hdmi_mode=70   1920x1200 75Hz
hdmi_mode=71   1920x1200 85Hz
hdmi_mode=72   1920x1200 120Hz reduced blanking
hdmi_mode=73   1920x1440 60Hz
hdmi_mode=74   1920x1440 75Hz
hdmi_mode=75   1920x1440 120Hz reduced blanking
hdmi_mode=76   2560x1600       reduced blanking
hdmi_mode=77   2560x1600 60Hz
hdmi_mode=78   2560x1600 75Hz
hdmi_mode=79   2560x1600 85Hz
hdmi_mode=80   2560x1600 120Hz reduced blanking
hdmi_mode=81   1366x768  60Hz
hdmi_mode=82   1080p     60Hz
hdmi_mode=83   1600x900        reduced blanking
hdmi_mode=84   2048x1152       reduced blanking
hdmi_mode=85   720p      60Hz
hdmi_mode=86   1366x768        reduced blanking

overscan_left 左侧跳过像素数
overscan_right 右侧跳过像素数
overscan_top 顶部跳过像素数
overscan_bottom 底部跳过像素数
framebuffer_width 控制台framebuffer宽度, 以像素为单位. 默认是显示器宽度减去超出扫描.
framebuffer_height 控制台framebuffer高度, 以像素为单位. 默认是显示器高度减去超出扫描.
framebuffer_depth 控制台framebuffer深度, 以位为单位. 默认是16位. 8位也是有效的, 但是默认RGB调色板会导致屏幕不可读. 24位效果更好 ,但是2012年6月15号发现有显示混乱问题. 32位没有混乱问题, 但是需要设置framebuffer_ignore_alpha=1, 并在2012年6月15号发现颜色显示错误.
framebuffer_ignore_alpha 设为1将禁用alpha通道. 仅对32位有效.
test_mode 允许在启动时做声音与图像测试.
disable_overscan 设为1将禁用超出扫描.
config_hdmi_boost 设置HDMI接口的信号强度. 默认为0. 如果出现HDMI干扰问题可以试试设为4. 最大为7.
display_rotate 顺时针旋转屏幕显示 (默认为0) 或者翻转显示.
display_rotate=0        正常
display_rotate=1        90度
display_rotate=2        180度
display_rotate=3        270度
display_rotate=0x10000  水平翻转
display_rotate=0x20000  垂直翻转

注意: 旋转90度或者270度额外需要GPU内存, 所以在GPU只分配到16M的时候旋转会无效. 可能的原因:
Crashes my RPI before Linux boots if set to “1” — REW 20120913.

哪些值对我的显示器有效?

你的HDMI显示器可能只支持一部分设置. 想要找出支持哪些设置, 可以使用下面的方法.
把输出格式设为VGA 60Hz (hdmi_group=1 hdmi_mode=1) 然后启动树莓派
输入下列命令可以获取CEA支持模式的列表
/opt/vc/bin/tvservice -m CEA
输入下列命令可以获取DMT支持模式的列表
/opt/vc/bin/tvservice -m DMT
输入下列命令可以获取当前设置状态
/opt/vc/bin/tvservice -s
输入下列命令可以从显示器获取更多详细信息
/opt/vc/bin/tvservice -d edid.dat /opt/vc/bin/edidparser edid.dat
使用默认HDMI模式去排除问题时, edid.dat文件同样会提供信息

许可的解码器

你可以购买绑定树莓派CPU序列号的证书来使用额外的硬件解码器.
decode_MPG2 可开启MPEG-2硬解的序列号.
decode_MPG2=0x12345678
decode_WVC1 可开启VC-1硬解的序列号.
decode_WVC1=0x12345678
可在多台树莓派间共享SD卡的序列号. 同时最多8个证书.
decode_XXXX=0x12345678,0xabcdabcd,0x87654321,...

启动

disable_commandline_tags 在启动内核前, 通过改写ATAGS (0x100处的内存)来阻止start.elf
cmdline (string) 命令行参数. 可用来代替cmdline.txt文件
kernel (string) 加载指定名称的内核镜像文件启动内核. 默认为”kernel.img”
kernel_address 加载kernel.img文件地址
kernel_old (bool) 为1时, 从0x0处加载内核
ramfsfile (string) 要的加载的ramfs文件
ramfsaddr 要加载的ramfs文件地址
initramfs (string address) 要加载的ramfs文件及其地址 (就是把ramfsfile+ramfsaddr合并为一项).
注意: 这项使用与其他项不同的语法 – 不要在这用”=”号. 正确示例:
initramfs initramf.gz 0x00800000
device_tree_address 加载device_tree的地址
init_uart_baud 初始化uart波特率. 默认为115200
init_uart_clock 初始化uart时序. 默认为3000000 (3Mhz)
init_emmc_clock 初始化emmc时序. 默认为100000000 (100MHz)
boot_delay 在加载内核前在start.elf等待指定秒. 总延迟=1000 * boot_delay + boot_delay_ms. 默认为1
boot_delay_ms 在加载内核前在start.elf等待指定毫秒. 默认为0
avoid_safe_mode 如果设为1, 将不以安全模式启动. 默认为0

超频

注意: 设置任何参数来超频树莓派都会在芯片中永久的储存一个保修位, 用于检测你的树莓派是否超频过. 如果设备超频过保修就无效了. 自2012年9月19号,你可以自由超频而不影响保修了.
最新的内核有一个默认开启”ondemand”调速器的cpu频率内核驱动. 未开启超频并不会有任何影响. 一旦你开超频, ARM频率将随处理器负载而变化. 只有在调速器需要时才会使用非默认值. 你可以使用*_min配置选项来调整最低值, 或者使用force_turbo=1来禁用动态超频.

当芯片温度达到85°C运行时会关闭超频及超压, 直到冷却. 即使在25°C环境温度下使用最高设置, 也不要让温度达到极限.

超频选项

参数    说明
arm_freq    ARM频率,以MHz为单位. 默认为700
gpu_freq    同时设置core_freq, h264_freq, isp_freq, v3d_freq. 默认为250
core_freq    GPU处理器核心频率,以MHz为单位. 由于GPU要驱动二级缓存, 对ARM性能会造成影响. 默认为 250
h264_freq    视频硬解模块频率,以MHz为单位. 默认为250
isp_freq    图像传感器管道模块频率,以MHz为单位. 默认为250
v3d_freq    3D模块频率,以MHz为单位. 默认为250
avoid_pwm_pll    不要把锁相环用在PWM音频. 这会略微降低模拟音频的效果. 空闲的锁相环允许从剩余GPU独立设置core_freq, 这将会比超频有更多权限. 默认为0
sdram_freq    SDRAM频率,以MHz为单位.默认为400
over_voltage    ARM/GPU核心电压调节. [-16,8]用0.025V步进等同于[0.8V,1.4V]. 默认为0 (1.2V). 只有在指定 force_turbo或current_limit_override时 (会设置保修位), 才允许数值在6以上
over_voltage_sdram    同时设置over_voltage_sdram_c, over_voltage_sdram_i, over_voltage_sdram_p
over_voltage_sdram_c    SDRAM控制器电压调节. [-16,8]用0.025V步进等同于[0.8V,1.4V]. 默认为0 (1.2V)
over_voltage_sdram_i    SDRAM I/O电压调节. [-16,8]用0.025V步进等同于[0.8V,1.4V]. 默认为0 (1.2V)
over_voltage_sdram_p    SDRAM phy电压调节. [-16,8]用0.025V步进等同于[0.8V,1.4V]. 默认为0 (1.2V)
force_turbo    关闭动态CPU频率驱动及下面的最小设置. 开启h264/v3d/isp超频. 默认为0. 会设置保修位.
initial_turbo    在启动时以指定秒数 (上限为60) 或者以CPU频率来开启急速模式. 如果已经超频, 能对SD卡错误问题有改善. 默认为0
arm_freq_min    设置动态时序的最小arm_freq. 默认为700
core_freq_min    设置动态时序的最小core_freq. 默认为250
sdram_freq_min    设置动态时序的最小sdram_freq. 默认为400
over_voltage_min    设置动态时序的最小over_voltage. 默认为0
temp_limit    过热保护. 当芯片达到指定温度就把时序和电源切换会默认值. 把此值设高于默认值将影响保修. 默认为85
current_limit_override    当设为”0x5A000020″时, 禁止SMPS限流保护. 在超频过高无法重启时设置此项会有所帮助. 会设置保修位.

force_turbo模式
force_turbo=0
开启对ARM核心,GPU核心和SDRAM的动态时序及电压. 在忙的时候ARM频率会提高到”arm_freq”并在闲的时候降低到”arm_freq_min”. “core_freq”, “sdram_freq”和”over_voltage”的行为都一样. “over_voltage”最高为6 (1.35V). h264/v3d/isp部分的非默认值将被忽略.
force_turbo=1
关闭动态时序, 因此所有频率和电压会保持高值. h264/v3d/isp GPU部分的超频也会开启, 等同于设置”over_voltage”为8 (1.4V). 

时序关系

GPU核心, h264, v3d和isp共享一个锁相环, 因此需要相关联的频率. ARM, SDRAM和GPU有各自独有的锁相环, 因此可以设为没有关联的频率.

当设了”avoid_pwm_pll=1″下列设置就没必要了.
pll_freq = floor(2400 / (2 * core_freq)) * (2 * core_freq)
gpu_freq = pll_freq / [偶数]

有效的gpu_freq会自动四舍五到到最接近的整型偶数, 所以请求core_freq为500, gpu_freq为300,算一下2000/300 = 6.666 => 6 ,结果就是333.33MHz.

已测试过的超频设置

下表显示了一些成功的超频尝试, 这些可以指导你进行超频. 这些设置不一定能在每台树莓派上都成功, 并且会缩短高通芯片的寿命.

arm_freq    gpu_freq    core_freq    h264_freq    isp_freq    v3d_freq    sdram_freq    over_voltage    over_voltage_sdram
800
900    275                    500
900        450                450
930    350                    500
1000        500                500    6
1050                            6
1150        500                600    8
这是一个表明Hynix产的RAM在超频上表现不如三星产的RAM的报告.

超频时SD卡使用

设置SD卡: http://elinux.org/RPi_Easy_SD_Card_Setup
超频时使用6速或10速的SD卡(SHDC/SHDX)会导致在一些天后树莓派读取SD卡文件系统不稳定.
不管是ext4 , NTFS 或其他格式都一样.
不管是哪家SD卡生产商都一样.
不管是哪个版本的树莓派都一样.
这与SD卡容量无关 – 实际验证出现在16G或更大的SD卡上.
! 关键是你何时让树莓派功率不足,也就是低于树莓派的基本设置需求 !
popcornmix发表在https://github.com/raspberrypi/linux/issues/280:
“超频会导致SD卡错误.这情况往往是与板子相关(就是说有些树莓派超频后SD卡没事,有些不行).
我认为通常都是core_freq导致的SD卡问题(和arm_freq,sdram_freq比)”
在2013年4月写这个提示的时候在树莓派官方论坛上一共有137个有关于SD的问题, 绝大部分与超频有关.
如果你使用6速或10速SD卡, 还想要树莓派稳定运行:  不要尝试超频,否则很可能会丢失数据

监测温度及电压

要检测树莓派的温度, 看: /sys/class/thermal/thermal_zone0/temp
要检测树莓派当前的频率, 看: /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
要检测树莓派电源装置的电压, 你需要一个万用电表, 接上电源测试点, 或者扩展头.

通常来说要保持核心温度低于70度, 电压高于4.8V. (另外请注意, 不要用那种便宜的USB电源, 那基本上是4.2V的, 这是因为那本来就是为充3.7V锂电池设计的, 根本无法为树莓派提供稳定的5V电压). 此外, 用散热片也是个好主意, 尤其是你把树莓派装到了壳子里. 一个合适的散热器是自带不干胶栅格状的 14x14x10 mm 散热片.

超频稳定性测试

大多数超频问题立马就会出现启动问题, 但还是会随时间而出现文件系统问题. 这是一个对系统,特别是SD卡进行压力测试的脚本. 如果脚本执行完成, dmesg中不提示任何错误, 你做的超频设置可能会比较稳定.

如果系统崩溃了, 在重启时按住shift键, 这会临时性关闭所有超频. 同样, 注意SD卡问题通常由core_freq造成,不要在raspi-config预设的高速(950 MHz)和超速(1 GHz)里来个大跳越(从250 MHz飞到500 MHz).
#!/bin/bash
#Simple stress test for system. If it survives this, it's probably stable.
#Free software, GPL2+

echo “Testing overclock stability…”

#Max out the CPU in the background (one core). Heats it up, loads the power-supply.
nice yes >/dev/null &

#Read the entire SD card 10x. Tests RAM and I/O
for i in `seq 1 10`; do echo reading: $i; sudo dd if=/dev/mmcblk0 of=/dev/null bs=4M; done

#Writes 512 MB test file,  10x.
for i in `seq 1 10`; do echo writing: $i; dd if=/dev/zero of=deleteme.dat bs=1M count=512; sync; done

#Clean up
killall yes
rm deleteme.dat

#Print summary. Anything nasty will appear in dmesg.
echo -n “CPU freq: ” ; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
echo -n “CPU temp: ” ; cat /sys/class/thermal/thermal_zone0/temp
dmesg | tail

echo "Not crashed yet, probably stable."