Linux Mint 要如何從 19 升級到 21 – Tsung’s Blog

Linux 的升級原本想說都只要 GUI 點選升級就好,沒想到 Mint 每個版本都不一樣,而且前面版本為了安全,會強迫要先做備份等等作業完成後,才會讓你開始做升級的動作。

首先,若是 32-bit 的系統,就只能到 19.3,暫時升級不上去,確認自己使用系統可用下述:

  • $ dpkg –print-architecture
    • amd64 (64bits) or i386 (32bits)

灌好 19.3 後,要升級到 21 前,需要先升級到 20,在慢慢升級上去,文章可見:How to upgrade to Linux Mint 21 — Linux Mint User Guide documentation

在選單可以選到升級功能:

  1. “Menu -> Administration -> Update Manager.”
  2. Launch Timeshift with “Menu -> Administration -> Timeshift.” # 升級之前需要跑 Timeshift 備份
    • 若不想要跑 Timeshift,可以:echo “{}” | sudo tee /etc/timeshift.json # 跳過此檢查

Mint 19.3 手動升級到 20

  1. sudo apt update
  2. sudo apt install mintupgrade
  3. mintupgrade # 這邊不能 sudo
  4. mkdir -p /tmp/Upgrade-Backup-tricia/APT
  5. cd /tmp/Upgrade-Backup-tricia/APT; cp /etc/apt/sources.list .
  6. 想要跳過不檢查 timeshift
    • echo “{}” | sudo tee /etc/timeshift.json # Skipping the timeshift requirement
  7. mintupgrade check
  8. mintupgrade download
  9. mintupgrade upgrade
  10. 管理 → 更新管理員

Mint 升級到 20.3 後,要升級到 21

  • sudo mintupgrade upgrade # 20.3 以後 就需要sudo 了

文章導覽

发表在 未分类 | 留下评论

k8s-architectur

发表在 未分类 | 留下评论

kubernetes核心实战(一)— namespace – 小陈运维

12/30

本文最后更新于2022年05月19日,已超过321天没有更新,若内容或图片失效,请留言反馈。

kubernetes核心实战

图片

1、资源创建方式

命令行创建

yaml文件创建

2、namespace

命名空间(namespace)是Kubernetes提供的组织机制,用于给集群中的任何对象组进行分类、筛选和管理。每一个添加到Kubernetes集群的工作负载必须放在一个命名空间中。

命名空间为集群中的对象名称赋予作用域。虽然在命名空间中名称必须是唯一的,但是相同的名称可以在不同的命名空间中使用。这对于某些场景来说可能帮助很大。例如,如果使用命名空间来划分应用程序生命周期环境(如开发、staging、生产),则可以在每个环境中维护利用同样的名称维护相同对象的副本。

命名空间还可以让用户轻松地将策略应用到集群的具体部分。你可以通过定义ResourceQuota对象来控制资源的使用,该对象在每个命名空间的基础上设置了使用资源的限制。类似地,当在集群上使用支持网络策略的CNI(容器网络接口)时,比如Calico或Canal(calico用于策略,flannel用于网络)。你可以将NetworkPolicy应用到命名空间,其中的规则定义了pod之间如何彼此通信。不同的命名空间可以有不同的策略。

使用命名空间最大的好处之一是能够利用Kubernetes RBAC(基于角色的访问控制)。RBAC允许您在单个名称下开发角色,这样将权限或功能列表分组。ClusterRole对象用于定义集群规模的使用模式,而角色对象类型(Role object type)应用于具体的命名空间,从而提供更好的控制和粒度。在角色创建后,RoleBinding可以将定义的功能授予单个命名空间上下文中的具体具体用户或用户组。通过这种方式,命名空间可以使得集群操作者能够将相同的策略映射到组织好的资源集合。

将命名空间映射到团队或项目上

使用命名空间对生命周期环境进行分区

使用命名空间隔离不同的使用者

[root@k8s-master-node1 ~]# kubectl  create  namespace cby
namespace/cby created
[root@k8s-master-node1 ~]# 
[root@k8s-master-node1 ~]# kubectl  get namespaces 
NAME                   STATUS   AGE
cby                    Active   2s
default                Active   21h
ingress-nginx          Active   21h
kube-node-lease        Active   21h
kube-public            Active   21h
kube-system            Active   21h
kubernetes-dashboard   Active   21h
[root@k8s-master-node1 ~]# 
[root@k8s-master-node1 ~]# kubectl  delete  namespace cby
namespace "cby" deleted
[root@k8s-master-node1 ~]# 
[root@k8s-master-node1 ~]# 
[root@k8s-master-node1 ~]# kubectl  get namespaces 
NAME                   STATUS   AGE
default                Active   21h
ingress-nginx          Active   21h
kube-node-lease        Active   21h
kube-public            Active   21h
kube-system            Active   21h
kubernetes-dashboard   Active   21h
[root@k8s-master-node1 ~]#
查看yaml格式
  • [root@k8s-master-node1 ~]# kubectl  create  namespace cby
    namespace/cby created
    [root@k8s-master-node1 ~]# 
    [root@k8s-master-node1 ~]# kubectl  get namespaces cby -o yaml
    apiVersion: v1
    kind: Namespace
    metadata:
    creationTimestamp: "2021-11-17T03:08:10Z"
    labels:
      kubernetes.io/metadata.name: cby
    name: cby
    resourceVersion: "311903"
    uid: 63f2e47d-a2a5-4a67-8fd2-7ca29bfb02be
    spec:
    finalizers:
    
    - kubernetes
      status:
        phase: Active
发表在 未分类 | 留下评论

How to make PHP 2000 times faster by Timofey Bugaevsky Medium

[

Timofey Bugaevsky

](https://tbugaevsky.medium.com/?source=post_page—–84c1446e43e7——————————–)

We’ll discuss why PHP is an awesome programming language, how to make your applications faster in means of performance and development.

Why PHP is an awesome language?

  1. It’s reliable, — you install it and it works.
  2. It’s stable, — updating between major versions requires little changes in your code and brings joy seeing performance increase and new features, same is inherited by developers who make libraries for PHP, and solutions that you find on stack overflow.
  3. It’s designed for web, — built-in templates, fetching, regular expressions, JSON, XML, various DB and web server support and it had server-side rendering (SSR) before it was invented.
  4. It’s supported, — check the list of popular CMS — they are mostly built with PHP, see plugins on vendor websites: Shopify, Stripe, Twilio and other vendors have SDK for PHP.
  5. It’s feature rich, — it supports latest technologies: Docker, NoSQL, WebSockets, Multi-tenancy, Image processing, Foreign Function Interface, frameworks like Laravel, single language on frontend and backend, and more.

What about speed?

Why I didn’t mention that PHP is fast? Let’s first define what means fast for web development. With my experience, bottle neck in web applications is a database, so how fast does language respond doing nothing but saying “Hello, world!” with grammar errors is not the thing you should compare.

There are simple ways to make your web application work faster — purchasing more powerful server. Even if there are great hosting companies like HostZealot, which allow you to get a high-performant dedicated server at an affordable price, and companies like Cloudflare which allow you to save your server’s CPU and RAM by reducing load made by bots and crawlers, improvements in the application sources can bring you much more impressive results.

Among other things, your site performance is important for SEO and thus for your business revenue, so I have an article, describing how to pass Google’s PageSpeed asessment.

For me as a developer, time wasted on finding working solutions, debugging, and compilation is most important when selecting a favorite language.
So let’s see what we can improve in terms of rapid application development.

What’s better than frontend and backend?

The current trend of web application development is using frontend and backend applications. This is good from standpoint of splitting work between 2 programmers: one should know how to work with databases and third-party APIs effectively, another should know how to build fancy interfaces.

What’s wrong with this approach?

  1. When an application goes to the sustaining stage you star searching for a full-stack developer who needs to work as two people mentioned above.
  2. Building 2 applications and integrating them with API doesn’t bring you value, but from my experience it often brings threats: you have an API which by mistake might allow reading data from your database, which you don’t want to share, for example your competitors could grab your user emails if it’s not prohibited explicitly.
  3. Fancy Interface increases size of your application, your users wait a lot, and Google considered this in search ranking. I have experience optimizing node.js application that had 1.6 GB of libraries and had page load time over 6.5 seconds and took several minutes to compile.
  4. Node.js means compilation, and it is eating time of a developer. JavaScript was designed to run without compilation, but node.js brought old times back, and to compensate this and other problems it brought, a lots of things were invented: hot module replacement (HMR), server-side rendering (SSR), compiler written in Go, and so on, among they are not needed in another application design, they are often not stable.

Is there another solution that can bring more profit? Imagine you can write backend and frontend parts in a single application and even in a same language, yet having modern interactive application. This is what Laravel Livewire framework lets you to have.

Laravel is not the only framework that allows this approach when creating full-stack applications. If you are open-minded enough, try Elixir programming language with its Phoenix framework and LiveView templates.

When language speed is important?

If your application uses math intensively, for example it’s image or video processing app, compressing or encryption algorithm, 3D, cryptocurrency or AI application, you are definitely interested in a language that allows building an application that uses CPU and RAM most efficiently.

Here PHP is not good at, it takes 40 bytes to store one integer in an array, and it makes algorithms like mentioned above work extremely slow.

The obvious solution here is choosing another language.

You definitely don’t want to write a more or less complex and sustainable application in Assembler, but which options do you have? Fortran is fast, but it’s very niche language, C++ is great, but it’s sometimes too powerful and it’s very simple to make memory leak with it. From fast modern languages there are Rust, made in Mozilla and Go made in Google, where Rust wins in calculating fractals.

How to make PHP be good at math?

“But wait, you said you can make PHP run faster!” — you’ll say.

Yes and no. We will make a PHP application run fast by making it execute CPU/RAM intensive operations using a library, written in a language that fits for that better.

There are various options of doing so:

  1. You can write an app and execute it using shell_exec() function, which is suitable if you need to run something large once.
  2. You can write a PHP extension and include it into PHP, which is great if you want to provide your functionality for the community.
  3. Use Foreign Function Interface (FFI) to include a library (.so for Linux, .dll for Windows, or .dylib for MacOS).

Foreign Function Interface (FFI)

FFI is what made Python so popular. It allows including any library into your application and get its functionality available. For example, to create a desktop application in Python you can use PyQt library, which is actually not a library itself, its a binding to Qt library.

In PHP this feature was introduced in PHP 7.4 in the end of 2018.

I believe you already got what are benefits of using FFI comparing to waiting for PHP extension to be created by a library vendor. It’s not very much more complicated comparing to writing an own PHP extension due to great PHP documentation and community, but it’s still psychologically simpler.

Live example

A live example is included so you can do it yourself and get your performance boost.

Preparing infrastructure

You can’t imagine working on web applications without using Docker, like I do, right? 🙂

We will not install PHP or Rust on your machine, instead, we’re going to use simplest way to run PHP in Docker, docker-compose and official PHP+Apache docker image.

Create docker-compose.yml file in your project folder with following content:

version: '3.5'services:  php:    container_name: php_2000x_faster    build:      context: .      dockerfile: Dockerfile    ports:      - 5080:80    volumes:      - './app:/var/www/html'      - './mylib:/var/www/mylib'

Create Dockerfile file in your project folder with following content:

FROM php:8.2-apacheRUN apt-get update &&    apt-get install -y cargoRUN set -eux;     docker-php-ext-configure opcache;     docker-php-ext-install opcache;RUN echo "opcache.enable=1" >> $PHP_INI_DIR/conf.d/opcache.ini &&    echo "opcache.jit=on" >> $PHP_INI_DIR/conf.d/opcache.iniRUN apt-get update &&    apt-get install -y libffi-dev &&    docker-php-ext-configure ffi --with-ffi &&    docker-php-ext-install ffiRUN echo "ffi.enable=preload" > $PHP_INI_DIR/conf.d/ffi.ini &&    echo "opcache.preload=/var/www/html/preload.php" >> $PHP_INI_DIR/conf.d/ffi.iniRUN usermod -u 1000 www-dataUSER www-dataENV USER=www-dataCMD echo 'Building a library.' &&                echo 'Starting apache' &&    apache2-foreground

Create folders for your project.

mkdir appmkdir mylib

Start the docker container by running in your project folder:

docker-compose up --build

Creating a Rust library project

Now we have required dependencies installed and can create a Rust project.

docker exec php_2000x_faster cargo init ../mylib

Remove git folder if you like to have both apps in your repository.

docker exec php_2000x_faster rm -rf ../mylib/.git

Library file is by default named lib.rs, let’s create this file in mylib/src folder. It will contain simple, beloved by programmers, Fibonacci number calculation function and also a function that allows running multiple times Fibonacci function, which we will use for benchmark below:

#[no_mangle]pub extern fn fibonacci(number: i64) -> i64 {  return match number {    0 => 0,    1 => 1,    number => fibonacci(number - 1) + fibonacci(number - 2)  }}#[no_mangle]pub extern fn fibonacci_loop(repeat: i64, number: i64) -> i64 {  let mut result = number;  for _ in 0..repeat {    result = fibonacci(number);  }  return result}

Now you can uncomment following lines in Dockerfile to enable compiling the library:

...CMD echo 'Building a library.' &&        cd /var/www/mylib &&    rustc --crate-type=cdylib -O -o ./mylib.so ./src/lib.rs &&    echo 'Starting apache' &&    apache2-foreground

Importing Rust library into PHP application

We have already enabled FFI for PHP, we have also instructed OPcache to preload a library from preload.php file in app folder. What we need to do is importing the library using this mechanism.

Create preload.php file in app folder with following content:

<?phpFFI::load(dirname(__DIR__) . "/mylib/mylib.h");opcache_compile_file(__DIR__ . "/mylib.php");

The important thing is that you need C header file that describes your library, this file contains definitions for functions that we are going to use. For this, create mylib.h file in mylib folder with following content:

#define FFI_SCOPE "MyLib"#define FFI_LIB "./mylib.so" int64_t fibonacci(int64_t n);int64_t fibonacci_loop(int64_t total, int64_t n);

What is left is creating a class that will use this library. For this, create mylib.php file in app folder with following content:

<?phpfinal class MyLib {    private static $ffi = null;    function __construct() {        if (is_null(self::$ffi)) {            self::$ffi = FFI::scope("MyLib");        }    }    function fibonacci($number) {       return (int)self::$ffi->fibonacci($number);    }    function fibonacci_loop($repeat, $number) {       return (int)self::$ffi->fibonacci_loop($repeat, $number);    }}

This class we will use to run functions from the Rust library.

Running benchmark

Create index.php file in app folder with following content:

<?phpfunction fibonacci($number) {    if ($number == 0) {        return 0;    } elseif ($number == 1) {  return 1;    } else {        return fibonacci($number - 1) + fibonacci($number - 2);    }}function fibonacci_loop($repeat, $number) {    $result = 0;    for ($i = 0; $i < $repeat; $i++) {        $result = fibonacci($number);    }    return $result;}require_once "mylib.php";$myLib = new MyLib();echo '<pre>';$repeat = 50;$number = 32;$startTime = microtime(true);$myLib->fibonacci_loop($repeat, $number);$executionTimeRust = microtime(true) - $startTime;echo "Running fibonacci number calculation $repeat times for $number number."."n";echo "Fully on Rust execution time: <strong>$executionTimeRust</strong> sec."."n";$startTime = microtime(true);for ($i = 0; $i < $repeat; $i++) {     $myLib->fibonacci($number);}$executionTimeRustPhp = microtime(true) - $startTime;echo "Calling Rust function in PHP loop execution time: <strong>$executionTimeRustPhp</strong> sec."."n";$startTime = microtime(true);fibonacci_loop($repeat, $number);$executionTimePhp = microtime(true) - $startTime;echo "Fully on PHP execution time: <strong>$executionTimePhp</strong> sec."."n";$boostFactor = $executionTimePhp/$executionTimeRust;echo "Total boost: <strong>$boostFactor</strong> times." . "n";        echo '</pre>';

Stop and restart docker container:

Ctrl+Cdocker-compose up --build

Open the application in web browser http://localhost:5080/ here is what you will see:

Sources on GitHub

Below are the sources and instructions how to run them:

Conclusion

As you can see, rewriting CPU-intensive calculations in Rust gave over 2000x performance increase. As I mentioned above, PHP is not very much optimal for large arrays like making custom algorithms for image processing, so here you can also have great benefits.

Note that -O option in rustc command is highly important, because without it it generates unoptimized code which runs extremely slow.

About the author

Timofey Bugaevsky is a software engineer with almost 20 years of experience, working with various programming languages and frameworks. He’s best at sustaining and adding new features to existing in-house built web systems. If you’re interested, you’re welcome to hire.

发表在 未分类 | 留下评论

世界,您好!

欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!

发表在 未分类 | 一条评论