首页 > 其他分享 >复制老师的博客

复制老师的博客

时间:2022-09-23 16:57:02浏览次数:46  
标签:老师 博客 etc controller 复制 yum etcd openstack root

脸都不要了.

# 切换到yum目录
[root@controller ~]# cd /etc/yum.repos.d/
# 创建备份目录
[root@controller yum.repos.d]# mkdir repo.bak
[root@controller yum.repos.d]# ls
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo
CentOS-CR.repo         CentOS-Media.repo  ....
# 把原来的yum文件移到到备份目录
[root@controller yum.repos.d]# mv *.repo repo.bak/
# 下载阿里的yum源
[root@controller yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo  http://mirrors.aliyun.com/repo/Centos-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2523  100  2523    0     0  20847      0 --:--:-- --:--:-- --:--:-- 21025
# 清理yum
[root@controller yum.repos.d]# yum clean all && yum makecache

2、主机名修改

# 修改主机名
[root@asdad yum.repos.d]# hostnamectl set-hostname controller
# 让修改生效显示
[root@asdad yum.repos.d]# bash
[root@controller yum.repos.d]# 
# 修改后hostname文件内容对应修改
[root@controller yum.repos.d]# cat /etc/hostname
controller

3、本地域名的解析

直接通过主机名访问主机,需要将主机名和IP地址进行绑定,绑定工作可以通过本地域名解析来实现。
Linux中的 /etc/hosts 文件可以将一些常用的域名和对应的IP建立对应关系。

默认hosts文件内容和意义:

[root@controller ~]# cat /etc/hosts
# 每一行都表示一个域名到Ip地址的映射关系
# 127.0.0.1表示IPv4的本地IP地址
# ::1表示IPv6的本地IP地址
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4   # 第一个名称是主机名,后面的为主机的别名
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6   # 第一个名称是主机名,后面的为主机的别名

案例:将controller解析为内网IP——192.168.10.10

# 添加解析信息到文件最后一行
[root@controller ~]# echo '192.168.10.10   controller' >> /etc/hosts
[root@controller ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.10   controller

# ping通,解析正常
[root@controller ~]# ping controller
PING controller (192.168.10.10) 56(84) bytes of data.
64 bytes from controller (192.168.10.10): icmp_seq=1 ttl=64 time=0.036 ms
64 bytes from controller (192.168.10.10): icmp_seq=2 ttl=64 time=0.034 ms

4、防火墙管理

CentOS7系统默认使用firewall作为系统防火墙,管理功能集成在系统服务管理命令 systemctl中。

常用参数功能说明
status 查看服务运行状态
start 开启服务
stop 停止服务
enable 服务开机启动
disable 服务开机禁用
restart 重启服务
# 停止防火墙和禁止开机启动防火墙
[root@controller ~]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
# 查看防火墙是否关闭
[root@controller ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

二、Openstack基础支持服务

Openstack平台需要借助多种第三方提供的基础服务才能正常运行,数据库、消息队列、时间同步、缓存服务等。

1、Chrony时间同步服务

同一个系统内的计算机时间必须保持一致才能保证系统工作正常。

Chrony软件是一款开源的自由软件,包括两个核心组件:chronyd(后台守护程序)和chronyc(命令行用户管理工具)。

(1)时间同步服务配置

通过修改chrony配置可以将任意一台计算机配置成NTP服务器或NTP服务器连接的客户端。

# 安装chrony
[root@controller ~]# yum install -y  chrony

# 查看chrony配置文件
[root@controller ~]# cat /etc/chrony.conf 
# Use public servers from the pool.ntp.org project.
server 0.centos.pool.ntp.org iburst  
server 1.centos.pool.ntp.org iburst  # Centos官方提供了4个NTP服务器 
server 2.centos.pool.ntp.org iburst  # iburst作用:设置当NTP服务器一定时间没有应答时,客户端发送8倍数据包以提升同步成功率
server 3.centos.pool.ntp.org iburst
...略
# Allow NTP client access from local network.
allow 192.168.10.0/24   # 设置允许某个网段的chrony客户端使用本机NTP服务
...略

# 修改配置后,重启服务生效
[root@controller ~]# systemctl restart chronyd 
[root@controller ~]# systemctl enable chronyd

(2)时间同步服务管理

时间同步由chronyc命令进行监控和管理。

功能说明常用参数命令
查看 ntp_servers信息,加-v将显示对数据的说明 chronyc sources -v
查看 ntp_servers 状态 chronyc sourcestats -v
查看 ntp_servers 是否在线 chronyc activity -v
查看 ntp 详细信息 chronyc tracking -v
强制同步下系统时钟 chronyc -a makestep
显示访问本服务器的客户端 chronyc clients
添加新的ntp服务器 chronyc add server
删除已有的ntp服务器 chronyc delete
# 查看当前客户端与NTP服务器连接情况(不加-v)
[root@controller ~]# chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 119.28.183.184                2   6    17     4  +4589us[  +17ms] +/-   45ms
^- ntp1.ams1.nl.leaseweb.net     2   6   375     5    +20ms[  +32ms] +/-  235ms
^+ 85.199.214.102                1   6   377     4    -17ms[-4919us] +/-  134ms
^- pingless.com                  2   6   377     4    -15ms[  -15ms] +/-  132ms

# 查看当前客户端与NTP服务器连接情况(加-v)
[root@controller ~]# chronyc sources -v
210 Number of sources = 4

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 119.28.183.184                2   6    17     6  +4589us[  +17ms] +/-   45ms
^- ntp1.ams1.nl.leaseweb.net     2   6   375     7    +20ms[  +32ms] +/-  235ms
^+ 85.199.214.102                1   6   377     6    -17ms[-4919us] +/-  134ms
^- pingless.com                  2   6   377     6    -15ms[  -15ms] +/-  132ms

# 查看 ntp服务器 是否在线
[root@controller ~]# chronyc activity 
200 OK
4 sources online
0 sources offline
0 sources doing burst (return to online)
0 sources doing burst (return to offline)
0 sources with unknown address

# 添加腾讯NTP服务器
[root@controller ~]# chronyc add server time1.cloud.tencent.com
200 OK
# 删除腾讯的NTP服务器
[root@controller ~]# chronyc delete time1.cloud.tencent.com
200 OK

2、Openstack云计算平台框架

安装组件前,需要先将框架搭建起来。因此要安装由CentOS官方发布的Openstack云计算框架与客户端管理工具。

(1)安装Openstack框架和客户端

# 1.安装Openstack框架
# 模糊查询软件包名称
[root@controller ~]# yum list *-openstack-train
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
centos-release-openstack-train.noarch                   1-1.el7.centos                    extras
# 安装
[root@controller ~]# yum -y install centos-release-openstack-train

# 2.升级所有的软件包
# 自动检查所有可升级的软件包并升级
[root@controller ~]# yum upgrade -y

# 3.安装openstack客户端
[root@controller ~]# yum install -y python-openstackclient

# 4.查看openstack的版本号
[root@controller ~]# openstack --version
openstack 4.0.2

(2)禁用Centos的SElinux,安装openstack-selinux
selinux有三种工作模式:
强制模式(enforcing)————强制使用selinux的安全策略;
宽容模式(permissive)————不使用安全策略,只将相关信息写入日志;
禁用模式(disabled)————禁用selinux。

openstack-selinux:帮助openstack平台自动控制和管理selinux安全策略。

# 1.禁用Centos的SElinux
[root@controller ~]# vi /etc/selinux/config
...略
SELINUX=disabled     《————改为这样
...略
# 让修改配置生效
[root@controller ~]# setenforce  0

# 2.安装openstack-selinux
[root@controller ~]# yum install -y openstack-selinux

3、mariadb数据库

Mysql的创始人Michel Widenius主导开发完全兼容MYSQL、开源免费的MariaDB数据库。

MariaDB采用Maria存储引擎的MYSQL数据库的分支版本。

(1)安装mariadb

# mariadb-server:数据库后台服务
# python2-PyMySQL:python访问数据库的模块
[root@controller ~]# yum install -y mariadb-server python2-PyMySQL

(2)编辑数据库配置文件

配置文件是 /etc/my.cnf.d/ 目录下所有后缀为 cnf的文件。

配置文件中主要参数及功能:

参数功能说明
port 数据库对外服务的端口号,默认为3306
datadir 数据库文件存放目录
bind-address 绑定远程访问地址,只允许从该地址访问数据库
default-storage-engine 默认存储引擎,MariaDB支持几十种存储引擎,其中InnoDB是比较常用的支持事务的存储引擎
innodb_file_per_table InnoDB引擎的独立表空间,让每个表的数据都单独保存
max_connections 最大连接数
collation-server 字符的排序规则,也称为排列字符集,每个字符集都对应一个或多个排列字符集
character-set-server 字符集
[root@controller ~]# cd /etc/my.cnf.d/
[root@controller my.cnf.d]# ls
client.cnf                mariadb-server.cnf
enable_encryption.preset  mysql-clients.cnf

# 创建文件
[root@controller my.cnf.d]# touch openstack.cnf
# 写入信息
echo '[mysqld]
bind-address = 192.168.10.10
default-storage-engine = innodb
innodb_file_per_table = on
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8' > openstack.cnf

(3)启动mariadb

# 设置开机启动
[root@controller my.cnf.d]# systemctl enable mariadb
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# 立即启动数据库
[root@controller my.cnf.d]# systemctl start mariadb
# 检查数据库启动情况
[root@controller my.cnf.d]# systemctl status mariadb

(4)初始化mariadb数据库

[root@controller ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):     《输入当前密码,没有则直接按【Enter】键
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y          《是否设置新密码
New password:                       《输入新密码
Re-enter new password:              《确认新密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y       《是否去掉匿名用户   
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y   《是否禁止root用户远程登录
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y  《是否去掉测试数据库
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y       《是否重新加载权限表
 ... Success!

Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

(5)登录和使用数据库

# 登录数据库
[root@controller ~]# mysql -h localhost -uroot -p000000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
MariaDB [(none)]> use mysql;
MariaDB [mysql]> show tables;
MariaDB [mysql]> exit
Bye

4、RabbitMQ消息队列服务

消息队列(Message Queue,MQ)是一种应用间的通信方式,消息发送到消息队列后由消息队列来确保消息的可靠传递,即消息发布者和消息使用者之间并不产生直接关系。

OpenStack各个组件之间就是通过消息队列进行相互通信的。其中RabbitMQ是一个开源的、应用广泛的消息服务系统。

通常使用RabbitMQ为OpenStack提供消息队列服务。

(1)用户管理常用语法

RabbitMQ用户的用户名和密码由rabbitmqctl命令进行管理
新建RabbitMQ用户的命令如下:
rabbitmqctl add_user <用户名> <密码>
删除RabbitMQ用户的命令如下:
rabbitmqctl delete_user <用户名>
修改RabbitMQ用户密码的命令如下:
rabbitmqctl change_password <用户名> <新密码>

(2)案例

# 1.安装RabbitMQ消息队列
[root@controller ~]# yum install -y rabbitmq-server

# 2.启动RabbitMQ消息队列
# 开机启动
[root@controller ~]# systemctl enable rabbitmq-server
Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.
# 立即启动
[root@controller ~]# systemctl start rabbitmq-server

# 3.设置用户和密码
# 创建一个名为“rabbitmq”的用户,密码为“RABBIT_PASS”
[root@controller ~]# rabbitmqctl add_user openstack RABBIT_PASS
Creating user "openstack"

# 修改openstack用户密码为000000
[root@controller ~]# rabbitmqctl change_password openstack 000000
Changing password for user "openstack"

# 4.管理用户权限
# 3个“.*”分别对应配置、写入、读取权。给openstack用户赋予对RabbitMQ所有资源的配置、写入与读取权限
[root@controller ~]# rabbitmqctl set_permissions openstack ".*" ".*" ".*"
Setting permissions for user "openstack" in vhost "/"

# 查看用户的权限
[root@controller ~]# rabbitmqctl list_user_permissions openstack
Listing permissions for user "openstack"
/	.*	.*	.*

5、Memcached内存缓存服务

内存缓存(Memcached)是一个高性能的分布式内存对象缓存系统,能够存储各种格式的数据,包括图像、视频、文件,以及数据库检索的结果等

(1)安装memcached服务

# “memcached”是内存缓存服务软件,
# “python-memcached”是对该服务进行管理的接口程序软件
[root@controller ~]# yum install -y memcached python-memcached

# 安装完成后,系统将自动创建名为“memcached”的用户
[root@controller ~]# cat /etc/passwd | grep memcached
memcached:x:995:992:Memcached daemon:/run/memcached:/sbin/nologin

(2)配置内存缓存服务

Memcached的配置文件为/etc/sysconfig/memcached

[root@controller ~]# vi /etc/sysconfig/memcached 
PORT="11211"                     # 服务端口
USER="memcached"                 # 用户名
MAXCONN="1024"                   # 允许的最大连接数
CACHESIZE="64"                   # 最大的缓存大小
OPTIONS="-l 127.0.0.1,::1,192.168.10.10"         # 监听地址(默认监听本地)

(3)启动内存缓存服务

# 开机启动
[root@controller ~]# systemctl enable memcached
Created symlink from /etc/systemd/system/multi-user.target.wants/memcached.service to /usr/lib/systemd/system/memcached.service.
# 立即启动
[root@controller ~]# systemctl start memcached

# 检查服务是否启动
[root@controller ~]# netstat -tnlup | grep memcached
tcp        0      0 192.168.10.10:11211     0.0.0.0:*               LISTEN      3778/memcached      
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      3778/memcached      
tcp6       0      0 ::1:11211               :::*                    LISTEN      3778/memcached

6、etcd分布式键值对存储系统

etcd是一个开源项目,它的目标是构建一个高可用的分布式键-值(Key-Value)数据库用于配置共享和服务发现。

这个软件的作用类似于分布式系统中“/etc”目录的功能,即存储大规模分布式系统的配置信息。

(1)etcd配置参数

配置参数说明
ETCD_LISTEN_PEER_URLS 用于监听其他etcd成员的地址,只能是IP地址,不能写域名
ETCD_LISTEN_CLIENT_URLS 对外提供服务的地址,只能是IP地址,不能写域名
ETCD_NAME 当前etcd成员的名字,成员必须有唯一名字,建议采用主机名
ETCD_INITIAL_ADVERTISE_PEER_URLS 列出这个成员的伙伴地址,通告给集群中的其他成员
ETCD_ADVERTISE_CLIENT_URLS 列出这个成员的客户端地址,通告给集群中的其他成员
ETCD_INITIAL_CLUSTER 启动初始化集群配置,值为“成员名=该成员服务地址”
ETCD_INITIAL_CLUSTER_TOKEN 初始化etcd集群标识,用于多个etcd集群相互识别
ETCD_INITIAL_CLUSTER_STATE 初始化集群状态(新建值为“new”,已存在值为“existing”)。如果这个选项被设置为existing,etcd将试图加入已有的集群

(2)安装配置

# 1.安装
[root@controller ~]# yum install -y etcd

# 2.备份配置文件
[root@controller ~]# cp /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak
# 修改配置
echo 'ETCD_LISTEN_PEER_URLS="http://192.168.10.10:2380"
ETCD_LISTEN_CLIENT_URLS="http://192.168.10.10:2379,http://127.0.0.1:2379"
ETCD_NAME="controller"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.10.10:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.10.10:2379"
ETCD_INITIAL_CLUSTER="controller=http://192.168.10.10:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER_STATE="new"
' > /etc/etcd/etcd.conf

# 3.启动服务
[root@controller ~]# systemctl enable etcd
Created symlink from /etc/systemd/system/multi-user.target.wants/etcd.service to /usr/lib/systemd/system/etcd.service.
[root@controller ~]# systemctl start etcd

# 4.检查运行
[root@controller ~]# netstat -tnlup| grep etcd
tcp        0      0 192.168.10.10:2379      0.0.0.0:*               LISTEN      4319/etcd           
tcp        0      0 127.0.0.1:2379          0.0.0.0:*               LISTEN      4319/etcd           
tcp        0      0 192.168.10.10:2380      0.0.0.0:*               LISTEN      4319/etcd  

(3)etcd服务管理

etcdctl是管理etcd服务的工具,利用它可以实现数据的存取。

[root@controller ~]# etcdctl set testkey 001
001
[root@controller ~]# etcdctl get testkey
001
[root@controller ~]# etcdctl set name kobe
kobe
[root@controller ~]# etcdctl get name
kobe

标签:老师,博客,etc,controller,复制,yum,etcd,openstack,root
From: https://www.cnblogs.com/BCYDY/p/16723267.html

相关文章

  • 云主机搭建WordPress个人博客
    安装宝塔控制面板宝塔面板是一个简单、好用的面板,它的功能就是将LNMP和服务器的各种管理集成到一个可视化的WEB环境来管理,通过面板,我们普通人不需要掌握具体的技术,只需要......
  • 博客园MarkDown 代码块样式修改
    1.下载样式您可以选择你需要的语言,我直接默认下载了2.查看样式效果这是我使用的样式3.使用样式解压下载的文件,打开你要是使用的样式文件,复制里面的内容直接复制到此......
  • 验证码输入框粘贴复制
    <divclass="box"><divclass="field-list"><divclass="field-item"></div><divclass="field-item"></div><divclass="field-item"></div&g......
  • 关于本博客
    密码:1.\((01111111111111111111111111111111)_2\)2.\(0x7ffffffff\)题解文章区见文章区有密码:校内网址+作者id一般反思上密码,这个密码就是公告栏展的,其实公开的密码......
  • 初入博客,请多指教
    自我介绍:嗨,米娜桑,鄙人不才,初入博客园,小趴菜一枚,这是第一次使用博客园来写随笔。博主主混一次元和二次元,不难猜宅女一个,没事不出门。目前是一位预备码农,但是目前......
  • Python复制Excel表格图片
    importosimporttimeimportpyautoguiimportwin32com.clientaswin32#发送函数deffz(app,bk):x,y=pyautogui.size()time.sleep(1)app.Application.Run......
  • 咯咯的第一篇博客
    介绍自己我叫薛加乐,湖南怀化人,能从专升本进入林涉外非常高兴,爱好健身,羽毛球,有去校园健身房的可以一起组队撸铁啊。计划在大专的时候浪费了很多时间,计划就是在本科两年的......
  • javascript: 复制对象时的深拷贝及浅拷贝(chrome 105.0.5195.125)
    一,js代码<html><head><metacharset="utf-8"/><title>测试</title></head><body><buttononclick="assign()">无效:变量直接赋值</button><br/><br/><br......
  • 我的第一篇博客
    大家好,我叫张熠,我来自湖南邵阳隆回,是一名伟大的共青团员,我也是通过专升本来到了这个学校,我是个有一点社恐的宅男,平常就喜欢打打游戏看小说啥的,也没啥大梦想,只要自己和家人......
  • 我的第一篇博客
    一、自我介绍  我的名字叫汪华庆,2020级软件工程11班,是一名通过专升本考试来到中南林业科技大学涉外学院的学生,之前是长沙商贸旅游职业技术学院的。我是一个比较随性的......