vi /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server controller iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 # Serve time even if not synchronized to a timesource. #local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory forlog files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking allow 192.168.157.0/24 local stratum 10 ###使配置生效 systemctl restart chronyd systemctl enable chronyd chronyc sources
vi /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server controller iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 # Serve time even if not synchronized to a timesource. #local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory forlog files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking ###使配置生效 systemctl restart chronyd systemctl enable chronyd chronyc sources
##查看空白分区 [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 44G 0 lvm / └─centos-swap 253:1 0 5G 0 lvm [SWAP] sdb 8:16 0 40G 0 disk sr0 11:0 1 1024M 0 rom
[root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x4cacbd86.
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-83886079, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): +20G Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (41945088-83886079, default 41945088): Using default value 41945088 Last sector, +sectors or +size{K,M,G} (41945088-83886079, default 83886079): +20G Using default value 83886079 Partition 2 of type Linux and of size 20 GiB is set
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
[root@controller ~]# mysql -uroot -p MariaDB [(none)]> create user examuser@'localhost' identified by '000000'; Query OK, 0 rows affected (0.005 sec) MariaDB [(none)]> use mysql Database changed MariaDB [mysql]> select user,host,password from user; +-----------+------------+-------------------------------------------+ | user | host | password | +-----------+------------+-------------------------------------------+ | root | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | root | controller | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | root | 127.0.0.1 | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | root | ::1 | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | keystone | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | keystone | % | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | glance | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | glance | % | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | nova | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | nova | % | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | placement | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | placement | % | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | neutron | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | neutron | % | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | cinder | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | cinder | % | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | | examuser | localhost | *032197AE5731D4664921A6CCAC7CFCE6A0698693 | +-----------+------------+-------------------------------------------+ 17 rows in set (0.000 sec) MariaDB [mysql]> grant select,delete,update,create on *.* to examuser@'localhost'; Query OK, 0 rows affected (0.000 sec) MariaDB [mysql]> select User, Select_priv,Update_priv,Delete_priv,Create_priv from user; +-----------+-------------+-------------+-------------+-------------+ | User | Select_priv | Update_priv | Delete_priv | Create_priv | +-----------+-------------+-------------+-------------+-------------+ | root | Y | Y | Y | Y | | root | Y | Y | Y | Y | | root | Y | Y | Y | Y | | root | Y | Y | Y | Y | | keystone | N | N | N | N | | keystone | N | N | N | N | | glance | N | N | N | N | | glance | N | N | N | N | | nova | N | N | N | N | | nova | N | N | N | N | | placement | N | N | N | N | | placement | N | N | N | N | | neutron | N | N | N | N | | neutron | N | N | N | N | | examuser | Y | Y | Y | Y | +-----------+-------------+-------------+-------------+-------------+ 15 rows in set (0.000 sec)
⑧请使用 openstack 命令创建一个名为 test 的 cinder 卷,卷大小为 5G。完成后使用 cinder命令列出卷列表并查看 test 卷的详细信息。
[root@controller python-depend]# yum install python3 –y [root@controller python-depend]# pip3 install certifi-2019.11.28-py2.py3-none-any.whl [root@controller python-depend]# pip3 install urllib3-1.25.11-py3-none-any.whl [root@controller python-depend]# pip3 install idna-2.8-py2.py3-none-any.whl [root@controller python-depend]# pip3 install chardet-3.0.4-py2.py3-none-any.whl [root@controller python-depend]# pip3 install requests-2.24.0-py2.py3-none-any.whl [root@controller ~]# python3 --version Python 3.6.8 [root@controller ~]# pip3 list DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning. certifi (2019.11.28) chardet (3.0.4) idna (2.8) pip (9.0.3) requests (2.24.0) setuptools (39.2.0) urllib3 (1.25.11)
class openstack_user_api: def __init__(self, handers: dict, resUrl: str): self.headers = handers self.resUrl = resUrl def create_users(self, user_name): body = { "user": { "description": "API create user!", "domain_id": "default", "name": user_name } } status_code = requests.post(self.resUrl, data=json.dumps(body), headers=self.headers).text result = json.loads(requests.get(self.resUrl, headers=self.headers).text) user_name = user_name for i in result['users']: if i['name'] == user_name: return f"用户 {user_name} 创建成功,ID为{i['id']}" def list_users(self): result = json.loads(requests.get(self.resUrl, headers=self.headers).text) roles = [] for i in result['users']: if i['name'] not in roles: roles.append(i['name']) return "该平台的用户为:\n"+'\n'.join(roles)
def get_user_id(self, user_name): result = json.loads(requests.get(self.resUrl, headers=self.headers).text) user_name = user_name for i in result['users']: if i['name'] == user_name: return (f"用户 {user_name} 的ID为{i['id']}")
def delete_user(self, user_name): result = json.loads(requests.get(self.resUrl, headers=self.headers).text) for i in result['users']: if i['name'] == user_name: i = i['id'] status_code = requests.delete(f'http://{controller_ip}:5000/v3/users/{i}', headers=self.headers) return f"用户 {user_name} 已删除!"
[root@master ~]# vi /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server master iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 allow 192.168.157.0/24 # Serve time even if not synchronized to a timesource. #local stratum 10 local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory forlog files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking ##重启服务 [root@localhost ~]# systemctl restart chronyd [root@localhost ~]# systemctl enable chronyd [root@localhost ~]# chronyc sources
[root@localhost ~]# cat /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server master iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 # Serve time even if not synchronized to a timesource. #local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory forlog files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking ##重启服务 [root@localhost ~]# systemctl restart chronyd [root@localhost ~]# systemctl enable chronyd [root@localhost ~]# chronyc sources
[root@localhost ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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:qveHAExYRiPQVv5rlsI3owC/pO72K9ZK+pOJFPnPfFQ root@node1 The key's randomart image is: +---[RSA 2048]----+ |.o.=* | | ++.. | | ..o. | | o o. E | |. o .. S | | + o .= | |.o=o* @. . | |+*++ @.+. . | |B=*++..... | +----[SHA256]-----+
[root@master ~]# ssh-copy-id root@node1 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.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 root@node1's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@node1'" and check to make sure that only the key(s) you wanted were added.
[root@master ~]# ssh-copy-id root@node2 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.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 root@node2's password: Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@node2'" and check to make sure that only the key(s) you wanted were added.
[root@master ~]# ssh-copy-id root@harbor /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.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 root@harbor's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@harbor'" and check to make sure that only the key(s) you wanted were added.
[root@localhost opt]# tar -zxvf harbor-offline-installer-v2.1.0.tgz harbor/harbor.v2.1.0.tar.gz harbor/prepare harbor/LICENSE harbor/install.sh harbor/common.sh harbor/harbor.yml.tmpl [root@localhost opt]# cd harbor [root@localhost harbor]# ls common.sh harbor.v2.1.0.tar.gz harbor.yml.tmpl install.sh LICENSE prepare [root@localhost harbor]# mv harbor.yml.tmpl harbor.yml [root@localhost harbor]# vi harbor.yml [root@harbor harbor]# cat harbor.yml # Configuration file of Harbor # The IP address or hostname to access admin UI and registry service. # DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients. hostname: 192.168.157.50 ##修改IP地址 # http related config http: # port for http, default is 80. If https enabled, this port will redirect to https port port: 80 ###在此处注释掉https # https related config #https: # https port for harbor, default is 443 # port: 443 # The path of cert and key files for nginx #certificate: /your/certificate/path #private_key: /your/private/key/path ........ [root@localhost harbor]# ./prepare [root@harbor harbor]# ./install.sh
[root@master paas]# ./k8s_image_push.sh 输入镜像仓库地址(不加http/https): 192.168.157.53 输入镜像仓库用户名: admin 输入镜像仓库用户密码: Harbor12345 您设置的仓库地址为: 192.168.157.53,用户名: admin,密码: xxx 是否确认(Y/N): y WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
# eval sed -i 's@docker.io/flannel@192.168.157.50/library@g' /opt/paas/yaml/flannel/kube-flannel.yaml [root@master ~]# kubectl apply -f /opt/paas/yaml/flannel/kube-flannel.yaml [root@master ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready control-plane 9m42s v1.18.1
[root@localhost ~]# 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:r7ZDne6h3xaK6zVevWSj77paApHMV6RAXHzH2s78cMc root@zabbix-agent The key's randomart image is: +---[RSA 2048]----+ | ooo..o. | | o.o.o. o | | = o. + | | o . . | | S. . + . | | .oo ..= E| | . o*.o.=+.| | +=oB.+ o.| | o**=o==+ | +----[SHA256]-----+ [root@localhost ~]# ssh-copy-id root@zabbix-agent /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host '192.168.157.40 (192.168.157.40)' can't be established. ECDSA key fingerprint is SHA256:EWGohbn7cIhP7AAYHbnuMx/IoLAEybzPJENWQazAFG4. ECDSA key fingerprint is MD5:81:d6:a5:02:87:4b:13:1b:eb:69:76:1c:5c:aa:80:bf. Are you sure you want to continue connecting (yes/no)? yes /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 root@192.168.157.40's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.157.40'" and check to make sure that only the key(s) you wanted were added.
# yum -y install zabbix-server zabbix-web-mysql zabbix-agent # systemctl start zabbix-server&& systemctl start zabbix-agent # systemctl status zabbix-server&& systemctl status zabbix-agent ● zabbix-server-mysql.service - Zabbix Server with MySQL DB Loaded: loaded (/usr/lib/systemd/system/zabbix-server-mysql.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2023-03-18 04:36:50 UTC; 4min 5s ago Main PID: 20737 (zabbix_server) CGroup: /system.slice/zabbix-server-mysql.service └─20737 /usr/sbin/zabbix_server -f
Mar 18 04:36:50 zabbix_server systemd[1]: Started Zabbix Serve... Hint: Some lines were ellipsized, use -l to show in full. ● zabbix-agent.service - Zabbix Agent Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2023-03-18 04:37:47 UTC; 3min 8s ago Process: 20752 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS) Main PID: 20754 (zabbix_agentd) CGroup: /system.slice/zabbix-agent.service ├─20754 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabb... ├─20755 /usr/sbin/zabbix_agentd: collector [idle 1 ... ├─20756 /usr/sbin/zabbix_agentd: listener #1 [waiti... ├─20757 /usr/sbin/zabbix_agentd: listener #2 [waiti... ├─20758 /usr/sbin/zabbix_agentd: listener #3 [waiti... └─20759 /usr/sbin/zabbix_agentd: active checks #1 [...
Mar 18 04:37:47 zabbix_server systemd[1]: Starting Zabbix Agen... Mar 18 04:37:47 zabbix_server systemd[1]: Started Zabbix Agent. Hint: Some lines were ellipsized, use -l to show in full.
# yum -y install mariadb-server # systemctl enable --now mariadb # systemctl status mariadb ● mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2023-03-18 04:52:20 UTC; 1min 2s ago Process: 20907 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS) Process: 20822 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS) Main PID: 20905 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─20905 /bin/sh /usr/bin/mysqld_safe --basedir=/usr... └─21071 /usr/libexec/mysqld --basedir=/usr --datadi...
Mar 18 04:52:18 zabbix_server mariadb-prepare-db-dir[20822]: M... Mar 18 04:52:18 zabbix_server mariadb-prepare-db-dir[20822]: P... Mar 18 04:52:18 zabbix_server mariadb-prepare-db-dir[20822]: T... Mar 18 04:52:18 zabbix_server mariadb-prepare-db-dir[20822]: Y... Mar 18 04:52:18 zabbix_server mariadb-prepare-db-dir[20822]: h... Mar 18 04:52:18 zabbix_server mariadb-prepare-db-dir[20822]: C... Mar 18 04:52:18 zabbix_server mariadb-prepare-db-dir[20822]: h... Mar 18 04:52:18 zabbix_server mysqld_safe[20905]: 230318 04:52... Mar 18 04:52:18 zabbix_server mysqld_safe[20905]: 230318 04:52... Mar 18 04:52:20 zabbix_server systemd[1]: Started MariaDB data... Hint: Some lines were ellipsized, use -l to show in full.
# mysql -uroot -p MariaDB [(none)]> create database zabbix charset utf8 collate utf8_bin;; MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'password'; MariaDB [zabbix]> show grants for 'zabbix'@'localhost'; +---------------------------------------------------------------------------------------------------------------+ | Grants for zabbix@localhost | +---------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'zabbix'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' | | GRANT ALL PRIVILEGES ON `zabbix`.* TO 'zabbix'@'localhost'