五 云部署
cloud:(virsh+qemu-img+openstack+docker)
1 virsh基本管理操作
list/dominfo/start/shutdown/reboot/destroy/define/undefine/console/edit/autostart/domifist查看虚拟机网卡信息/domblklist查看虚拟机硬盘信息/blockresize --path [绝对路径] --size 50G 主机名/
2 qemu-img基本操作:
创建一个新的镜像盘文件: qemu-img create -f disk.img 50G qcow2
使用后端模板文件创建一个16G的镜像盘文件: qemu-img create -b disk.img -f disk2.img 16G qcow2
查看镜像盘文件的信息: qemu-img info disk1.img
3 创建虚拟机及部署环境(并配置主机名,IP,yum源,hosts,resolve.conf)
qemu-img create -f qcow2 -b /var/lib/libvirt/images/.node_base.qcow2 /var/lib/libvirt/images/"$1".img 20G
cp /var/lib/libvirt/images/.node_base.xml /etc/libvirt/qemu/$1.xml
sed -i "s,node_base,"$1"," /etc/libvirt/qemu/$1.xml
virsh define /etc/libvirt/qemu/$1.xml
virsh start $1
virsh console $1
sleep 60
expect<<EOF
spawn virsh console $1
expect " " {
send "\r"}
expect "login:" {
send "root\r"}
expect "ssword: " {
send "a\r"}
expect "#" {
send "sed -i '9c GATEWAY="$2"' /etc/sysconfig/network-scripts/ifcfg-eth0\r"}
sed -i "7c IPADDR="$2"" /etc/sysconfig/network-scripts/ifcfg-eth0
EOF
hostnamectl set-hostname host1 //配置主机名
vim /etc/sysconfig/network-scripts/ifcfg-eth0 //配置ip
DEVICE="eth0"
ONBOOT="yes"
IPV6INIT="no"
IPV4_FAILURE_FATAL="no"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="static"
PERSISTENT_DHCLIENT="yes"
IPADDR="192.168.1.31"
PREFIX=24
GATEWAY=192.168.1.254
NETMASK=255.255.255.0
mkdir /var/ftp/Tom //配置yum
mount /linux-soft/04/openstack/RHEL7-extras.iso /var/ftp/Tom
vim /etc/yum.repos.d/dvd.repo
[dvd]
name=dvd
baseurl="ftp://192.168.1.254/Tom"
enabled=1
gpgcheck=0
备注:RPM-GPG-KEY-centos-7
createrepo k8s
4 openstack部署
yum -y install qemu-kvm libvirt-client libvirt-daemon libvirt-daemon-driver-qemu python-setuptools
yum -y install openstack-packstack
packstack --gen-answer-file answer.ini //用vim打开answer.ini文件有颜色,其他一样
vim answer.ini
42 CONFIG_SWIFT_INSTALL=n
45 CONFIG_CEILOMETER_INSTALL=n //计费相关模块
49 CONFIG_AODH_INSTALL=n //计费相关模块
53 CONFIG_GNOCCHI_INSTALL=n //计费相关模块
75 CONFIG_NTP_SERVERS=192.168.1.254 //时间服务器的地址
98 CONFIG_COMPUTE_HOSTS=192.168.1.11
102 CONFIG_NETWORK_HOSTS=192.168.1.10,192.168.1.11
333 CONFIG_KEYSTONE_ADMIN_PW=a //修改管理员的密码
840 CONFIG_NEUTRON_ML2_TYPE_DRIVERS=flat,vxlan //驱动类型
876 CONFIG_NEUTRON_ML2_VXLAN_GROUP=239.1.1.5 //设置组播地址,最后一个随意不能为0和255,其他固定
910 CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS=physnet1:br-ex //物理网桥的名称
921 CONFIG_NEUTRON_OVS_BRIDGE_IFACES=br-ex:eth0 //br-ex桥的名称与eth0连接,管理eth0
1179 CONFIG_PROVISION_DEMO=n //DEMO是否测试
packstack --answer-file=answer.ini
登录openstack(补充:ovs是交换机)
1)需要改配置文件并重新加载
sed -i '35a WSGIApplicationGroup %{GLOBAL}' /etc/httpd/conf.d/15-horizon_vhost.conf
systemctl reload httpd
systemctl restart openstack-nova-compute.service
2)查看用户名和密码: cat keystonerc_admin
5 Docker部署
1)yum -y install docker
systemctl restart docker
2)容器基本操作
docker ps //查看后台运行的容器
docker ps -qa //显示后台运行所有的容器ID
docker stop 0f //关闭容器(0f为容器ID)
docker start 0f //启动容器
docker restart 0f //重启容器
docker rm 0f //删除容器(先关闭容器才能删除)
docker rm $(docker ps -aq) //删除所有容器
docker attach 0f //进入容器attach(容器关闭) 一般不用
docker exec -it 0f /bin/bash //进入容器exec(容器不关闭) 公司经常用
docker top f7 //在容器外查看容器内进程列表
docker inspect -f '{
{.NetworkSettings.MacAddress}}' 76 //查看mac
docker inspect -f '{
{.NetworkSettings.IPAddress}}' 76 //查看ip地址
root@56ec8154f8e0:/
3)镜像基本操作
容器六大命令空间:uts net pid user mount ipc
man docker-serch //man的docker特殊用法
docker help serch //help的docker特殊用法
docker run -it docker.io/centos /bin/bash //启动镜像(it代表交互式终端)
docker run -itd docker.io/nginx //启动nginx的镜像(d代表放到后台)
docker search docker.io/busybox //搜索busybox镜像
docker pull docker.io/busybox //下载镜像
docker push docker.io/busybox //上传镜像
docker save docker.io/busybox:latest -o busybox.tar //导出busybox镜像为busybox.tar
docker load -i nginx.tar //导入镜像
docker rmi docker.io/nginx //删除镜像
scp -r /linux-soft/04/docker/ root@192.168.1.31:/
for i in * ; do docker load -i $i; done //一次性导入多个镜像
docker images //查看镜像列表
docker history docker.io/centos //查看centos镜像历史(有几层)
docker tag docker.io/centos:latest docker.io/cen:v1 //修改镜像的名称和标签
docker inspect docker.io/centos //查看镜像的底层信息
4)制作自定义镜像
步骤一:使用镜像启动容器
docker run -it docker.io/centos
rm -rf /etc/yum.repos.d/*
vim /etc/yum.repos.d/dvd.repo
yum -y install net-tools iproute psmisc vim-enhanced
步骤二:另存为另外一个镜像
docker start 8d07ecd7e345
docker images
docker run -it docker.io/myos:latest //验证新建镜像
步骤三:使用Dockerfile文件创建一个Apache镜像文件
mkdir bulid
cd bulid
touch Dockerfile //Dockerfile文件第一个字母要大写
cp /etc/yum.repos.d/local.repo ./
vim Dockerfile
FROM docker.io/myos:latest
RUN yum -y install httpd
ENV EnvironmentFile=/etc/sysconfig/httpd
WORKDIR /var/www/html/ //定义容器默认工作目录
ADD index.html index.html
EXPOSE 80 //设置开放端口号
EXPOSE 443
CMD ["/usr/sbin/httpd", "-D"]
docker build -t docker.io/myos:http .
docker run -d docker.io/myos:http
docker inspect d9
curl 172.17.0.7
5)创建私有镜像仓库
步骤一:自定义私有仓库(1.30)
yum -y install docker-distribution
systemctl start docker-distribution
步骤二 : 给仓库上传镜像(1.31)
docker load -i nginx.tar
docker tag docker.io/busybox:latest 192.168.1.30:5000/docker.io/busybox:latest //打标签
docker push 192.168.1.30:5000/docker.io/busybox:latest //上传
sed -i '24c INSECURE_REGISTRY=--insecure-registry 仓库IP:5000' /etc/sysconfig/docker
sed -i '13c ADD_REGISTRY=--add-registry 仓库IP:5000' /etc/sysconfig/docker
systemctl restart docker
docker run -it myos:latest /bin/bash //直接启动
6)NFS共享存储(持久化)
步骤一:配置NFS服务器(1.30)
yum -y install nfs-utils
mkdir /content
vim /etc/exports
/content *(rw)
systemctl restart nfs
exportfs -rv
chmod 777 /content
步骤二:配置客户端
yum -y install nfs-utils
systemctl restart nfs
mount -t nfs 192.168.1.30:/content /mnt/
docker run -itd -v /mnt:/usr/share/nginx/html docker.io/nginx:latest //-v 映射
7)创建自定义网桥
步骤一:新建Docker网络模型
1)新建docker1网络模型
docker network create --subnet=10.10.10.0/24 docker1
docker network inspect docker1
2)使用自定义网桥(docker1)启动容器
docker run --network=docker1 -itd docker.io/myos
docker run --network=docker1 -itd docker.io/myos
docker network inspect docker1 //可以看到容器的ip
3)使用默认网桥(docker0)启动容器
docker run -itd docker.io/myos
docker run -itd docker.io/myos
docker inspect -f '{
{.NetworkSettings.IPAddress}}' f41
docker inspect -f '{
{.NetworkSettings.IPAddress}}' 63e
4)测试
docker exec -it ae /bin/bash
ping 172.17.0.3 //可以ping通
ping 10.10.10.2 //ping不通
步骤二:扩展实验
1)新建一个网络模型docker02
docker network create --driver bridge docker02 //新建一个 名为docker02的网络模型
docker network list //查看显示docker02(查看加粗字样)
2)若要解决使用ifconfig命令可以看到docker02的问题,可以执行以下几步命令
docker network list //查看docker0的NETWORK ID(加粗字样)
3)查看16dc92e55023的信息
docker network inspect bc189673f959
4)查看图片的倒数第六行有"com.docker.network.bridge.name": "docker0"字样
5)把刚刚创建的docker02网桥删掉
docker network rm docker02 //删除docker02
docker network create \
6)若想在创建docker03时候自定义网段(之前已经创建过docker01和02,这里用docker03),执行以下命令
docker network create docker03 --subnet=172.30.0.0/16 -o com.docker.network.bridge.name=docker03
ifconfig //ifconfig查看,显示的是自己定义的网段
curl http://192.168.1.100:5000/v2/docker.io/pod-infrastructure/tags/list
architecture:
1 ansible
部署(40ansible 41web1 42web2 43db1 44db2 45cache)
真机
scp -r /linux-soft/04/ansible/ root@192.168.1.40:/
ssh root@192.168.1.40
yum -y install ansible python-*.rpm sshpass python2
sed -i '14s/#//' /etc/ansible/ansible.cfg
sed -i '61s/#//' /etc/ansible/ansible.cfg
echo [web]\nweb[1:2]\n[db]\ndb[1:2]\n[other]\ncache >> /etc/ansible/hosts
补充:
1)变量解析
ansible 执行命令是二次解析,第一次在本机解析, 第二次在执行机器解析,需要第二次解析的变量要转移(\)
2)创建的文件在哪里
文件在用户家目录,ansible 是使用 ssh 多次连接执行,连接退出以后之前的状态就全部失效了
解决方法:使用 chdir 代替 cd 命令
ansible cache -m shell -a 'chdir=/tmp touch testfile'
3) 模块:ansible 主机集合 -m 模块 -a '命令'
shell(命令)
script(脚本)
yum(name=服务 state=installed/removed)
service(name=服务 state=started/stopped/restarted/reloaded enabled=yes/no)
copy(src=本地目录 dest=远程目录)
lineinfile(path=目录 regexp=^哪一行 line=这一行的输出结果)
replace(path=目录 regexp=修改的东西 replace=改为什么)
setup(filter=)(grep=)
4)'uptime' //查负载
ansible-doc -l //列出所有模块
ansible-doc moudulename //看帮助
2 playbook
1)ansible 七种武器
ansible命令/ansible-doc模块/ansible-console交互式工具/ansible-galaxy管理角色/ansible-playbook脚本/ansible-vault配置文件加密/ansible-pull和push工作模式/
2)JSON是基于文本独立与语言的轻量级的数据交换格式,是字符串
特性:纯文本/自我描述/层级结构/解析javascript
语法规则:大括号保存对象,中括号保存数组,逗号保存数据 {key: value} [a,b,c]
3)YAML表达数据序列,可读性高
语法规则:数组用"- "表示,键值用": "表示(符号后面都有空格)(不要使用tab,统一层级缩进必须对齐)
{key: value}
- "a"
- "b"
- "123"
4)jinja2是python的模板引擎
语法: {
% if name == tom %}
{
% elif name == tom %}
{
% else %}
{
% endif %}
5)playbook
ansible-doc service/user/yum/lineinfile
vim a.yml
---
- hosts: web
remote_user: root
tasks:
- name: install the latest version of Apache
yum:
name: httpd
state: installed
- lineinfile:
path: /etc/httpd/conf/httpd.conf
regexp: '^Listen 80'
line: 'Listen 8080'
- copy:
src: /index.html
dest: /var/www/html/index.html
- service:
name: httpd
state: started
enabled: yes
ansible-playbook a.yml
打标签
tags: tom
handlers:
ansible-playbook b.yml -t tom
when
register
补充:template与copy一样
vim /myhost
3 ELK:
1) e集群安装(51-55es 56kibana 57logstash)
方法一for循环:
真机:
for i in 51 52 53 54 55 56 57
do
scp -r /linux-soft/04/elk/ root@192.168.1.$i:/
done
51-55:
yum -y install java-1.8.0-openjdk.x86_64
yum -y install /elk/elasticsearch-2.3.4.rpm
echo "192.168.1.51 es1\n192.168.1.52 es2\n192.168.1.53 es3\n192.168.1.54 es4\n192.168.1.55 es5" /etc/hosts
sed -i '17c cluster.name: myelk' /etc/elasticsearch/elasticsearch.yml
sed -i '23c node.name: es1' /etc/elasticsearch/elasticsearch.yml //此处其他机子修改为es2,es3等等
sed -i '54c network.host: 0.0.0.0' /etc/elasticsearch/elasticsearch.yml
sed -i '68c discovery.zen.ping.unicast.hosts: ["es1", "es2", "es3"]' /etc/elasticsearch/elasticsearch.yml
systemctl restart elasticsearch
ss -antup | grep 9200
ss -antup | grep 9300
firefox http://192.168.1.51:9200/_cluster/health?pretty
"方法二用ansibe写:
---
- hosts: es
remote_user: root
tasks:
- copy:
src: /etc/yum.repos.d/local.repo
dest: /etc/yum.repos.d/local.repo
- yum:
name: java-1.8.0-openjdk,/elk/elasticsearch
state: installed
- template:
src: /etc/elasticsearch/elasticsearch.yml
dest: /etc/elasticsearch/elasticsearch.yml
notify: reload elasticsearch
tags: esconf
- service:
name: elasticsearch
enabled: yes
handlers:
- service:
name: elasticsearch
state: restarted
echo "ansible_ssh_passwd="a"" >> myhost
ansible es -m shell -e ''"
2) e部署插件
cp -r /linux-soft/04/elk/ /var/ftp/
ssh root@192.168.1.51
cd /usr/share/elasticsearch/bin
./plugin install ftp://192.168.1.254/elk/elasticsearch-head-master.zip
./plugin install ftp://192.168.1.254/elk/elasticsearch-kopf-master.zip
./plugin install ftp://192.168.1.254/elk/bigdesk-master.zip
firefox http://192.168.1.51:9200/_plugin/head
1)图形用鼠标创建索引
2)命令创建索引(JSON格式)
[root@es5 bin]
"settings": {
"index": {
"number_of_shards": 5, //分片数
"number_of_replicas": 1 //副本数
}
}
}'
{
"acknowledged":true}
3) e增删改查(JSON格式)
1) 增加
[root@es5 ~]
"职业": "诗人",
"年代": "唐"
}'
2) 删除数据和索引
[root@es5 ~]
[root@es5 bin]
3) 修改
[root@es5 ~]
"doc":{
"年代": "唐代"
}
}'
4) 查询
[root@es5 ~]
4) e导入数据
scp /var/ftp/elk/*.gz root@192.168.1.56:/
ssh root@192.168.1.56
gzip -d /logs.jsonl.gz
curl -X POST "http://192.168.1.51:9200/_bulk" --data-binary @/logs.jsonl
补充:爬取数据的解决办法,盘个验证法(12306)
百度基于lucene写出来
http协议请求由三部分组成:请求行,消息报头,请求正文.常用方法:get post head
格式:Method Request-URI HTTP-Version CRLF
curl常用参数:-A(修改请求) -X(设置请求方法) -i(显示返回头信息)
?pretty:让其竖着显示
4 kibana和logstash(56)(端口5601)
kibana原理:数据可视化平台工具
kibana特点:灵活分析/可视化平台/即使分享/实时图形显示
logstash原理:数据采集/加工处理/传输工具
logstash特点:集中处理/高扩展/插件丰富
安装kibana:
yum -y install /elk/kibana-4.5.2-1.x86_64.rpm
scp /etc/hosts root@192.168.1.56:/etc/hosts
sed -i '2s/# //' /opt/kibana/config/kibana.yml
sed -i '5s/# //' /opt/kibana/config/kibana.yml
sed -i '15s/# //' /opt/kibana/config/kibana.yml
sed -i '15s/localhost/192.168.1.51/' /opt/kibana/config/kibana.yml
sed -i '23s/# //' /opt/kibana/config/kibana.yml
sed -i '26s/# //' /opt/kibana/config/kibana.yml
sed -i '53s/# //' /opt/kibana/config/kibana.yml
sed -i '57s/# //' /opt/kibana/config/kibana.yml
sed -i '64s/# //' /opt/kibana/config/kibana.yml
systemctl restart kibana
ss -antup | grep 5601
安装logstash:
yum -y install java-1.8.0-openjdk
yum -y install /elk/logstash-2.3.4-1.noarch.rpm
scp /etc/hosts root@192.168.1.57:/etc/hosts
echo "input{
stdin{
codec => json }}
filter{
}
output{
stdout{
codec => rubydebug }}" >> /etc/logstash/logstash.conf
/opt/logstash/bin/logstash -f /etc/logstash/logstash.conf ////启动并测试
{
"a": 1, "b": 2}
注:/opt/logstash/bin/logstash-plugin list //查看插件
插件codes的stdin类型/file类型/filter grok插件
input{
file {
path => [ "/tmp/a.log", "/tmp/b.log" ]
sincedb_path => "/var/lib/logstash/sincedb" //记录读取文件的位置
start_position => "beginning" //配置第一次读取文件从什么地方开始
type => "testlog"}} //类型名称
filter{
grok{
match => [ "message", "(?reg)" ]}}
filebeat:
ssh root@192.168.1.55
yum -y install filebeat
sed -i '15s/*.log/httpd/access_log/' /etc/filebeat/filebeat.yml
sed -i '72s/#//' /etc/filebeat/filebeat.yml
sed -i '72s/log/apachelog/' /etc/filebeat/filebeat.yml //文档类型
sed -i '183s/^/#/' /etc/filebeat/filebeat.yml
sed -i '188s/^/#/' /etc/filebeat/filebeat.yml
sed -i '278s/#//' /etc/filebeat/filebeat.yml
sed -i '280s/#//' /etc/filebeat/filebeat.yml
sed -i '280s/localhost/192.168.1.57/' /etc/filebeat/filebeat.yml
systemctl start filebeat
ssh root@192.168.1.57
5 hadoop
1) 部署:(javajdk都装),四台机子互相免秘钥登录和hosts,scp传配置文件到其他四台)(60,61,62,63)
yum -y install java-1.8.0-openjdk-devel
tar -avxf /hadoop-2.7.7.tar.gz
mv hadoop-2.7.7/ /usr/local/hadoop
sed -i '25s/${JAVA_HOME}/"/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre"/' /usr/local/hadoop/etc/hadoop/hadoop-env.sh //第一个配置文件
sed -i '33s/${*}/"/usr/local/hadoop/etc/hadoop"/' /usr/local/hadoop/etc/hadoop/hadoop-env.sh
/usr/local/hadoop/bin/hadoop //启动服务,单机版就配置完成了
echo node1\nnode2\nnode3 > /usr/local/hadoop/etc/hadoop/slaves //第二个配置文件(删除localhost)
sed -i '19a
<property>
<name>fs.defaultFS</name> //是用什么样的文件系统,默认文件系统
<value>hdfs://nn01:9000</value> //访问文件系统的前缀
</property>
<property>
<name>hadoop.tmp.dir</name> //数据存放目录
<value>/var/hadoop</value>
</property>' /usr/local/hadoop/etc/hadoop/core-site.xml //第三个配置文件
mkdir /var/hadoop
sed -i '19a
<property>
<name>dfs.namenode.http-address</name> //谁是namenode
<value>nn01:50070</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name> //哪台启动secondarynode
<value>nn01:50090</value>
</property>
<property>
<name>dfs.replication</name> //数据存几份
<value>2</value>
</property>' /usr/local/hadoop/etc/hadoop/hdfs-site.xml //第四个配置文件
mv /usr/local/hadoop/etc/hadoop/mapred-site.xml.template /usr/local/hadoop/etc/hadoop/mapred-site.xml
sed -i '19a
<property>
<name>mapreduce.framework.name</name> //验证管理系统
<value>yarn</value>
</property>' /usr/local/hadoop/etc/hadoop/mapred-site.xml //第五个配置文件
sed -i '18a
<property>
<name>yarn.resourcemanager.hostname</name>
<value>nn01</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value> //计算框架的名称
</property>' /usr/local/hadoop/etc/hadoop/yarn-site.xml //第六个配置文件
/usr/local/hadoop/bin/hdfs namenode -format //格式化 namenode
/usr/local/hadoop/sbin/start-dfs.sh //启动
/usr/local/hadoop/sbin/start-yarn.sh //启动
jps //验证角色
/usr/local/hadoop/bin/hdfs dfsadmin -report //查看集群是否组建成功
/usr/local/hadoop/bin/yarn node -list //验证服务在node上操作
补充:
2) Hadoop词频统计
/usr/local/hadoop/bin/hadoop fs -ls /etc/
/usr/local/hadoop/bin/hadoop fs -mkdir /aaa
/usr/local/hadoop/bin/hadoop fs -touchz /aaa //只有这个和shell命令不一样
/usr/local/hadoop/bin/hadoop fs -put /usr/local/hadoop/*.txt /aaa //上传*.txt到集群文件系统下的aaa目录
/usr/local/hadoop/bin/hadoop fs -get /aaa /bbb //下载
3) 添加节点
1>nn01修改hosts,slave,重新同步hosts,slave,秘钥三个到其他四台
rsync -aSH --delete /usr/local/hadoop/192.168.1.$i:/usr/local/hadoop/ -e 'ssh' &
2>/usr/local/hadoop/sbin/hadoop-daemon.sh start datanode //启动//node4操作
/usr/local/hadoop/bin/hdfs dfsadmin -setBalancerBandwidth 60000000 //设置同步带宽//node4操作
/usr/local/hadoop/sbin/start-balancer.sh //启动带宽同步//node4操作
4) 删除节点
1>去掉slaves的node4
2>vim /usr/local/hadoop/etc/hadoop/hdfs-site.xml //加入四行,
<property>
<name>dfs.hosts.exclude</name>
<value>/usr/local/hadoop/etc/hadoop/exclude</value>
</property>
3> echo "node4" >> /usr/local/hadoop/etc/hadoop/exclude
5)导出数据
/usr/local/hadoop/bin/hdfs dfsadmin -refreshNodes
/usr/local/hadoop/bin/hdfs dfsadmin -report
6) NFS配置
步骤一:
/etc/hosts
yum -y install java-1.8.0-openjdk-devel //nfsgw上面操作
groupadd -g 800 nfsuser //创建代理用户(nn01和nfsgw上面操作),以nn01为例子
useradd -u 800 -g 800 -r -d /var/hadoop nfsuser //创建代理用户(nn01和nfsgw上面操作),以nn01为例子
/usr/local/hadoop/sbin/stop-all.sh //停止所有服务
sed -i '19a
<property>
<name>hadoop.proxyuser.nfsuser.groups</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.nfsuser.hosts</name>
<value>*</value>
</property>' /usr/local/hadoop/etc/hadoop/core-site.xml
for i in 61 62 63
do
rsync -aSH --delete /usr/local/hadoop/ 192.168.1.$i:/usr/local/hadoop/ -e 'ssh' &
done
/usr/local/hadoop/sbin/start-dfs.sh
步骤二:NFSGW配置
rsync -avSH --delete /usr/local/hadoop/ 192.168.1.65:/usr/local/hadoop/ -e 'ssh'
mkdir -p /var/hadoop /var/nfstmp
chown nfsuser:nfsuser /var/nfstmp
setfacl -m user:nfsuser:rwx /usr/local/hadoop/logs
sed -i '19a
<property>
<name>nfs.exports.allowed.hosts</name>
<value>* rw</value>
</property>
<property>
<name>nfs.dump.dir</name>
<value>/var/nfstmp</value>
</property>' /usr/local/hadoop/etc/hadoop/hdfs-site.xml
/usr/local/hadoop/sbin/hadoop-daemon.sh --script ./bin/hdfs start portmap //启动服务(先后顺序)
/usr/local/hadoop//sbin/hadoop-daemon.sh --script ./bin/hdfs start nfs3 //nfs3只能代理用户启动
步骤三:新机子客户端
yum -y install nfs-utils
echo "192.168.1.65:/ /mnt/nfs vers=3,proto=tcp,nolock,noatime,sync,noacl,_netdev 0 0" >> /etc/fstab
mount -a
rpcinfo -p 192.168.1.65
6 Hadoop高可用(hosts,私钥和公钥,,,,)
/usr/local/hadoop/sbin/stop-all.sh //停止所有服务
/usr/local/zookeeper/bin/zkServer.sh start
sed -i '25s/${JAVA_HOME}/"/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre"/' /usr/local/hadoop/etc/hadoop/hadoop-env.sh //第一个配置文件
sed -i '33s/${*}/"/usr/local/hadoop/etc/hadoop"/' /usr/local/hadoop/etc/hadoop/hadoop-env.sh
/usr/local/hadoop/bin/hadoop //启动服务,单机版就配置完成了
echo node1\nnode2\nnode3 > /usr/local/hadoop/etc/hadoop/slaves //第二个配置文件(删除localhost)
sed -i '19a
<property>
<name>fs.defaultFS</name>
<value>hdfs://nsdcluster</value> //nsdcluster是随便起的名。相当于一个组,访问的时候访问这个组
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/var/hadoop</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>node1:2181,node2:2181,node3:2181</value> //zookeepe的地址
</property>
<property>
<name>hadoop.proxyuser.nfs.groups</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.nfs.hosts</name>
<value>*</value>
</property>' /usr/local/hadoop/etc/hadoop/core-site.xml //第三个配置文件
mkdir /var/hadoop
sed -i '19a
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.nameservices</name>
<value>nsdcluster</value>
</property>
<property>
<name>dfs.ha.namenodes.nsdcluster</name> //nn1,nn2名称固定,是内置的变量,nsdcluster里面有nn1,nn2
<value>nn1,nn2</value>
</property>
<property>
<name>dfs.namenode.rpc-address.nsdcluster.nn1</name> //声明nn1 8020为通讯端口,是nn01的rpc通讯端口
<value>nn01:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.nsdcluster.nn2</name> //声明nn2是谁,nn02的rpc通讯端口
<value>nn02:8020</value>
</property>
<property>
<name>dfs.namenode.http-address.nsdcluster.nn1</name> //nn01的http通讯端口
<value>nn01:50070</value>
</property>
<property>
<name>dfs.namenode.http-address.nsdcluster.nn2</name> //nn01和nn02的http通讯端口
<value>nn02:50070</value>
</property>
<property>
<name>dfs.namenode.shared.edits.dir</name> //指定namenode元数据存储在journalnode中的路径
<value>qjournal://node1:8485;node2:8485;node3:8485/nsdcluster</value>
</property>
<property>
<name>dfs.journalnode.edits.dir</name> //指定journalnode日志文件存储的路径
<value>/var/hadoop/journal</value>
</property>
<property>
<name>dfs.client.failover.proxy.provider.nsdcluster</name> //指定HDFS客户端连接active namenode的java类
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<property>
<name>dfs.ha.fencing.methods</name> //配置隔离机制为ssh
<value>sshfence</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name> //指定密钥的位置
<value>/root/.ssh/id_rsa</value>
</property>
<property>
<name>dfs.ha.automatic-failover.enabled</name> //开启自动故障转移
<value>true</value>
</property>' /usr/local/hadoop/etc/hadoop/hdfs-site.xml //第四个配置文件
mv /usr/local/hadoop/etc/hadoop/mapred-site.xml.template /usr/local/hadoop/etc/hadoop/mapred-site.xml
sed -i '19a
<property>
<name>mapreduce.framework.name</name> //验证管理系统
<value>yarn</value>
</property>' /usr/local/hadoop/etc/hadoop/mapred-site.xml //第五个配置文件
sed -i '18a
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.ha.rm-ids</name> //rm1,rm2代表nn01和nn02
<value>rm1,rm2</value>
</property>
<property>
<name>yarn.resourcemanager.recovery.enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.resourcemanager.store.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
</property>
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>node1:2181,node2:2181,node3:2181</value>
</property>
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yarn-ha</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>nn01</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>nn02</value>
</property>' /usr/local/hadoop/etc/hadoop/yarn-site.xml //第六个配置文件
for i in {
60..63} 66; do ssh 192.168.1.$i rm -rf /usr/local/hadoop/logs ; done //删除所有logs,方便排错
for i in {
61..63} 66; do rsync -aSH --delete /usr/local/hadoop/ 192.168.1.$i:/usr/local/hadoop -e 'ssh' & done //同步配置
高可用验证:
步骤一:验证hadoop的高可用
/usr/local/hadoop/bin/hdfs zkfc -formatZK //初始化ZK集群(nn01)
/usr/local/hadoop/sbin/hadoop-daemon.sh start journalnode //在node1,node2,node3启动journalnode服务
/usr/local/hadoop//bin/hdfs namenode -format //格式化(nn01)
rsync -aSH nn01:/var/hadoop/ /var/hadoop/ //nn02数据同步到本地 /var/hadoop/dfs(nno2)
/usr/local/hadoop/bin/hdfs namenode -initializeSharedEdits //初始化 JNS(nn01)
/usr/local/hadoop/sbin/hadoop-daemon.sh stop journalnode //停止 journalnode服务(node1,node2,node3)
步骤二:启动集群
/usr/local/hadoop/sbin/start-all.sh //启动所有集群(nn01)
/usr/local/hadoop/sbin/yarn-daemon.sh start resourcemanager //nn02上面操作
/usr/local/hadoop/bin/hdfs haadmin -getServiceState nn1 //查看集群状态(nn01操作)
/usr/local/hadoop/bin/hdfs haadmin -getServiceState nn2
/usr/local/hadoop/bin/yarn rmadmin -getServiceState rm1
/usr/local/hadoop/bin/yarn rmadmin -getServiceState rm2
/usr/local/hadoop/bin/hdfs dfsadmin -report //查看节点是否加入
/usr/local/hadoop/bin/yarn node -list //
步骤三:访问集群(nn01操作)
/usr/local/hadoop/bin/hadoop fs -ls /
/usr/local/hadoop/bin/hadoop fs -mkdir /aa //创建aa
/usr/local/hadoop/bin/hadoop fs -ls / //再次查看
/usr/local/hadoop/bin/hadoop fs -put *.txt /aa
/usr/local/hadoop/bin/hadoop fs -ls hdfs://nsdcluster/aa //也可以这样查看
/usr/local/hadoop/bin/hdfs haadmin -getServiceState nn1
/usr/local/hadoop/sbin/hadoop-daemon.sh stop namenode
/usr/local/hadoop/bin/hdfs haadmin -getServiceState nn1 //再次查看会报错
/usr/local/hadoop/bin/hdfs haadmin -getServiceState nn2 //nn02由之前的standby变为active
/usr/local/hadoop/bin/yarn rmadmin -getServiceState rm1
/usr/local/hadoop/sbin/yarn-daemon.sh stop resourcemanager //停止resourcemanager
/usr/local/hadoop/bin/yarn rmadmin -getServiceState rm2
/usr/local/hadoop/sbin/hadoop-daemon.sh start namenode //恢复节点 //启动namenode
/usr/local/hadoop/sbin/yarn-daemon.sh start resourcemanager //恢复节点 //启动resourcemanage
/usr/local/hadoop/bin/hdfs haadmin -getServiceState nn1 //恢复节点
/usr/local/hadoop/bin/yarn rmadmin -getServiceState rm1 //恢复节点
6 zookeeper集群(60 61 62 63)
tar -xf /zookeeper-3.4.13.tar.gz
mv zookeeper-3.4.13 /usr/local/zookeeper
mv /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg
chown root.root /usr/local/zookeeper/conf/zoo.cfg
echo "server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
server.4=nn01:2888:3888:observer" >> /usr/local/zookeeper/conf/zoo.cfg
for i in {
61..63}; do rsync -aXSH --delete /usr/local/zookeeper/ 192.168.1.$i:/usr/local/zookeeper done
mkdir /tmp/zookeeper //创建 mkdir /tmp/zookeeper,每一台都要
echo 4 >/tmp/zookeeper/myid //每一台都要,其余对应配置文件数字分别输入1,2,3
/usr/local/zookeeper/bin/zkServer.sh start //每一台上面都要手工启动
/usr/local/zookeeper/bin/zkServer.sh status
官方文档:zookeeper.apache.org/doc
7 Kafka集群
部署:(依赖事先建好的zookeeper集群)(60 61 62 63)
tar -xf /kafka_2.12-2.1.0.tgz
mv kafka_2.12-2.1.0 /usr/local/kafka
sed -i '21s/0/4/' /usr/local/kafka/config/server.properties //其他三台分别把0改为1,2,3
sed -i '123s/localhost:2181/node1:2181,node2:2181,node3:2181/' /usr/local/kafka/config/server.properties
for i in 61 62 63; do rsync -aSH --delete /usr/local/kafka 192.168.1.$i:/usr/local/; done
/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties //启动 (node1,node2,node3都启动)
/usr/local/kafka/bin/kafka-topics.sh --create --partitions 1 --replication-factor 1 --zookeeper node3:2181 --topic aa //验证配置,创建一个 topic,只61操作
/usr/local/kafka/bin/kafka-console-producer.sh --broker-list node2:9092 --topic aa //模拟生产者,发布消息,写一个数据,只62操作
/usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server node1:9092 --topic aa //模拟消费者,接收消息,这边会直接同步,只63操作
8 k8s:是容器集群管理系统,是一个开源的平台,可以实现容器集群的自动化部署、自动扩缩容、维护等功能
- 快速部署应用
- 快速扩展应用
- 无缝对接新的应用功能
- 节省资源,优化硬件资源的使用
- **可移植**: 支持公有云,私有云,混合云,多重云(multi-cloud)
- **可扩展**: 模块化, 插件化, 可挂载, 可组合
- **自动化**: 自动部署,自动重启,自动复制,自动伸缩/扩展
- **Build, Ship and Run (创建,发送和运行)**
- **Build once,Run anywhere(搭建一次,到处能用)**
- Docker技术的三大核心概念,分别是:
1. 镜像(Image)
2. 容器(Container)
3. 仓库(Repository)
一个K8S系统,通常称为一个**K8S集群(Cluster)**
这个集群主要包括两个部分:
- **一个Master节点(主节点)**
- Master节点包括API Server、Scheduler、Controller manager、etcd。
<200b> API Server是整个系统的对外接口,供客户端和其它组件调用,相当于“营业厅”。
<200b> Scheduler负责对集群内部的资源进行调度,相当于“调度室”。
<200b> Controller manager负责管理控制器,相当于“大总管”。
**一群Node节点(计算节点)**
- Node节点包括**Docker、kubelet、kube-proxy、Fluentd、kube-dns**(可选),还有就是**Pod**。
<200b> **Pod**是Kubernetes最基本的操作单元。
<200b> 一个Pod代表着集群中运行的一个进程,它内部封装了一个或多个紧密相关的容器。
<200b> 除了Pod之外,K8S还有一个**Service**,一个Service可以看作一组提供相同服务的Pod的对外访问接口
<200b> Docker,不用说了,创建容器的。
<200b> Kubelet,主要负责监视指派到它所在Node上的Pod,包括创建、修改、监控、删除等。
<200b> Kube-proxy,主要负责为Pod对象提供代理。
<200b> Fluentd,主要负责日志收集、存储与查询。
安装配置
1 设置 ip 和主机名
/etc/hosts
2 开启路由转发
net.ipv4.ip_forward=1
3 配置 yum 源
RHEL7-extras.iso
4 配置私有仓库 registry [repo]
yum install docker-distribution
管理镜像使用 docker
yum install docker
/etc/sysconfig/docker
上传镜像
centos.tar
kubernetes-dashboard.tar
pod-infrastructure.tar
验证
curl http://192.168.1.100:5000/v2/_catalog
5 配置 kubernets - master
package:
etcd
kubernetes-master
kubernetes-client
service:
kube-apiserver
kube-controller-manager
kube-scheduler
etcd
conf:
/etc/etcd/etcd.conf
6: ETCD_LISTEN_CLIENT_URLS="http://192.168.1.10:2379"
/etc/kubernetes/config
22: KUBE_MASTER="--master=http://192.168.1.10:8080"
/etc/kubernetes/apiserver
8: KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
17: KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.1.10:2379"
23: 删除 ServiceAccount 参数
/etc/kubernetes/controller-manager
/etc/kubernetes/scheduler
验证
kubectl get cs
kubectl get csr
kubectl get node
6 配置 kubernets - minion(node1-3)
package:
kubernetes-node
docker
service:
kubelet
kube-proxy
docker
conf:
/etc/sysconfig/docker
4: 添加参数 --insecure-registry=192.168.1.100:5000 --add-registry 192.168.1.100:5000
/etc/kubernetes/config
22: KUBE_MASTER="--master=http://192.168.1.10:8080"
/etc/kubernetes/kubelet
5: KUBELET_ADDRESS="--address=0.0.0.0"
11: KUBELET_HOSTNAME="--hostname-override=本机名称"
14: 添加 --kubeconfig=/etc/kubernetes/kubelet.kubeconfig
--pod-infra-container-image=pod-infrastructure:latest
/etc/kubernetes/kubelet.kubeconfig
apiVersion: v1
kind: Config
clusters:
- cluster:
server: http://192.168.1.10:8080
name: local
contexts:
- context:
cluster: local
name: local
current-context: local
7 网络
master:
yum -y install flannel.x86_64
/etc/etcd/etcd.conf
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
systemctl restart etcd
etcdctl mk /atomic.io/network/config '{"Network": "10.254.0.0/16", "Backend": {"Type": "vxlan"}}'
minion:
yum -y install flannel.x86_64
package: flannel
/etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://192.168.1.10:2379" //master也配置
systemctl restart flanneld docker
8 创建容器,测试
kubectl create -f baseos.yaml
测试
kubectl get pod -o wide
kubectl exec -it test-os-3826630470-jc5j4 -- /bin/bash
kubectl create -f kube-dashboard.yaml
image: 192.168.1.100:5000/docker.io/kubernetes-dashboard-amd64:latest
node1操作:docker run -it centos:latest