在CentOS上安装Python3的三种方法

原文地址https://www.centos.bz/2018/01/%E5%9C%A8centos%E4%B8%8A%E5%AE%89%E8%A3%85python3%E7%9A%84%E4%B8%89%E7%A7%8D%E6%96%B9%E6%B3%95/

Centos7默认自带了Python2.7版本,但是因为项目需要使用Python3.x你可以按照此文的三个方法进行安装.

注:本文示例安装版本为Python3.6,

一、Python源代码编译安装

安装必要工具 yum-utils ,它的功能是管理repository及扩展包的工具 (主要是针对repository)

$ sudo yum install yum-utils

使用yum-builddep为Python3构建环境,安装缺失的软件依赖,使用下面的命令会自动处理.

$ sudo yum-builddep python

完成后下载Python3的源码包,目前最新是3.7.4,Python源码包目录: https://www.python.org/ftp/python/ ,是不是最新的直接去官网查

https://www.python.org/downloads/source/

$ curl -O https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

最后一步,编译安装Python3,默认的安装目录是 /usr/local 如果你要改成其他目录可以在编译(make)前使用 configure 命令后面追加参数 “–prefix=/alternative/path” 来完成修改。

$ tar xf Python-3.7.4.tgz
$ cd Python-3.7.4
$ ./configure
$ make
$ sudo make install

至此你已经在你的CentOS系统中成功安装了python3、pip3、setuptools,查看python版本

$ python3 -V

如果你要使用Python3作为python的默认版本,你需要修改一下 bashrc 文件,增加一行alias参数

alias python='/usr/local/bin/python3.7'

由于CentOS 7建议不要动/etc/bashrc文件,而是把用户自定义的配置放入/etc/profile.d/目录中,具体方法为

vi /etc/profile.d/python.sh

输入alias参数 alias python=’/usr/local/bin/python3.5’,保存退出

如果非root用户创建的文件需要注意设置权限

chmod 755 /etc/profile.d/python.sh

重启会话使配置生效

source /etc/profile.d/python.sh

二、从EPEL仓库安装

最新的EPEL 7仓库提供了Python3(python 3.4)的安装源,如果你使用CentOS7或更新的版本的系统你也可以按照下面的步骤很轻松的从EPEL仓库安装。

安装最新版本的EPEL

$ sudo yum install epel-release

用yum安装python 3.6:

$ sudo yum install python36

注意:上面的安装方法并未安装pip和setuptools,如果你要安装这两个库可以使用下面的命令:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo /usr/bin/python3.6 get-pip.py

三、从SCL(Software Collections)仓库安装

最后一种方法是通过Software Collections (SCL) repository来安装,需要注意的是SCL仓库仅支持CentOS 6.5以上版本,最新版的SCL提供了Python3.3版本,具体安装步骤:

$ sudo yum install python36

从SCL中使用python3,你需要一行命令来启用Python3:

$ scl enable python36 

您还可以使用Python编译器来调用一个bash shell:

$ scl enable python36 bash
发表在 python | 标签为 | 留下评论

yum配置mariaDB仓库

官方有多种方法配置mariaDB仓库,我复制了一份,方便不能正常打开的朋友,直接看后面的原文。

我喜欢跑官方给出的脚本,一劳永逸,最新版,执行下面语句

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

我把我机器的结果贴出来了,你也可以直接复制

[mariadb-main]
name = MariaDB Server
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-10.4/yum/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck = 1
enabled = 1

[mariadb-maxscale]
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
name = MariaDB MaxScale
baseurl = https://downloads.mariadb.com/MaxScale/2.3/centos/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY
gpgcheck = 1
enabled = 1

[mariadb-tools]
name = MariaDB Tools
baseurl = https://downloads.mariadb.com/Tools/rhel/$releasever/$basearch
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY
gpgcheck = 1
enabled = 1

Installing MariaDB with yum/dnf

On RHEL, CentOS, Fedora, and other similar Linux distributions, it is highly recommended to install the relevant RPM packages from MariaDB’s repository using yum or dnf. Starting with RHEL 8 and Fedora 22, yum has been replaced by dnf, which is the next major version of yum. However, yum commands still work on many systems that use dnf.

This page walks you through the simple installation steps using yum.

Adding the MariaDB YUM repository

We currently have YUM repositories for the following Linux distributions:

  • Red Hat Enterprise Linux (RHEL) 6
  • Red Hat Enterprise Linux (RHEL) 7
  • CentOS 6
  • CentOS 7
  • Fedora 27
  • Fedora 28
  • Fedora 29

Using the MariaDB Package Repository Setup Script

If you want to install MariaDB with yum, then you can configure yum to install from MariaDB Corporation’s MariaDB Package Repository by using the MariaDB Package Repository setup script.

MariaDB Corporation provides a MariaDB Package Repository for several Linux distributions that use yum to manage packages. This repository contains software packages related to MariaDB Server, including the server itself, clients and utilitiesclient librariesplugins, and Mariabackup. The MariaDB Package Repository setup script automatically configures your system to install packages from the MariaDB Package Repository.

To use the script, execute the following command:

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

Note that this script also configures a repository for MariaDB MaxScale and a repository for MariaDB Tools, which currently only contains Percona XtraBackup and its dependencies.

See MariaDB Package Repository Setup and Usage for more information.

Using the MariaDB Repository Configuration Tool

If you want to install MariaDB with yum, then you can configure yum to install from MariaDB Foundation’s MariaDB Repository by using the MariaDB Repository Configuration Tool.

The MariaDB Foundation provides a MariaDB repository for several Linux distributions that use yum to manage packages. This repository contains software packages related to MariaDB Server, including the server itself, clients and utilitiesclient librariesplugins, and Mariabackup. The MariaDB Repository Configuration Tool can easily generate the appropriate configuration file to add the repository for your distribution.

Once you have the appropriate repository configuration section for your distribution, add it to a file named MariaDB.repo under /etc/yum.repos.d/.

For example, if you wanted to use the repository to install MariaDB 10.3 on CentOS 7, then you could use the following yum repository configuration in /etc/yum.repos.d/MariaDB.repo:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

The example file above includes a gpgkey line to automatically fetch the GPG public key that is used to verify the digital signatures of the packages in our repositories. This allows the the yumdnf, and rpm utilities to verify the integrity of the packages that they install.

Pinning the MariaDB Repository to a Specific Minor Release

If you wish to pin the yum repository to a specific minor release, or if you would like to do a yum downgrade to a specific minor release, then you can create a yum repository configuration with a baseurl option set to that specific minor release.

The MariaDB Foundation archives repositories of old minor releases at the following URL:

So if you can’t find the repository of a specific minor release at yum.mariadb.org, then it would be a good idea to check the archive.

For example, if you wanted to pin your repository to MariaDB 10.3.14 on CentOS 7, then you could use the following yum repository configuration in /etc/yum.repos.d/MariaDB.repo:

[mariadb]
name = MariaDB-10.3.14
baseurl=http://yum.mariadb.org/10.3.14/centos7-amd64
# alternative: baseurl=http://archive.mariadb.org/mariadb-10.3.14/yum/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Note that if you change an existing repository configuration, then you need to execute the following:

sudo yum clean all

Updating the MariaDB YUM repository to a New Major Release

MariaDB’s yum repository can be updated to a new major release. How this is done depends on how you originally configured the repository.

Updating the Major Release with the MariaDB Package Repository Setup Script

If you configured yum to install from MariaDB Corporation’s MariaDB Package Repository by using the MariaDB Package Repository setup script, then you can update the major release that the repository uses by running the script again.

Updating the Major Release with the MariaDB Repository Configuration Tool

If you configured yum to install from MariaDB Foundation’s MariaDB Repository by using the MariaDB Repository Configuration Tool, then you can update the major release that the repository uses by updating the yum repository configuration file in-place. For example, if you wanted to change the repository from MariaDB 10.2 to MariaDB 10.3, and if the repository configuration file was at /etc/yum.repos.d/MariaDB.repo, then you could execute the following:

sudo sed -i 's/10.2/10.3/' /etc/yum.repos.d/MariaDB.repo

After that, the repository should refer to MariaDB 10.3.

Importing the MariaDB GPG Public Key

Before MariaDB can be installed, you also have to import the GPG public key that is used to verify the digital signatures of the packages in our repositories. This allows the yumdnf and rpm utilities to verify the integrity of the packages that they install.

The id of our GPG public key is 0xcbcb082a1bb943db. The short form of the id is 0x1BB943DB. The full key fingerprint is:

1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB

yum should prompt you to import the GPG public key the first time that you install a package from MariaDB’s repository. However, if you like, the rpm utility can be used to manually import this key instead. For example:

sudo rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

Once the GPG public key is imported, you are ready to install packages from the repository.

Installing MariaDB Packages with YUM

After the yum repository is configured, you can install MariaDB by executing the yum command. The specific command that you would use would depend on which specific packages that you want to install.

Installing the Most Common Packages with YUM

MariaDB starting with 10.4

In MariaDB 10.4 and later, to Install the most common packages, execute the following command:

sudo yum install MariaDB-server galera-4 MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common
MariaDB until 10.3

In MariaDB 10.3 and before, to Install the most common packages, execute the following command:

sudo yum install MariaDB-server galera MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common

Installing MariaDB Server with YUM

To Install MariaDB Server, execute the following command:

sudo yum install MariaDB-server

Installing MariaDB Galera Cluster with YUM

The process to install MariaDB Galera Cluster with the MariaDB yum repository is practically the same as installing standard MariaDB Server.

In MariaDB 10.1 and later, Galera Cluster support has been included in the standard MariaDB Server packages, so you will need to install the MariaDB-server package, as you normally would.

In MariaDB 10.4 and later, you also need to install the galera-4 package to obtain the Galera 4 wsrep provider library.

In MariaDB 10.3 and before, you also need to install the galera package to obtain the Galera 3 wsrep provider library.

MariaDB starting with 10.4

In MariaDB 10.4 and later, to install MariaDB Galera Cluster, you could execute the following command:

sudo yum install MariaDB-server MariaDB-client galera-4
MariaDB until 10.3

In MariaDB 10.3 and before, to install MariaDB Galera Cluster, you could execute the following command:

sudo yum install MariaDB-server MariaDB-client galera

If you haven’t yet imported the MariaDB GPG public key, then yum will prompt you to import it after it downloads the packages, but before it prompts you to install them.

See MariaDB Galera Cluster for more information on MariaDB Galera Cluster.

Installing MariaDB Clients and Client Libraries with YUM

In MariaDB 10.2 and later, MariaDB Connector/C has been included as the client library. However, the package name for the client library has not been changed.

To Install the clients and client libraries, execute the following command:

sudo yum install MariaDB-client MariaDB-shared

Installing Mariabackup with YUM

To install Mariabackup, execute the following command:

sudo yum install MariaDB-backup

Installing Plugins with YUM

Some plugins may also need to be installed.

For example, to install the cracklib_password_check password validation plugin, execute the following command:

sudo yum install MariaDB-cracklib-password-check

Installing Debug Info Packages with YUM

MariaDB starting with 5.5.64

The MariaDB yum repository first added debuginfo packages in MariaDB 5.5.64MariaDB 10.1.39MariaDB 10.2.23MariaDB 10.3.14, and MariaDB 10.4.4.

The MariaDB yum repository also contains debuginfo packages. These package may be needed when debugging a problem.

Installing Debug Info for the Most Common Packages with YUM

To install debuginfo for the most common packages, execute the following command:

sudo yum install MariaDB-server-debuginfo MariaDB-client-debuginfo MariaDB-shared-debuginfo MariaDB-backup-debuginfo MariaDB-common-debuginfo

Installing Debug Info for MariaDB Server with YUM

To install debuginfo for MariaDB Server, execute the following command:

sudo yum install MariaDB-server-debuginfo

Installing Debug Info for MariaDB Clients and Client Libraries with YUM

In MariaDB 10.2 and later, MariaDB Connector/C has been included as the client library. However, the package name for the client library has not been changed.

To install debuginfo for the clients and client libraries, execute the following command:

sudo yum install MariaDB-client-debuginfo MariaDB-shared-debuginfo

Installing Debug Info for Mariabackup with YUM

To install debuginfo for Mariabackup, execute the following command:

sudo yum install MariaDB-backup-debuginfo

Installing Debug Info for Plugins with YUM

For some pluginsdebuginfo may also need to be installed.

For example, to install debuginfo for the cracklib_password_check password validation plugin, execute the following command:

sudo yum install MariaDB-cracklib-password-check-debuginfo

Installing Older Versions from the Repository

The MariaDB yum repository contains the last few versions of MariaDB. To show what versions are available, use the following command:

yum list --showduplicates MariaDB-server

In the output you will see the available versions. For example:

$ yum list --showduplicates MariaDB-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.mirrors.ovh.net
 * extras: centos.mirrors.ovh.net
 * updates: centos.mirrors.ovh.net
Available Packages
MariaDB-server.x86_64   10.3.10-1.el7.centos    mariadb
MariaDB-server.x86_64   10.3.11-1.el7.centos    mariadb
MariaDB-server.x86_64   10.3.12-1.el7.centos    mariadb
mariadb-server.x86_64   1:5.5.60-1.el7_5         base   

The MariaDB yum repository in this example contains MariaDB 10.3.10MariaDB 10.3.11, and MariaDB 10.3.12. The CentOS base yum repository also contains MariaDB 5.5.60.

To install an older version of a package instead of the latest version we just need to specify the package name, a dash, and then the version number. And we only need to specify enough of the version number for it to be unique from the other available versions.

However, when installing an older version of a package, if yum has to install dependencies, then it will automatically choose to install the latest versions of those packages. To ensure that all MariaDB packages are on the same version in this scenario, it is necessary to specify them all.

The packages that the MariaDB-server package depend on are: MariaDB-client, MariaDB-shared, and MariaDB-common. Therefore, to install MariaDB 10.3.11 from this yum repository, we would do the following:

sudo yum install MariaDB-server-10.3.11 MariaDB-client-10.3.11 MariaDB-shared-10.3.11 MariaDB-backup-10.3.11 MariaDB-common-10.3.11

The rest of the install and setup process is as normal.

After Installation

After the installation is complete, you can start MariaDB.

If you are using MariaDB Galera Cluster, then keep in mind that the first node will have to be bootstrapped.

发表在 mariadb | 标签为 | 留下评论

shell变量类型

一、定义一个变量

shell在定义变量的时候,变量名与变量之间不能存在空格,这个大多数的语言的这个不同还是蛮大的,不过定义的规则就其他的语言定义的规则大致相同了。
使用变量

使用一个已经定义过的变量,只需要在变量的名字前加$,例如下面的例子。
在使用变量额时候

[root@n7 ~]# cat test.sh
#!/bin/bash
line=”hello world”
echo $line
echo ${line}  #可以的添加一个{},添加一个边界,更加的醒目,好理解
[root@n7 ~]# sh test.sh
hello world
hello world

1、只读变量 readonly

在变量的前面 添加readonly把变量定义为一个只能读取的变量,无法进行修改。

[root@n7 ~]# cat test2.sh
#!/bin/bash
name=”fencatn”
readonly name
name=”test”
echo $name
[root@n7 ~]# sh test2.sh
test2.sh: line 4: name: readonly variable
#这里就是为了让大家看这个输出报错,提示是一个只读变量

2、删除变量unset

使用unset定义一个变量,变量的内容就被删除了。

[root@n7 ~]# cat test3.sh
#!/bin/bash
name=”fencatn”
echo “1-$name”
unset name
echo “2-$name”
[root@n7 ~]# sh test3.sh
1-fencatn
2-
[root@n7 ~]#

注意看第2个变量没输出,因为被取消定义了

shell变量的类型

和其他的语言中一样,shell中的变量也是分为不同的类型的。
– 全局变量(环境变量)
– 局部变量(普通变量)

3、全局变量(环境变量)

在Linux中,内置了一些环境变量,如HOME,PATH,SHELL,UID,GID,HOSTNAME等,可以通过命令env显示所有的环境变量。

[root@n7 ~]# echo $HOME
/root
[root@n7 ~]#

定义环境变量

用户也可以根据自己的需要定义自己的环境变量(全局变量),定义环境变量的方法:

export variable_name=value
#or
variable_name=value
export variable_name

举个例子:

export NAME=idealcitier

[root@n7 ~]# export website=fencatn.com
[root@n7 ~]# env | grep website
website=fencatn.com

可以看出,定义的环境变量,成功了。
对环境变量进行操作

可以使用echo对环境变量进行显示。
[root@n7 ~]# echo $website
fencatn.com

利用env,显示所有的环境变量。
[root@n7 ~]# env
XDG_SESSION_ID=1
HOSTNAME=n7
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=192.168.0.15 51152 22
SSH_TTY=/dev/pts/0
USER=root

清除环境变量unset

[root@n7 ~]# export website=fencatn.com
[root@n7 ~]# echo $website
fencatn.com
[root@n7 ~]# unset website
[root@n7 ~]# echo $website

[root@n7 ~]#

4、普通变量

环境变量一般在脚本或命令中进行定义,只在当前的shell中有效,其他启动的shell这个变量是无效的。

variable_name=name

 

二、shell字符串

字符串使用单引号”和双引号””。
1、单引号

单引号中所有的字符都是原样的输出,也就是说单引号中的变量是无效的。
单引号中无能再出现单引号了,对转移符也无效

2、双引号

双引号中可以有变量
可以使用转移符

[root@n7 ~]# str=’name is fencatn’
[root@n7 ~]# echo “my $str”
my name is fencatn
[root@n7 ~]# echo ‘my $str’
my $str
[root@n7 ~]#

3、拼接字符串

[root@n7 ~]# name=’fencatn’
[root@n7 ~]# age=’18’
[root@n7 ~]# list1=”hello,my name is $name”
[root@n7 ~]# list2=”my age is $age”
[root@n7 ~]# echo “$list1 , $list2”
hello,my name is fencatn , my age is 18
[root@n7 ~]#

4、获取字符串长度

[root@n7 ~]# test=”akjdflkjsaf”
[root@n7 ~]# echo ${#test}
11
[root@n7 ~]#

4、提取子字符串

以下实例从字符串第 2 个字符开始截取 4 个字符:

[root@n7 ~]# test2=”my name is fencatn”
[root@n7 ~]# echo ${test2:3:7}
name is
[root@n7 ~]#

6、查找子字符串

查找字符 “i 或 s” 的位置:

[root@n7 ~]# test2=”my name is fencatn”
[root@n7 ~]# echo `expr index “$test2” n`
4
[root@n7 ~]# echo `expr index “$test2” s`
10
[root@n7 ~]# echo `expr index “$test2” is`
9
[root@n7 ~]#

 

三、shell数组

支持一维数组(不支持多维数组),并且没有限定数组的大小。
类似与C语言,数组元素的下标由0开始编号。获取数组中的元素要利用下标,下标可以是整数或算术表达式,其值应大于或等于0。
定义数组

在Shell中,用括号来表示数组,数组元素用”空格”符号分割开。定义数组的一般形式为:
数组名=(值1 值2 … 值n)

array_name=(value0 value1 value2 value3)

or

array_name=(
value0
value1
value2
value3
)

还可以单独定义数组的各个分量:

array_name[0]=value0
array_name[1]=value1
array_name[n]=valuen

可以不使用连续的下标,而且下标的范围没有限制。
读取数组

读取数组元素值的一般格式是:
${数组名[下标]},也就是valuen=${array_name[n]}

使用@符号可以获取数组中的所有元素,例如:

echo ${array_name[@]}

获取数组的长度

获取数组长度的方法与获取字符串长度的方法相同,例如:
取得数组元素的个数

length=${#array_name[@]}

or

length=${#array_name[*]}

取得数组单个元素的长度

lengthn=${#array_name[n]}

本文参考http://www.runoob.com/linux/linux-shell-variable.html

发表在 shell | 标签为 | 留下评论

shell常用正则表达式实例

以下内容,转自:https://blog.csdn.net/sty124578/article/details/79408880

正则表达式的分类

1、基本的正则表达式(Basic Regular Expression 又叫Basic RegEx 简称BREs)
2、扩展的正则表达式(Extended Regular Expression 又叫Extended RegEx 简称EREs)
3、Perl的正则表达式(Perl Regular Expression 又叫Perl RegEx 简称PREs)

shell常用正则表达式

“^\d+$” //非负整数(正整数 + 0)
“^[0-9]*[1-9][0-9]*$” //正整数
“^((-\d+)|(0+))$” //非正整数(负整数 + 0)
“^-[0-9]*[1-9][0-9]*$” //负整数
“^-?\d+$” //整数
“^\d+(\.\d+)?$” //非负浮点数(正浮点数 + 0)
“^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$” //正浮点数
“^((-\d+(\.\d+)?)|(0+(\.0+)?))$” //非正浮点数(负浮点数 + 0)
“^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$” //负浮点数
“^(-?\d+)(\.\d+)?$” //浮点数
“^[A-Za-z]+$” //由26个英文字母组成的字符串
“^[A-Z]+$” //由26个英文字母的大写组成的字符串
“^[a-z]+$” //由26个英文字母的小写组成的字符串
“^[A-Za-z0-9]+$” //由数字和26个英文字母组成的字符串
“^\w+$” //由数字、26个英文字母或者下划线组成的字符串
“^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$” //email地址
“^[a-zA-z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$” //url
/^(d{2}|d{4})-((0([1-9]{1}))|(1[1|2]))-(([0-2]([1-9]{1}))|(3[0|1]))$/   //  年-月-日
/^((0([1-9]{1}))|(1[1|2]))/(([0-2]([1-9]{1}))|(3[0|1]))/(d{2}|d{4})$/   // 月/日/年
“^([w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$”   //Emil
/^((\+?[0-9]{2,4}\-[0-9]{3,4}\-)|([0-9]{3,4}\-))?([0-9]{7,8})(\-[0-9]+)?$/     //电话号码
“^(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5]).(d{1,2}|1dd|2[0-4]d|25[0-5])$”   //IP地址

元字符及其在正则表达式上下文中的行为: 

\      将下一个字符标记为一个特殊字符、或一个原义字符、或一个后向引用、或一个八进制转义符。
^     匹配输入字符串的开始位置。如果设置了 RegExp 对象的Multiline 属性,^ 也匹配 ‘\n’ 或 ‘\r’ 之后的位置。
$      匹配输入字符串的结束位置。如果设置了 RegExp 对象的Multiline 属性,$ 也匹配 ‘\n’ 或 ‘\r’ 之前的位置。
*      匹配前面的子表达式零次或多次。
+     匹配前面的子表达式一次或多次。+ 等价于 {1,}。
?      匹配前面的子表达式零次或一次。? 等价于 {0,1}。
{n}      n 是一个非负整数,匹配确定的n 次。
{n,}     n 是一个非负整数,至少匹配n 次。
{n,m}  m 和 n 均为非负整数,其中n <= m。最少匹配 n 次且最多匹配 m 次。在逗号和两个数之间不能有空格。
?        当该字符紧跟在任何一个其他限制符 (*, +, ?, {n}, {n,}, {n,m}) 后面时,匹配模式是非贪婪的。非贪婪模式尽可能少的匹配所搜索的字符串,而默认的贪婪模式则尽可能多的匹配所搜索的字符串。

.         匹配除 “\n” 之外的任何单个字符。要匹配包括 ‘\n’ 在内的任何字符,请使用象 ‘[.\n]’ 的模式。

(pattern)         匹配pattern 并获取这一匹配。
(?:pattern)       匹配pattern 但不获取匹配结果,也就是说这是一个非获取匹配,不进行存储供以后使用。
(?=pattern)     正向预查,在任何匹配 pattern 的字符串开始处匹配查找字符串。这是一个非获取匹配,也就是说,该匹配不需要获取供以后使用。
(?!pattern)       负向预查,与(?=pattern)作用相反

x|y         匹配 x 或 y。
[xyz]      字符集合。
[^xyz]    负值字符集合。
[a-z]      字符范围,匹配指定范围内的任意字符。
[^a-z]    负值字符范围,匹配任何不在指定范围内的任意字符。
\b          匹配一个单词边界,也就是指单词和空格间的位置。
\B          匹配非单词边界。
\cx         匹配由x指明的控制字符。
\d          匹配一个数字字符。等价于 [0-9]。
\D          匹配一个非数字字符。等价于 [^0-9]。
\f           匹配一个换页符。等价于 \x0c 和 \cL。
\n          匹配一个换行符。等价于 \x0a 和 \cJ。
\r           匹配一个回车符。等价于 \x0d 和 \cM。
\s           匹配任何空白字符,包括空格、制表符、换页符等等。等价于[ \f\n\r\t\v]。
\S           匹配任何非空白字符。等价于 [^ \f\n\r\t\v]。
\t           匹配一个制表符。等价于 \x09 和 \cI。
\v           匹配一个垂直制表符。等价于 \x0b 和 \cK。
\w          匹配包括下划线的任何单词字符。等价于'[A-Za-z0-9_]’。
\W         匹配任何非单词字符。等价于 ‘[^A-Za-z0-9_]’。
\xn         匹配 n,其中 n 为十六进制转义值。十六进制转义值必须为确定的两个数字长。

\num      匹配 num,其中num是一个正整数。对所获取的匹配的引用。

\n            标识一个八进制转义值或一个后向引用。如果 \n 之前至少 n 个获取的子表达式,则 n 为后向引用。否则,如果 n 为八进制数字 (0-7),则 n 为一个八进制转义值。
\nm         标识一个八进制转义值或一个后向引用。如果 \nm 之前至少有is preceded by at least nm 个获取得子表达式,则 nm 为后向引用。如果 \nm 之前至少有 n 个获取,则 n 为一个后跟文字 m 的后向引用。如果前面的条件都不满足,若 n 和 m 均为八进制数字 (0-7),则 \nm 将匹配八进制转义值 nm。
\nml         如果 n 为八进制数字 (0-3),且 m 和 l 均为八进制数字 (0-7),则匹配八进制转义值 nml。

\un           匹配 n,其中 n 是一个用四个十六进制数字表示的Unicode字符。

常用正则表达式

匹配中文字符的正则表达式: [\u4e00-\u9fa5]
匹配双字节字符(包括汉字在内):[^\x00-\xff]
匹配空行的正则表达式:\n[\s| ]*\r
匹配HTML标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/
匹配首尾空格的正则表达式:(^\s*)|(\s*$)
匹配IP地址的正则表达式:/(\d+)\.(\d+)\.(\d+)\.(\d+)/g //
匹配Email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
匹配网址URL的正则表达式:http://(/[\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?

sql语句:^(select|drop|delete|create|update|insert).*$ 

1、非负整数:^\d+$
2、正整数:^[0-9]*[1-9][0-9]*$
3、非正整数:^((-\d+)|(0+))$
4、负整数:^-[0-9]*[1-9][0-9]*$
5、整数:^-?\d+$
6、非负浮点数:^\d+(\.\d+)?$
7、正浮点数:^((0-9)+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)| ([0-9]*[1-9][0-9]*))$
8、非正浮点数:^((-\d+\.\d+)?)|(0+(\.0+)?))$
9、负浮点数:^(-((正浮点数正则式)))$
10、英文字符串:^[A-Za-z]+$
11、英文大写串:^[A-Z]+$
12、英文小写串:^[a-z]+$
13、英文字符数字串:^[A-Za-z0-9]+$
14、英数字加下划线串:^\w+$
15、E-mail地址:^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$
16、URL:^[a-zA-Z]+://(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\s*)?$
或:^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\’:+!]*([^& lt;>\”\”])*$
17、邮政编码:^[1-9]\d{5}$
18、中文:^[\u0391-\uFFE5]+$
19、电话号码:^((\d2,3

)|(\d{3}\-))?(0\d2,3|0\d{2,3}-)?[1-9] \d{6,7}(\-\d{1,4})?$
20、手机号码:^((\d2,3)|(\d{3}\-))?13\d{9}$
21、双字节字符(包括汉字在内):^\x00-\xff
22、匹配首尾空格:(^\s*)|(\s*$)(像vbscript那样的trim函数)
23、匹配HTML标记:<(.*)>.*<\/\1>|<(.*) \/>
24、匹配空行:\n[\s| ]*\r
25、提取信息中的网络链接:(h|H)(r|R)(e|E)(f|F) *= *(‘|”)?(\w|\\|\/|\.)+(‘|”| *|>)?
26、提取信息中的邮件地址:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
27、提取信息中的图片链接:(s|S)(r|R)(c|C) *= *(‘|”)?(\w|\\|\/|\.)+(‘|”| *|>)?
28、提取信息中的IP地址:(\d+)\.(\d+)\.(\d+)\.(\d+)
29、提取信息中的中国手机号码:(86)*0*13\d{9}
30、提取信息中的中国固定电话号码:(\d3,4|\d{3,4}-|\s)?\d{8}
31、提取信息中的中国电话号码(包括移动和固定电话):(\d3,4|\d{3,4}-|\s)?\d{7,14}
32、提取信息中的中国邮政编码:[1-9]{1}(\d+){5}
33、提取信息中的浮点数(即小数):(-?\d*)\.?\d+
34、提取信息中的任何数字 :(-?\d*)(\.\d+)?
35、IP:(\d+)\.(\d+)\.(\d+)\.(\d+)
36、电话区号:/^0\d{2,3}$/
37、腾讯QQ号:^[1-9]*[1-9][0-9]*$
38、帐号(字母开头,允许5-16字节,允许字母数字下划线):^[a-zA-Z][a-zA-Z0-9_]{4,15}$
39、中文、英文、数字及下划线:^[\u4e00-\u9fa5_a-zA-Z0-9]+$

发表在 shell | 标签为 | 留下评论

shell正则表达式基础

正则表达式是操作字符串的一种逻辑公式,他使用事先定义好的特殊字符和这些特殊字符所构成的一种组合。正则表达式规定一些特殊语法,用来表示字符类、数量限定符和位置关系,然后用这些特殊语法和普通字符一起表示一个模式,这就是正则表达式(Regular Expression)。

如上面所说,正则表达式有三部分组成:字符类、数量限定符、位置限定符。下面详细举例说明。

1、字符类

. 匹配任意一个字符,比如下图所示food. 可以匹配fooda foodabcd

[ ] 匹配中括号中的任意一个字符,- 表示字符的范围,当然,你可以写任意字符。比如下图所示的[a-z]可以匹配a到z的所有字母

^ 可以匹配除了括号中的字符外的任意字符

[[:xxx:]]是grep工具预定义的一些命名字符,可以灵活使用

 

2、数量限定符

比如说,合法的邮箱地址,每一部分都可以有一个或者多个x字符,合法的IP地址每一部分可以有1-3个字符,等等

?紧跟在?前面的单元应匹配0次或者1次

+紧跟在+前面的单元应匹配1次或者多次

*紧跟在*前面的单元应匹配0次或者多次

{N}紧跟在{N}前面的单元应精确匹配N次,例如[1-9][0-9]{2}匹配100-999的整数

{N,}紧跟在它前面的单元应至少N次,例如[1-9][0-9]{2}匹配3位以上的整数

{,M}紧跟在它前面的单元应最多匹配M次,例如[0-9]{,2}表示最多匹配1次数字

{N,M}紧跟在它前面的单元匹配至少N次,最多M次,例如[0-9]{1,3}表示0-9数字至少匹配1次,最多匹配3次

 

3、位置 限定符

位置限定符(Anchor):描述各种字符类以及普通字符之间的位置关系,例如邮件地址分三部分,用普通字符@和.隔 开,IP地址分四部分,用.隔开,每一部分都可以用字符类和数量限定符描述。

^匹配行首的位置

$匹配行末的位置

\<匹配单词开头的位置

\>匹配单词词尾的位置

匹配某个单词

\b匹配单词的开头或者结尾的位置

\B匹配非单词开头或者结尾的位置

 

4、特殊字符

\转义字符,普通字符转为特殊字符,特殊字符转为普通字符。比如我们上面看到的\<就代表开头,因为<是个普通字符;而\.就是把特殊字符.转为普通字符的. 例如去匹配IP地址的时候就需要用到

() 将正则表达式的一部分括起来组成一个单元,可以对整个单元来使用数量限定符。例如可以用来表示IP地址。(下图的例子的意思我翻译一下,就是以0到9的数字出现1次到3次,也就是1到3位数嘛,并且后面跟着一个小数点.以这个为整体,用括号括起来,出现了3次。然后以0-9的3位数结尾的一组数字)

|连接2个子表达式,表示或的关系。例如使用^h|^H来匹配hello或者Hello

发表在 shell | 标签为 | 留下评论

ansible批量分发ssh公钥实现免密

1、在hosts里面定义好用户名和密码

[root@n0 ansible]# grep -v "^#" /etc/ansible/hosts | grep -v "^$"
[rancher]
n1 ansible_ssh_user="root" ansible_ssh_pass="123456"
n2 ansible_ssh_user="root" ansible_ssh_pass="123456"
[nginx]
n3 ansible_ssh_user="root" ansible_ssh_pass="123456"
[rancheragent]
n4 ansible_ssh_user="root" ansible_ssh_pass="123456"
n5 ansible_ssh_user="root" ansible_ssh_pass="123456"
[gitlab]
n6 ansible_ssh_user="root" ansible_ssh_pass="123456"
[jenkins]
n7 ansible_ssh_user="root" ansible_ssh_pass="123456"
[harbormysql]
n8 ansible_ssh_user="root" ansible_ssh_pass="123456"
[root@n0 ansible]#

2、写playbook

[root@n0 ansible]# cat ssh3.
cat: ssh3.: No such file or directory
[root@n0 ansible]# cat ssh3.
ssh3.retry ssh3.yml 
[root@n0 ansible]# cat ssh3.yml 
---
- hosts: all
gather_facts: no

tasks:

- name: install ssh key
authorized_key: user=root
key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}" 
state=present
[root@n0 ansible]#

3、生成密钥

[root@n0 ansible]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Ir1UbXrjinufSLitv5rmwYpZwKMc4rwUYbIybbbSQmU root@n0
The key's randomart image is:
+---[RSA 2048]----+
| |
| . |
|.o E . o |
|o++ . . o |
|=+B . + S o |
|B*o+ + + o . |
|+=o . = . . |
|.o.+ ..B.o . |
| .o .oO**oo |
+----[SHA256]-----+
[root@n0 ansible]#

4、发公钥

[root@n0 ansible]# ansible-playbook ssh3.yml

PLAY [all] *********************************************************************************************************************************************************************************************************************************************************************************************************************************

TASK [install ssh key] *********************************************************************************************************************************************************************************************************************************************************************************************************************
changed: [n4]
changed: [n1]
changed: [n3]
changed: [n6]
changed: [n5]
changed: [n2]
changed: [n7]
changed: [n8]

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************************************************************************
n1 : ok=1 changed=1 unreachable=0 failed=0 
n2 : ok=1 changed=1 unreachable=0 failed=0 
n3 : ok=1 changed=1 unreachable=0 failed=0 
n4 : ok=1 changed=1 unreachable=0 failed=0 
n5 : ok=1 changed=1 unreachable=0 failed=0 
n6 : ok=1 changed=1 unreachable=0 failed=0 
n7 : ok=1 changed=1 unreachable=0 failed=0 
n8 : ok=1 changed=1 unreachable=0 failed=0
发表在 ansible | 标签为 | 留下评论

ssh非交互式密钥分发

ssh非交互式密钥分发
一、用户名和密码相同的情况
原文地址:https://yq.aliyun.com/articles/337907
原文脚本有些问题,我重新修改了一下
1、安装sshpass,负责免交互式登陆ssh,如果要深入了解,看下面的链接
https://linux.cn/article-8086-1.html
[root@n0 ~]# yum install -y sshpass
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.cn99.com
base | 3.6 kB 00:00:00 
extras | 3.4 kB 00:00:00 
updates | 3.4 kB 00:00:00 
Resolving Dependencies
--> Running transaction check
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================================================================================================================================================
Installing:
sshpass x86_64 1.06-2.el7 extras 21 k

Transaction Summary
============================================================================================================================================================================================================================================================================================================================================
Install 1 Package

Total download size: 21 k
Installed size: 38 k
Downloading packages:
sshpass-1.06-2.el7.x86_64.rpm | 21 kB 00:00:00 
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : sshpass-1.06-2.el7.x86_64 1/1 
Verifying : sshpass-1.06-2.el7.x86_64 1/1

Installed:
sshpass.x86_64 0:1.06-2.el7

Complete!
2、编写脚本,这是原作者的脚本
[root@n0 ~]# vim sshpass.sh
[root@n0 ~]# cat sshpass.sh 
#!/bin/bash
passwd=123456
IP_ADDR="211 212 213 214 215 216 217 218"
. /etc/init.d/functions
# 一键生成密钥
if ! [ -f ~/.ssh/id_dsa.pub ];then
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa >/dev/null 2>&1 
echo -e "\033[32m======Local=========\033[0m"
action "Generate the key!" /bin/true
fi

# 批量发送密钥
for i in $IP_ADDR;do
sshpass -p$passwd ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no 192.168.0.${i}" >/dev/null 2>&1

if [ $? == 0 ];then
echo -e "\033[32m=========`ssh 192.168.0.$i hostname`==========\033[0m"
action "发送成功!!!" /bin/true
else
echo -e "\033[31m======192.168.0.$i=======\033[0m"
action "发送失败!!!" /bin/false
fi
done
[root@n0 ~]# sh sshpass.sh 
======Local=========
Generate the key! [ OK ]
======192.168.0.211=======
发送失败!!! [FAILED]
======192.168.0.212=======
发送失败!!! [FAILED]
======192.168.0.213=======
发送失败!!! [FAILED]
======192.168.0.214=======
发送失败!!! [FAILED]
======192.168.0.215=======
发送失败!!! [FAILED]
======192.168.0.216=======
发送失败!!! [FAILED]
======192.168.0.217=======
发送失败!!! [FAILED]
======192.168.0.218=======
发送失败!!! [FAILED]
[root@n0 ~]# cat /root/.ssh/id_dsa.pub 
ssh-dss AAAAB3NzaC1kc3MAAACBAPmHGEIyHpwfdA0qi6HCFx07jR/fzOobZZOPaTDz0lArG7lZflRS6AYCm5IXOxGidqxZNmAcuqKXX8Yk5SHZAk97rXCrOQ+k1JnUEZdsebgzgo8IfkwEWI4D90EI8mAOU3CLohD1NHuJQy1U2MDcbzmVN/G12UasAFJ14QIlDp3RAAAAFQCsGckfliC1/INFi/m8uT0rmmJBGwAAAIAZP021s+4nhvKgT3cc/aWCwAHVzVzH0JTUjia/1bYKSF+NCdWC/NBwELt9gXhwMPgCPOnPtsfLHfMMclPMcFUq7Qxyb2u6ir1iAyjXCCBiRiZ1fe3nZyz1BZ/zgAzWy+LhmGWyYIQ06xthOuD3yk28XzQjbXjEQHeiLqNu450EPQAAAIEA1hOp/OPhLRa95rBJP2rKxXn3+ahmzpgwMhy3wqgBLGeTmwcneLDALS/rYeA+W0+PTnVuMYiEaKlOdeaNOJmgfXqc7iL5GJGcuOY4ur9SpishIjkyVP3z8MkrsjjPIA5rclXlaUI1SjPZlNAVc7a6hhCQADIopLA86SAjwGqJgzo= root@n0

 

运行报错,单独运行一下试试
[root@n0 ~]# sshpass -p$passwd ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no 192.168.0.212"
sshpass: invalid option -- 'i'
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
-f filename Take password to use from file
-d number Use number as file descriptor for getting password
-p password Provide password as argument (security unwise)
-e Password is passed as env-var "SSHPASS"
With no parameters - password will be taken from stdin

-P prompt Which string should sshpass search for to detect a password prompt
-v Be verbose about what you're doing
-h Show help (this screen)
-V Print version information
At most one of -f, -d, -p or -e should be used

 

这是原作者的一个出错,是-o选项的格式没有写对,应该是下面的格式
[root@n0 ~]# ssh-copy-id -i /root/.ssh/id_dsa.pub -o "StrictHostKeyChecking=no" [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_dsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:

 

3、重新编辑脚本
[root@n0 ~]# cat sshpass.sh 
#!/bin/bash
passwd=123456
IP_ADDR="211 212 213 214 215 216 217 218"
. /etc/init.d/functions
# 一键生成密钥
if ! [ -f ~/.ssh/id_dsa.pub ];then
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa >/dev/null 2>&1 
echo -e "\033[32m======Local=========\033[0m"
action "Generate the key!" /bin/true
fi

# 批量发送密钥
for i in $IP_ADDR;do
sshpass -p$passwd ssh-copy-id -i /root/.ssh/id_dsa.pub -o "StrictHostKeyChecking=no" 192.168.0.${i} >/dev/null 2>&1

if [ $? == 0 ];then
echo -e "\033[32m=========`ssh 192.168.0.$i hostname`==========\033[0m"
action "发送成功!!!" /bin/true
else
echo -e "\033[31m======192.168.0.$i=======\033[0m"
action "发送失败!!!" /bin/false
fi
done

 

4、执行和验证,现在对了
[root@n0 ~]# sh sshpass.sh 
=========n1==========
发送成功!!! [ OK ]
=========n2==========
发送成功!!! [ OK ]
=========n3==========
发送成功!!! [ OK ]
=========n4==========
发送成功!!! [ OK ]
=========n5==========
发送成功!!! [ OK ]
=========n6==========
发送成功!!! [ OK ]
=========n7==========
发送成功!!! [ OK ]
=========n8==========
发送成功!!! [ OK ]

 

二、用户名和密码不相同的情况
原文地址:https://www.cnblogs.com/panchong/p/6027138.html
上面的脚本是远程主机的密码都是相同,在命令行将密码硬编码写死,如果每台主机的密码不一样,可以将密码记录在remote-hosts文件中,通过cut命令分割,可以分别获得主机的IP地址或域名和对应的密码,当然如果ssh的端口号不是默认的22,也可以一并记录。如下列格式:


10.10.10.10:2222:YOURPASSWORD

可将上面的脚本稍做修改:

因为ssh-copy-id使用非默认端口时,需要加双引号,没有找到地的办法,取了个巧,先将整个命令放至一个临时文件。再执行该临时文件,执行之后,再删除。

 

for host in $(cat remote-hosts)
do
ip=$(echo ${host} | cut -f1 -d ":")
port=$(echo ${host} | cut -f2 -d ":")
password=$(echo ${host} | cut -f3 -d ":")
  arg=$(echo -p ${port} -o StrickHostKeyChecking=no root@${ip})
  echo sshpass -p ${password} ssh-copy-id '"'${arg}'"' >> tmp.sh
done
sh tmm.sh
rm -f tmp.sh
发表在 ssh | 标签为 | 留下评论

ansible部署免密密钥(单向)

ansible单向部署密钥比较简单,也就是将跳板机(我这里是ansible本机)的公钥部署到远端主机

事先生成公钥就不写了

部署前,不如不加-k输入密码,或者配置文件实现定义好ssh用户和密码,那执行命令是失败的

[root@ansible ~]# ansible all -m ping
jmp1 | UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", 
"unreachable": true
}
jmp3 | UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", 
"unreachable": true
}
jmp2 | UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", 
"unreachable": true
}
jmp4 | UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).", 
"unreachable": true
}

下面执行免密操作,写好yaml剧本

[root@ansible ~]# cd ansible/
[root@ansible ansible]# pwd
/root/ansible
[root@ansible ansible]# vim auth_key.yml

[root@ansible ansible]# cat auth_key.yml 
---
- name: configure authorized key
hosts: all
tasks:
- name: root key
authorized_key:
user: root
state: present
key: "{{ lookup('file', '/root/.ssh/id_rsa.pub')}}"

检查语法

[root@ansible ansible]# ansible-playbook --syntax-check auth_key.yml

playbook: auth_key.yml

执行剧本

 

[root@ansible ansible]# ansible-playbook auth_key.yml -k
SSH password:

PLAY [configure authorized key] ***********************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [jmp2]
ok: [jmp1]
ok: [jmp3]
ok: [jmp4]

TASK [root key] ***************************************************************************************************************************************************************************************************
changed: [jmp4]
changed: [jmp1]
changed: [jmp2]
changed: [jmp3]

PLAY RECAP ********************************************************************************************************************************************************************************************************
jmp1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 
jmp2 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 
jmp3 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 
jmp4 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

 

验证免密,可以看到成功了
[root@ansible ansible]# 
[root@ansible ansible]# ansible all -m ping
jmp4 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
}, 
"changed": false, 
"ping": "pong"
}
jmp3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
}, 
"changed": false, 
"ping": "pong"
}
jmp2 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
}, 
"changed": false, 
"ping": "pong"
}
jmp1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
}, 
"changed": false, 
"ping": "pong"
}
[root@ansible ansible]# 
发表在 ansible | 标签为 | 留下评论

kubernets通过给node设置标签实现pod指定node部署

1、添加标签ssd,模拟Node2节点是ssd硬盘

[fencatn@k8s-master ~]$ kubectl get node --show-labels 
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready master 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
k8s-node1 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node1,kubernetes.io/os=linux
k8s-node2 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node2,kubernetes.io/os=linux
k8s-node3 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node3,kubernetes.io/os=linux
[fencatn@k8s-master ~]$ kubectl label node k8s-node2 disktype=ssd
node/k8s-node2 labeled
[fencatn@k8s-master ~]$ kubectl get node --show-labels 
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready master 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
k8s-node1 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node1,kubernetes.io/os=linux
k8s-node2 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node2,kubernetes.io/os=linux
k8s-node3 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node3,kubernetes.io/os=linux

制定nginx调度到ssd标签的node

[fencatn@k8s-master ~]$ cp nginx.yml nginx_ssd.yml
[fencatn@k8s-master ~]$ vim nginx_ssd.yml 
[fencatn@k8s-master ~]$ diff nginx.yml nginx_ssd.yml 
15a16,17
> nodeSelector:
> disktype: ssd
[fencatn@k8s-master ~]$ cat nginx_ssd.yml 
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 5
template:
metadata:
labels:
app: web_server
spec:
containers:
- name: nginx
image: nginx:1.7.9
nodeSelector:
disktype: ssd
[fencatn@k8s-master ~]$

重新部署配置文件

[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 137m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 137m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-76cbf 1/1 Running 0 13s 10.244.3.19 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-ch24p 1/1 Running 0 13s 10.244.3.20 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-pgg86 1/1 Running 0 13s 10.244.1.26 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-r2kpf 1/1 Running 0 13s 10.244.2.18 k8s-node2 <none> <none>
nginx-deployment-656d6ccbd5-swmrs 1/1 Running 0 13s 10.244.2.17 k8s-node2 <none> <none>
[fencatn@k8s-master ~]$ kubectl apply -f nginx_ssd.yml 
deployment.extensions/nginx-deployment configured

可以看到k8s正在自动调整中

[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 138m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 138m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-76cbf 0/1 Terminating 0 28s <none> k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-pgg86 0/1 Terminating 0 28s 10.244.1.26 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-r2kpf 1/1 Terminating 0 28s 10.244.2.18 k8s-node2 <none> <none>
nginx-deployment-656d6ccbd5-swmrs 1/1 Running 0 28s 10.244.2.17 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-6scnc 1/1 Running 0 4s 10.244.2.20 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-f25ds 0/1 ContainerCreating 0 2s <none> k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-f4gjf 1/1 Running 0 2s 10.244.2.21 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-g9zq2 1/1 Running 0 4s 10.244.2.19 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-scpsv 0/1 ContainerCreating 0 1s <none> k8s-node2 <none> <none>

[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 138m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 138m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-pgg86 0/1 Terminating 0 34s 10.244.1.26 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-swmrs 0/1 Terminating 0 34s 10.244.2.17 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-6scnc 1/1 Running 0 10s 10.244.2.20 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-f25ds 1/1 Running 0 8s 10.244.2.22 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-f4gjf 1/1 Running 0 8s 10.244.2.21 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-g9zq2 1/1 Running 0 10s 10.244.2.19 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-scpsv 1/1 Running 0 7s 10.244.2.23 k8s-node2 <none> <none>
[fencatn@k8s-master ~]$

调整完毕,全部到了node2节点

[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 139m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 139m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-6bb686dbcf-6scnc 1/1 Running 0 55s 10.244.2.20 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-f25ds 1/1 Running 0 53s 10.244.2.22 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-f4gjf 1/1 Running 0 53s 10.244.2.21 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-g9zq2 1/1 Running 0 55s 10.244.2.19 k8s-node2 <none> <none>
nginx-deployment-6bb686dbcf-scpsv 1/1 Running 0 52s 10.244.2.23 k8s-node2 <none> <none>

删除标签

[fencatn@k8s-master ~]$ kubectl label node k8s-node2 disktype-
node/k8s-node2 labeled
[fencatn@k8s-master ~]$ kubectl get node --show-labels 
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready master 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
k8s-node1 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node1,kubernetes.io/os=linux
k8s-node2 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node2,kubernetes.io/os=linux
k8s-node3 Ready <none> 52d v1.14.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node3,kubernetes.io/os=linux

但是Pod不会自动调整

[fencatn@k8s-master ~]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
http-app-5b7568bf86-bnszg 1/1 Running 0 143m
http-app-5b7568bf86-vwtl6 1/1 Running 0 143m
myjob-4gbwc 0/1 Completed 0 52d
myjob-bpw87 0/1 Completed 0 52d
myjob-lmbbv 0/1 Completed 0 52d
myjob-zz9fx 0/1 Completed 0 52d
nginx-deployment-6bb686dbcf-6scnc 1/1 Running 0 5m14s
nginx-deployment-6bb686dbcf-f25ds 1/1 Running 0 5m12s
nginx-deployment-6bb686dbcf-f4gjf 1/1 Running 0 5m12s
nginx-deployment-6bb686dbcf-g9zq2 1/1 Running 0 5m14s
nginx-deployment-6bb686dbcf-scpsv 1/1 Running 0 5m11s
[fencatn@k8s-master ~]$

手动调整pod,选择之前的配置文件

[fencatn@k8s-master ~]$ kubectl apply -f nginx.yml 
deployment.extensions/nginx-deployment configured

pod开始自动调整

[fencatn@k8s-master ~]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
http-app-5b7568bf86-bnszg 1/1 Running 0 143m
http-app-5b7568bf86-vwtl6 1/1 Running 0 143m
myjob-4gbwc 0/1 Completed 0 52d
myjob-bpw87 0/1 Completed 0 52d
myjob-lmbbv 0/1 Completed 0 52d
myjob-zz9fx 0/1 Completed 0 52d
nginx-deployment-656d6ccbd5-g9htz 1/1 Running 0 3s
nginx-deployment-656d6ccbd5-njfvh 1/1 Running 0 2s
nginx-deployment-656d6ccbd5-p2ckr 1/1 Running 0 3s
nginx-deployment-656d6ccbd5-rv9nd 0/1 ContainerCreating 0 1s
nginx-deployment-656d6ccbd5-sxlg6 1/1 Running 0 1s
nginx-deployment-6bb686dbcf-6scnc 1/1 Terminating 0 5m28s
nginx-deployment-6bb686dbcf-f25ds 0/1 Terminating 0 5m26s
nginx-deployment-6bb686dbcf-f4gjf 1/1 Terminating 0 5m26s
nginx-deployment-6bb686dbcf-g9zq2 1/1 Terminating 0 5m28s

稍等片刻,pod调整完毕

[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 145m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 145m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-g9htz 1/1 Running 0 109s 10.244.3.21 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-njfvh 1/1 Running 0 108s 10.244.2.24 k8s-node2 <none> <none>
nginx-deployment-656d6ccbd5-p2ckr 1/1 Running 0 109s 10.244.1.27 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-rv9nd 1/1 Running 0 107s 10.244.1.28 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-sxlg6 1/1 Running 0 107s 10.244.3.22 k8s-node3 <none> <none>
发表在 kubernetes | 标签为 | 留下评论

kubernetes中的deployment模拟failover

先写了个简单的应用部署,副本设置为5
[fencatn@k8s-master ~]$ cat nginx.yml 
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 5
template:
metadata:
labels:
app: web_server
spec:
containers:
- name: nginx
image: nginx:1.7.9
[fencatn@k8s-master ~]$
然后开始部署应用
[fencatn@k8s-master ~]$ kubectl apply -f nginx.yml 
deployment.extensions/nginx-deployment configured
[fencatn@k8s-master ~]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
http-app-5b7568bf86-bnszg 1/1 Running 0 106m
http-app-5b7568bf86-vwtl6 1/1 Running 0 106m
myjob-2q7tk 0/1 Completed 0 52d
myjob-4gbwc 0/1 Completed 0 52d
myjob-bpw87 0/1 Completed 0 52d
myjob-lmbbv 0/1 Completed 0 52d
myjob-s6s7j 0/1 Completed 0 52d
myjob-zz9fx 0/1 Completed 0 52d
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 3s
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 98s
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 98s
nginx-deployment-656d6ccbd5-rmkz6 1/1 Running 0 3s
nginx-deployment-656d6ccbd5-sd4ss 1/1 Running 0 98s
查看详细属性
[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 111m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 111m 10.244.3.14 k8s-node3 <none> <none>
myjob-2q7tk 0/1 Completed 0 52d 10.244.2.11 k8s-node2 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-s6s7j 0/1 Completed 0 52d 10.244.2.12 k8s-node2 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 5m43s 10.244.1.24 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 7m18s 10.244.1.23 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 7m18s 10.244.3.17 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-rmkz6 1/1 Running 0 5m43s 10.244.2.16 k8s-node2 <none> <none>
nginx-deployment-656d6ccbd5-sd4ss 1/1 Running 0 7m18s 10.244.2.15 k8s-node2 <none> <none>
过了一会
[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 113m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 113m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 7m11s 10.244.1.24 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-8ckzb 1/1 Running 0 18s 10.244.3.18 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 8m46s 10.244.1.23 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-j88pc 1/1 Running 0 18s 10.244.1.25 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 8m46s 10.244.3.17 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-rmkz6 1/1 Terminating 0 7m11s 10.244.2.16 k8s-node2 <none> <none>
nginx-deployment-656d6ccbd5-sd4ss 1/1 Terminating 0 8m46s 10.244.2.15 k8s-node2 <none> <none>
同时确认node2下线
[fencatn@k8s-master ~]$ kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 52d v1.14.2
k8s-node1 Ready <none> 52d v1.14.2
k8s-node2 NotReady <none> 52d v1.14.2
k8s-node3 Ready <none> 52d v1.14.2
Node2重新开机
[fencatn@k8s-master ~]$ kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 52d v1.14.2
k8s-node1 Ready <none> 52d v1.14.2
k8s-node2 Ready <none> 52d v1.14.2
k8s-node3 Ready <none> 52d v1.14.2
再次查看pod,可以发现原来状态为terminating的pod已经删除,但是已有的pod不会重新调度回去
[fencatn@k8s-master ~]$ kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-app-5b7568bf86-bnszg 1/1 Running 0 115m 10.244.1.20 k8s-node1 <none> <none>
http-app-5b7568bf86-vwtl6 1/1 Running 0 115m 10.244.3.14 k8s-node3 <none> <none>
myjob-4gbwc 0/1 Completed 0 52d 10.244.3.12 k8s-node3 <none> <none>
myjob-bpw87 0/1 Completed 0 52d 10.244.3.13 k8s-node3 <none> <none>
myjob-lmbbv 0/1 Completed 0 52d 10.244.1.19 k8s-node1 <none> <none>
myjob-zz9fx 0/1 Completed 0 52d 10.244.1.18 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-2nc6m 1/1 Running 0 9m47s 10.244.1.24 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-8ckzb 1/1 Running 0 2m54s 10.244.3.18 k8s-node3 <none> <none>
nginx-deployment-656d6ccbd5-hr5ff 1/1 Running 0 11m 10.244.1.23 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-j88pc 1/1 Running 0 2m54s 10.244.1.25 k8s-node1 <none> <none>
nginx-deployment-656d6ccbd5-k8lbj 1/1 Running 0 11m 10.244.3.17 k8s-node3 <none> <none>
发表在 kubernetes | 标签为 | 留下评论