热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

centossshlocalhostrefused_centos配置高可用环境

前言:使用centos虚拟机做各种实验时候总会碰到以下情况:重启后机器ip不固定,需要手动开启,不知道防火墙是否开启总有意外

前言:

使用centos虚拟机做各种实验时候总会碰到以下情况:重启后机器ip不固定,需要手动开启,不知道防火墙是否开启总有意外的连接失败,机器没有特殊标识上面安装了啥云里雾里一个分布式环境只做一次实验,服务器开机后没有免蜜登录一团乱麻密码是root还是root123;

我也常有以上困扰,百分之二十的时间用在实验上,剩下的时间全部用在实验环境搭建上,所以做了以下整理;

环境准备:

centos虚拟机或者待使用的服务器;

具体操作:

1、防火墙:

#第一步: 停止firewall
systemctl stop firewalld.service
#第二步:禁止firewall开机启动
systemctl disable firewalld.service
#第三步:查看防火墙状态
systemctl status firewalld.service

fbb6a3a5794fb00af7605ec75a43418e.png

2、设置静态ip:

[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-*
/etc/sysconfig/network-scripts/ifcfg-ens33
/etc/sysconfig/network-scripts/ifcfg-lo
[root@localhost ~]# ifconfig
ens33: flags=4163 mtu 1500inet 192.168.x.xx netmask 255.255.255.0 broadcast 192.168.x.xxxinet6 xxxx::xxxx:xxxx:xxxx:xxxx prefixlen 64 scopeid 0x20ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet)RX packets 271715 bytes 379958418 (362.3 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 79173 bytes 5679903 (5.4 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73 mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10loop txqueuelen 1000 (Local Loopback)RX packets 166 bytes 13876 (13.5 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 166 bytes 13876 (13.5 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ifcfg-ens33就是网卡需要修改,先备份然后修改
cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-enp0s8vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
具体修改如下:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
#修改为static
BOOTPROTO=static
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和device
NAME=enp0s8
#uuid是唯一值
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxx
DEVICE=enp0s8
ONBOOT=yes#配置静态ip地址自己指定该ip段的地址
IPADDR=192.168.1x.xxx

修改后重启机器即可;

3、重启机器前可以修改机器的主机名称,方便知道用途和环境阶段:
[root@localhost ~]# hostnamectl set-hostname 主机名称

4、配置免密登录:

1、生成公钥、私钥:
ssh-keygen -t rsa
然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)[root@localhost ~]# ssh-keygen -t rsa
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:GuRRqM5vxTH9U64Mv7nUgCyZjEbOjkGzpASPbw8FnEU root@sql_01
The key's randomart image is:
+---[RSA 2048]----+
|...+E .. |
| +o. .. |
|. o =.+ . |
| o =.O +o+.. . |
| =oo B.Soo..o |
| . oo= oo.. oo. |
| o.o. +.o. |
| o .+. |
| . +o |
+----[SHA256]-----+
[root@localhost ~]# ls -a
. .bashrc .gnupg .mozilla 模板 桌面
.. .cache google-chrome.desktop .pki 视频
anaconda-ks.cfg .config .ICEauthority .ssh 图片
.bash_history .cshrc initial-setup-ks.cfg .tcshrc 文档
.bash_logout .dbus .java .viminfo 下载
.bash_profile .esd_auth .local 公共 音乐
[root@localhost ~]# ls .ssh
id_rsa id_rsa.pub
[root@localhost ~]#

将公钥拷贝到本地机器上:

#localhost也可以是目标机器ip
[root@localhost ~]# ssh-copy-id localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:+G6UXSGpkFozRiVjxksLUQJt3glI4CZa4xrmFV7vThY.
ECDSA key fingerprint is MD5:51:19:c1:fc:1a:52:76:94:b0:36:48:66:bc:06:d7:9b.
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@localhost's password: Number of key(s) added: 1Now try logging into the machine, with: "ssh 'localhost'"
and check to make sure that only the key(s) you wanted were added.#拷贝到目标机器后使用ssh登录;
[root@localhost ~]# ssh localhost
Last login: Mon Feb 3 11:50:47 2020 from 192.168.x.xx
[root@sql_01 ~]#
可以看到登录后机器名称是有所变化的;




推荐阅读
author-avatar
小新亚笔
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有