个人记录,仅供参考,非理想型的学习文章
因为穷,买不起服务器,所以要使用vmware虚拟机
安装过程略
个人选择的系统是centos 7 64位
,需要对应的iso文件,打开centos的官网,点击Get Centos Now
,点击centos linux DVD iso
(稳定版),另外一个是尝鲜版;当前最新版本的centos是8,如果想下载其他的版本的,可以在 More Download Choices
中查找
CentOS的镜像文件除了可以安装,修复系统之外,本身也可以作为操作系统,直接运行,此外还含有一些软件的安装包(Packages),当你以后需要的时候,可以从中选择进行安装,各个版本简略区别如下:
- DVD:大多数时候的选择,你可以在安装的过程中选择安装一些软件,让其成为网页服务器,文件服务器等等,需要安装更多软件的时候,多数情况,基础Packages足够使用
- Everything:在DVD版的基础上拥有更多的Packages
- LiveGNOME:带图像界面,运行于U盘,光盘等介质上的操作系统,类似老毛桃,微PE这类工具,桌面为GNOME,只能安装出带GNOME桌面的系统
- LiveKDE:同LiveGNOME版,不同在于桌面为KDE,此两种Live版本主要在于无需安装,即可体验带图形界面的操作系统,也具有安装功能不过限制只能安装成出带指定桌面的版本
- Minimal:只有安装出最精简的系统,仅有少量安装包(Packages);无法在安装时选择更多的软件,使其成为网页服务器,文件服务器等,对于有经验的服务器管理员,系统安装时所安装的这些网页服务器功能等,并不实用,同时完全精简的系统对硬件资源消耗也更小,同时安装速度也更快
- NetInstall:比较特殊的一种,主要用于连接网络上的资源,用以安装系统,其本身只是引导安装,并不含有实际的安装文件,
- 通常选择DVD版本即可
文件大小参考
CentOS-7-x86_64-DVD-XXXX.iso(约4G)
CentOS-7-x86_64-Everything-XXXX.iso(约8G)
CentOS-7-x86_64-LiveGNOME-XXXX.iso(约1G)
CentOS-7-x86_64-LiveKDE-XXXX.iso(约2G)
CentOS-7-x86_64-Minimal-XXXX.iso(约800M)
CentOS-7-x86_64-NetInstall-XXXX.iso(约400M)
以上来自 CentOS 7 安装篇之ISO文件选择
不过DVD版的是由操作界面的,我还是习惯命令行,所以我用的是Minimal
给虚拟机配置了iso文件后,开启虚拟机时还要配置centos,配置Centos
配置完成并成功开启后,记得克隆多几个出来备用(使用完整克隆)
启动成功后,命令行ip address
查询ip,然后使用Shell工具连接,不要直接在VMWare上操作,一个原因是VMWare对文件查看,上传什么的操作不是很方面;另外一个原因是个人觉得他丑;我用的是FinalShell,高星级推荐
注:
如果ip address后inet项没有信息,可以修改 etc/sysconfig/network-scripts//ifcfg-ens33 文件
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=89cd37ee-7018-4764-a9ea-b822919457d5
DEVICE=ens33
ONBOOT=yes
将最后一行的ONBOOT=no
改成ONBOOT=yes
,其他的关于ip的改动也主要是通过这个文件的配置
如果shell工具连接不上,请优先查看虚拟机中防火墙、网络等设置是否正常,再查看本机的网络适配器
部署一个普通的elastic之后(记得先安装java环境),在服务器中输入curl -XGET "ip:9200"
,看到以下内容:
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "uW9SwwfjTHu5Qavb3hsT2g",
"version" : {
"number" : "6.6.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "a9861f4",
"build_date" : "2019-01-24T11:27:09.439740Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
说明启动成功;这时候再使用浏览器访问 ip:9200 发现无法访问,考虑是不是端口跟防火墙问题,需要修改etc/sysconfig下的iptables
然而,centos7现在是默认没有iptables这个文件的,需要自己再去安装
使用yum install iptables-services
进行更新或者安装,安装完成后vi etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
在配置-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
后面新增配置:-A INPUT -m state --state NEW -m tcp -p tcp --dport 9200 -j ACCEPT
,之后重启防火墙 service iptables restart
本地浏览器就可以访问相关端口了
开三台机器,elasticsearch.yml配置如下
server1
# 集群名,每一台机器的集群名必须一样
cluster.name: my-application
# 节点名,每一台机器的节点名必须不一样
node.name: node-1
# 日志跟数据的存放位置,正式环境中应该在服务器中开一块合理的、足够大的空间去存放
#path.data: /path/to/data
#path.logs: /path/to/logs
# 这个配置也重要,暂时没研究
#bootstrap.memory_lock: true
# 主机ip
network.host: 192.168.81.128
# 开放端口,默认为9200跟9300,这里为了方便识别,不使用默认的,三台服务器的port都要不一样
http.port: 9201
transport.tcp.port: 9301
# 每添加一个节点,需要在这个配置中加上
discovery.zen.ping.unicast.hosts: ["192.168.81.128:9301", "192.168.81.129:9302", "192.168.81.130:9303"]
# 防集群脑裂设置,规则为(总机器数/2 + 1)
discovery.zen.minimum_master_nodes: 3
# 跨域设置,用于各种可视化插件能正常接入(head、kibana)
http.cors.enabled: true
http.cors.allow-origin: "*"
# 节点功能设置,master(可参与选举主节点),data(可存放数据)
node.master: true
node.data: true
server2
cluster.name: my-application
node.name: node-2
#path.data: /path/to/data
#path.logs: /path/to/logs
#bootstrap.memory_lock: true
network.host: 192.168.81.129
http.port: 9202
transport.tcp.port: 9302
discovery.zen.ping.unicast.hosts: ["192.168.81.128:9301", "192.168.81.129:9302", "192.168.81.130:9303"]
discovery.zen.minimum_master_nodes: 3
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
server3
cluster.name: my-application
node.name: node-3
#path.data: /path/to/data
#path.logs: /path/to/logs
#bootstrap.memory_lock: true
network.host: 192.168.81.130
http.port: 9203
transport.tcp.port: 9303
discovery.zen.ping.unicast.hosts: ["192.168.81.128:9301", "192.168.81.129:9302", "192.168.81.130:9303"]
discovery.zen.minimum_master_nodes: 3
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
还有一部工作需要做,那就是清除es路径中的原有的data文件夹,三台机器全部启动(记得开放相关的端口,否则会ping不上),开启后使用head等工具连接其中一个,如图
1、开启后集群会根据内部规则选举一个主节点(master),如果在配置文件中设置 node.master:false
那么该节点就无法成为主节点;
2、head只需要连接任意服务器,便能看到集群;
3、新建一个索引,分片跟副本会分不到不同的机器上,同编号的分片跟副本不会在同一台机器上,如0分片在node-1,那么0副本就只能在node-2或者node-3;
多机器ES集群部署结束,接下来尝试docker部署
Docker
- 官方建议linux内核3.8以上,用
uname -a
查看内核信息
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
- 将yum包更新一下
yum update
- 安装软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
- 设置yum源(二选一)
(阿里仓库)
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
(中央仓库)
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
- 查看docker仓库中所有的docker版本
yum list docker-ce --showduplicates | sort -r
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
* updates: mirrors.ustc.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
* extras: mirrors.aliyun.com
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable
* base: mirrors.ustc.edu.cn
Available Packages
- 安装docker,版本在上面选,比如
yum install docker-ce-18.03.1.ce
- 启动dokcer并加入开机启动
[root@localhost ~]# systemctl start docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
- 查看docker版本信息
[root@localhost ~]# docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:20:16 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:23:58 2018
OS/Arch: linux/amd64
Experimental: false
- 测试是否安装成功
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout.
See 'docker run --help'.
出现以上内容,则是安装成功,之所以不能运行,是远程镜像拉不下来
- 配置镜像加速器(阿里云)
在etc/docker路径下找到daemon.json文件,如果没有,就手动创建它,加入以下配置(严格json格式)
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
然后重启docker
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl restart docker
检测加速器是否安装成功 docker info
,如果在返回结果中看到找到以下内容,则成功
Registry Mirrors:
https://registry.docker-cn.com/
TODO…