Skip to content

Commit

Permalink
mdadm software raid
Browse files Browse the repository at this point in the history
  • Loading branch information
huataihuang committed Aug 16, 2023
1 parent d96e0e1 commit b99f996
Show file tree
Hide file tree
Showing 85 changed files with 1,090 additions and 17 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion source/apple/one/apple_news_in_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

通过 :ref:`apple_one` 订阅,可以同时获得苹果的6个服务,如果购买 Premier plan ,每月 29.95 美刀,可以家庭共享并且获得 2T icloud 存储。通过 Apple TV 和 Apple News ,可以打开英语世界的大门...

美区账号无法直接使用国内的信用卡,即使是双币信用卡(假的Visa/Master?)也无法在Google/Apple上直接订阅,变通的曲径是采用 `Apple Gift Card - App Store, iTunes, iPhone, iPad, AirPods, MacBook, accessories and more (Email Delivery) <https://www.amazon.com/gp/product/B08F7GTP2R/ref=ppx_yo_dt_b_asin_title_o00?ie=UTF8&psc=1>`_ 向美区账号充值
美区账号无法直接使用国内的信用卡,即使是双币信用卡(假的Visa/Master?)也无法在Google/Apple上直接订阅,变通的曲径有两种方法:

- 采用 `Apple Gift Card - App Store, iTunes, iPhone, iPad, AirPods, MacBook, accessories and more (Email Delivery) <https://www.amazon.com/gp/product/B08F7GTP2R/ref=ppx_yo_dt_b_asin_title_o00?ie=UTF8&psc=1>`_ 向美区账号充值(目前我采用这种方法)
- `美区 Apple ID 绑定 美区 Paypal <https://blog.shuziyimin.org/171>`_ 这个方法可能更好,但是有一个非常难以跨越的门槛(我没有成功): 需要有一个美国手机号(也可以是虚拟号码)

- `Google Voice <https://voice.google.com/>`_ 虚拟号码的依赖条件是首先有一个美国移动电话号码,晕倒...我就是要一个虚拟号码来替代美国手机号码啊...
- `TextNow <https://www.textnow.com/>`_ 虚拟号码似乎屏蔽了云计算服务的虚拟机IP导致无法注册...

准备和加载Apple News
=====================
Expand Down
4 changes: 4 additions & 0 deletions source/clang/upgrade_gcc_on_centos7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
.. literalinclude:: upgrade_gcc_on_centos7/build_gcc
:caption: 编译gcc

.. warning::

编译GCC是非常大型的编译,如果没有使用 :ref:`parallel_make` 则编译过程非常漫长。对于多处理器核心建议使用 :ref:`parallel_make` 。不过,也很郁闷的是,这个并行编译可能还受限于gcc版本,我在aliOS 7.2环境使用发行版的gcc 4.8.5,开启 :ref:`parallel_make` 居然无法完成 ``gcc-10.5.0`` 编译,取消了并行编译才能正确完成编译gcc。

参考
======

Expand Down
2 changes: 1 addition & 1 deletion source/clang/upgrade_gcc_on_centos7/prepare_build_gcc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sudo yum -y install bzip2 wget gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel make
sudo yum -y install bzip2 wget gcc gcc-c++ gmp-devel mpfr-devel libmpc-devel make texinfo
30 changes: 28 additions & 2 deletions source/flask/flask_startup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ Flask 使用的 HTML 渲染模版 `Jinja2 template <http://quintagroup.com/cms/p
:caption: 明确编写 ``escape()`` 防止恶意注入JS
:emphasize-lines: 2,8

此时用户在浏览器中输入 http:://127.0.0.1:5000/<script>alert("bad")</script> 这样的注入,就会直接被拒绝渲染,页面提示::
.. note::

程序中 ``return f"Hello, {escape(name)}!"`` 中有一个 ``f`` 表示 ``f-string`` ,是Python 3.6以上版本共鞥,用于格式化字符串。也就是最后返回的值( ``escape()`` 处理后的值进行转义 ),最后返回的是 ``User xxx``

此时用户在浏览器中输入 http:://127.0.0.1:5001/<script>alert("bad")</script> 这样的注入,就会直接被拒绝渲染,页面提示::

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
Expand All @@ -61,12 +65,34 @@ Flask 使用的 HTML 渲染模版 `Jinja2 template <http://quintagroup.com/cms/p

注意, `Jinja2 template <http://quintagroup.com/cms/python/jinja2>`_ 已经内嵌了自动防范的功能,上述代码片段不使用 ``escape()`` 也是有同样效果的

所以用户只能输入正常的名字 如 http:://127.0.0.1:5000/huatai
所以用户只能输入正常的名字 如 http:://127.0.0.1:5001/huatai

此时页面才能正常渲染::

Hello,huatai!

路由(Routing)
================

Web应用会使用一些有意义的URLs让用户访问以及调用不同的函数返回页面,这种方式称为 ``route`` (路由)

.. literalinclude:: flask_startup/hello_route.py
:language: python
:caption: 路由访问

不同规则
==========

以下代码可以从url中获取需要的内容,根据不同路径以及关系分别返回 ``username / post_id / subpath`` ,你可以分别试试::

http://http://127.0.0.1:5001/user/huatai
http://http://127.0.0.1:5001/post/1
http://http://127.0.0.1:5001/path/the_large_path/small_path

.. literalinclude:: flask_startup/variable_rules.py
:language: python
:caption: 根据用户访问路径来返回不同类型的数据

参考
=======

Expand Down
11 changes: 11 additions & 0 deletions source/flask/flask_startup/hello_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
return 'Index Page'

@app.route("/hello")
def hello_world():
return "Hello, World"
19 changes: 19 additions & 0 deletions source/flask/flask_startup/variable_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask import Flask
from markupsafe import escape

app = Flask(__name__)

@app.route('/user/<username>')
def show_user_profile(username):
# show the user profile for that user
return f'User {escape(username)}'

@app.route('/post/<int:post_id>')
def show_post(post_id):
# show the post with the given id, the id is an interger
return f'Post {post_id}'

@app.route('/path/<path:subpath>')
def show_subpath(subpath):
# show the subpath after /path/
return f'Subpath {escape(subpath)}'
2 changes: 1 addition & 1 deletion source/flask/intro_flask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Flask依赖以下开源项目:
- `MarkupSafe <https://palletsprojects.com/p/markupsafe/>`_ 随Jinja提供,渲染模版是避免注入攻击
- `ItsDangerous <https://palletsprojects.com/p/itsdangerous/>`_ 对数据进行安全签名确保完整性,用于保护flask的会话cookie
- `click command line interfaces <https://click.palletsprojects.com/>`_ 编写命令行应用程序的框架,提供了flask命令以及允许添加定制的管理命令
- `Blinker <https://blinker.readthedocs.io/>` 实现 ``Signals`` 功能(轻量级订阅通知)
- `Blinker <https://blinker.readthedocs.io/>`_ 实现 ``Signals`` 功能(轻量级订阅通知)

Flask 并不原生支持数据库、Web表单、用户认证等高级功能,这些功能以及大多数Web程序所需的关键服务都以扩展的方式集成到核心包:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ GlusterFS底层需要采用操作系统提供的文件系统,有以下推荐
实践
=======

- :ref:`deploy_centos7_gluster11_lvm_mdadm_raid6`
- :ref:`deploy_centos7_gluster11_lvm_mdadm_raid10`
6 changes: 6 additions & 0 deletions source/gluster/deploy/centos/centos_gluster_init.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ CentOS目前依然是生产环境中常用的操作系统,虽然由于 :ref:`r
:language: bash
:caption: 通过 :ref:`pssh` 批量完成分区、格式化和挂载

- 完成后在服务器上检查 ``df -h`` 可以看到12块已经格式化好 :ref:`xfs` 并挂载好的磁盘:

.. literalinclude:: centos_gluster_init/parted_xfs_df
:caption: 分区和格式化、挂载好的12块磁盘的文件系统
:emphasize-lines: 9-20

``wrong fs type, bad option, bad superblock``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
for i in {0..11};do
if [ ! -d /data/brick${i} ];then mkdir -p /data/brick${i};fi
parted -s -a optimal /dev/nvme${i}n1 mklabel gpt
# 如果随机遇到以下报错,显示磁盘设备busy无法分区,则添加sleep 1避免上一个parted命令还没处理完就发起下一个parted
# Error: Error informing the kernel about modifications to partition /dev/nvme1n1p1 -- Device or resource busy. This means Linux won't know about any changes you made to /dev/nvme1n1p1 until you reboot -- so you shouldn't mount it or use it in any way before rebooting.
# Error: Failed to add partition 1 (Device or resource busy)
sleep 1
parted -s -a optimal /dev/nvme${i}n1 mkpart primary xfs 0% 100%
parted -s -a optimal /dev/nvme${i}n1 name 1 gluster_brick${i}
sleep 1
Expand Down
20 changes: 20 additions & 0 deletions source/gluster/deploy/centos/centos_gluster_init/parted_xfs_df
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Filesystem Size Used Avail Use% Mounted on
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 66M 63G 1% /dev/shm
tmpfs 63G 2.2M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/sda3 49G 21G 27G 44% /
/dev/sda5 167G 1.4G 157G 1% /home
/dev/sda2 976M 181M 728M 20% /boot
/dev/nvme0n1p1 3.5T 3.7G 3.5T 1% /data/brick0
/dev/nvme1n1p1 3.5T 3.7G 3.5T 1% /data/brick1
/dev/nvme2n1p1 3.5T 3.7G 3.5T 1% /data/brick2
/dev/nvme3n1p1 3.5T 3.7G 3.5T 1% /data/brick3
/dev/nvme4n1p1 3.5T 3.7G 3.5T 1% /data/brick4
/dev/nvme5n1p1 3.5T 3.7G 3.5T 1% /data/brick5
/dev/nvme6n1p1 3.5T 3.7G 3.5T 1% /data/brick6
/dev/nvme7n1p1 3.5T 3.7G 3.5T 1% /data/brick7
/dev/nvme8n1p1 3.5T 3.7G 3.5T 1% /data/brick8
/dev/nvme9n1p1 3.5T 3.7G 3.5T 1% /data/brick9
/dev/nvme10n1p1 3.5T 3.7G 3.5T 1% /data/brick10
/dev/nvme11n1p1 3.5T 3.7G 3.5T 1% /data/brick11
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
.. _deploy_centos7_gluster11_lvm_mdadm_raid6:
.. _deploy_centos7_gluster11_lvm_mdadm_raid10:

========================================
在软RAID6+LVM上CentOS 7 部署Gluster 11
========================================
=============================================
在软RAID10 + LVM上CentOS 7 部署Gluster 11
=============================================

.. note::

根据 :ref:`deploy_centos7_gluster11` 迭代改进部署方案

**待续**
:ref:`deploy_centos7_gluster11` 我采用了一个比较ugly的部署方案,将物理服务器上的12个 ``brick`` (磁盘)分别用于同一个volume,但是由于强制顺序安排,可以让数据分布到不同服务器上。但是,实际上这种方案限制了集群的扩容和缩容,例如在 :ref:`add_centos7_gluster11_server` 就会看到缺陷。对于GlusterFS这种精简架构的分布式存储, :ref:`think_best_practices_for_gluster` ,改进为底层采用 :ref:`linux_software_raid` 来统一存储磁盘,实现一个超大规模的磁盘,然后借助 :ref:`linux_lvm` 来实现灵活的卷划分和管理。

准备工作
===========

- :ref:`build_glusterfs_11_for_centos_7`
- :ref:`gluster11_rpm_createrepo`

磁盘存储池构建
================

- :ref:`mdadm_raid10` 是因为本省存储磁盘非常充裕,所以我就没有采用更为节约磁盘(且高数据安全)的RAID6

.. warning::

由于项目方案调整,我现在采用了直接在 :ref:`mdadm_raid10` 构建 :ref:`xfs` ,快速完成部署。

以下部分请暂时忽略,等后续再有实践机会重新开始...

安装和启动服务
===============

Expand Down
2 changes: 1 addition & 1 deletion source/gluster/deploy/centos/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CentOS平台GlusterFS部署
download_gluster_rpm_createrepo.rst
gluster11_rpm_createrepo.rst
deploy_centos7_gluster11.rst
deploy_centos7_gluster11_lvm_mdadm_raid6.rst
deploy_centos7_gluster11_lvm_mdadm_raid10.rst
add_centos7_gluster11_server.rst

.. only:: subproject and html
Expand Down
33 changes: 32 additions & 1 deletion source/kernel/process/utils/ps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,41 @@ Linux/Unix 通常采用 System V ( ``ps -elf`` ) 或 BSD ( ``ps alx`` ) 风格 `

似乎 ``ps -elf`` 更为适合(输出字段中有 ``C`` 表明CPU使用率)

后续再学习
- 检查进程启动时间 ``lstart`` :

.. literalinclude:: ps/ps_lstart
:caption: 检查进程启动时间,例如 ``qemu-system-x86``

输出显示案例类似如下:

.. literalinclude:: ps/ps_lstart_output
:caption: 检查进程启动时间,例如 ``qemu-system-x86`` 可以看到详细的启动时间

``ps`` 检查线程
=================

``ps`` 命令的 ``-T`` 参数表示输出线程, ``-p`` 可以指定进程,结合上文的输出字段,我们可以构建一个检查某个进程所有线程的CPU使用率以及运行在哪些cpu core上,以便进一步排查进程异常。

举例,进程 ``qemu-system-x86`` 的 ``pid`` 是 ``7354`` ,当前 ``top`` 可以看到使用的CPU百分比大约是 10+% :

.. literalinclude:: ps/top_qemu
:caption: 检查 ``qemu-system-x86`` 进程的线程负载
:emphasize-lines: 8

- 现在来解析这个进程的线程:

.. literalinclude:: ps/ps_tid_cpu
:caption: 检查进程的所有线程使用的cpu资源以及调度的cpu core

输出信息:

.. literalinclude:: ps/ps_tid_cpu_output
:caption: 检查进程的所有线程使用的cpu资源以及调度的cpu core

这里可以看到4个kvm线程分别消耗了大约 2.5% 的CPU资源

参考
======

- `About the output fields of the ps command in Unix <https://kb.iu.edu/d/afnv>`_ 非常清晰的 ``ps -o`` 参数字段快速查询,建议参考
- `How to get the start time of a long-running Linux process? <https://stackoverflow.com/questions/5731234/how-to-get-the-start-time-of-a-long-running-linux-process>`_
1 change: 1 addition & 0 deletions source/kernel/process/utils/ps/ps_lstart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ps -eo pid,lstart,cmd | grep qemu-system-x86_64
3 changes: 3 additions & 0 deletions source/kernel/process/utils/ps/ps_lstart_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
7300 Sun Aug 6 11:10:56 2023 /usr/bin/qemu-system-x86_64 -name guest=z-b-data-3,...
7354 Sun Aug 6 11:11:03 2023 /usr/bin/qemu-system-x86_64 -name guest=z-b-data-1,...
7405 Sun Aug 6 11:11:09 2023 /usr/bin/qemu-system-x86_64 -name guest=z-b-data-2,...
1 change: 1 addition & 0 deletions source/kernel/process/utils/ps/ps_tid_cpu
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ps -T -o pid,tid,c,pcpu,comm -p 7354
10 changes: 10 additions & 0 deletions source/kernel/process/utils/ps/ps_tid_cpu_output
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PID TID C %CPU COMMAND
7354 7354 0 0.2 qemu-system-x86
7354 7358 0 0.0 qemu-system-x86
7354 7361 0 0.0 IO mon_iothread
7354 7363 2 2.1 CPU 0/KVM
7354 7364 2 2.6 CPU 1/KVM
7354 7365 2 2.5 CPU 2/KVM
7354 7366 2 2.7 CPU 3/KVM
7354 7470 0 0.0 worker
7354 210749 0 0.0 worker
11 changes: 11 additions & 0 deletions source/kernel/process/utils/ps/top_qemu
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
top - 16:30:30 up 4 days, 5:28, 11 users, load average: 0.72, 0.55, 0.40
Tasks: 630 total, 1 running, 629 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.6 us, 0.3 sy, 0.0 ni, 99.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 386813.0 total, 327264.1 free, 51822.8 used, 7726.1 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 332638.5 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7354 libvirt+ 20 0 16.8g 16.0g 19768 S 10.2 4.2 635:51.79 qemu-system-x86
7300 libvirt+ 20 0 16.7g 16.0g 19668 S 6.6 4.2 459:39.34 qemu-system-x86
7405 libvirt+ 20 0 16.8g 16.0g 19732 S 6.6 4.2 442:22.15 qemu-system-x86
2014 prometh+ 20 0 726984 19972 12036 S 4.3 0.0 50:29.36 node_exporter
1 change: 1 addition & 0 deletions source/kernel/startup/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Kernel起步
howto_learn_kernel.rst
prepare_kernel_dev.rst
kernel_overview.rst
sysctl.rst

.. only:: subproject and html

Expand Down
40 changes: 40 additions & 0 deletions source/kernel/startup/sysctl.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _sysctl:

=================
sysctl
=================

``sysctl`` 命令工具可以动态修改内核参数

快速起步
==========

- 列出所有系统内核变量(参数值):

.. literalinclude:: sysctl/sysctl_a
:caption: 列出所有内核变量及值

- 读取变量(这里案例是读取 ``kernel.version`` ):

.. literalinclude:: sysctl/sysctl_read
:caption: 读取 ``kernel.version`` 内核参数

- 临时修改内核变量:

.. literalinclude:: sysctl/sysctl_change
:caption: 临时修改内核参数

- 修改内核变量持久化(也就是写入配置文件,重启依然生效):

.. literalinclude:: sysctl/sysctl_change_permanently
:caption: 永久修改内核参数

.. note::

内核参数除了配置在 ``/etc/sysctl.conf`` 配置文件,也可以将大配置文件拆解成多个存储在 ``/etc/sysctl.d`` 目录下的各个配置文件


参考
======

- `Product Documentation > Red Hat Enterprise Linux > 7 > Kernel Administration Guide > Chapter 2. Working with sysctl and kernel tunables <https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/kernel_administration_guide/working_with_sysctl_and_kernel_tunables>`_
1 change: 1 addition & 0 deletions source/kernel/startup/sysctl/sysctl_a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sysctl -a
1 change: 1 addition & 0 deletions source/kernel/startup/sysctl/sysctl_change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sysctl <tunable class>.<tunable>=<value>
1 change: 1 addition & 0 deletions source/kernel/startup/sysctl/sysctl_change_permanently
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sysctl -w <tunable class>.<tunable>=<value> >> /etc/sysctl.conf
1 change: 1 addition & 0 deletions source/kernel/startup/sysctl/sysctl_read
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sysctl kernel.version
1 change: 1 addition & 0 deletions source/kubernetes/network/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Kubernetes只支持基于Container Network Interface(CNI)的网络,需要通
k8s_network_infa.rst
k8s_loadbalancer_ingress.rst
dynamic_dns_loadbalancing_without_cloud_provider.rst
k8s_hosts_file_for_pods.rst
ingress/index
flannel/index
cilium/index
Expand Down
43 changes: 43 additions & 0 deletions source/kubernetes/network/k8s_hosts_file_for_pods.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.. _k8s_hosts_file_for_pods:

================================
Kubernetes配置Pods中的hosts文件
================================

在故障排查中(也可能测试环境),需要为 pod 中注入 ``/etc/hosts`` 配置,以便能够绕过DNS解析来直接访问目标服务器。在Kubernetes中, ``PodSpec`` 段落提供了 ``HostAliases`` 字段完成配置:

.. literalinclude:: k8s_hosts_file_for_pods/hostalias.yaml
:language: yaml
:caption: 为pod添加hosts

- 测试:

.. literalinclude:: k8s_hosts_file_for_pods/kubectl_hostalias
:caption: 创建测试pods

- 检查:

.. literalinclude:: k8s_hosts_file_for_pods/kubectl_get_hostalias
:caption: 查看创建的测试pods

输出可以看到运行的pod:

.. literalinclude:: k8s_hosts_file_for_pods/kubectl_get_hostalias_output
:caption: 查看创建的测试pods


- 查看日志:

.. literalinclude:: k8s_hosts_file_for_pods/kubectl_logs_hostalias
:caption: 查看创建的测试pods的日志

- 日志结果(就是 ``cat /etc/hosts`` 的输出内容验证):

.. literalinclude:: k8s_hosts_file_for_pods/kubectl_logs_hostalias_output
:caption: 查看创建的测试pods的日志内容就是 hosts 内容


参考
=======

- `Adding entries to Pod /etc/hosts with HostAliases <https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/>`_

0 comments on commit b99f996

Please sign in to comment.