VisualBox 安裝 CentOS 7.6 操做記錄

20181213 VisualBox 安裝 CentOS 7.6 操做記錄

20190328 克隆一個CentOS 7.6,修改主機名和IP

一、下載

官網下載地址: https://wiki.centos.org/Download
找到
	i386   Everything (ISO), Minimal (ISO), NetInstall (ISO)
選擇 阿里雲鏡像 下載
	http://mirrors.aliyun.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso

二、 開始安裝,記住鼠標切換鍵 : 左邊的 Win !切記!切記!切記!

安裝過程(以及之後運行中)只要操做鼠標就會彈出警告提示: 
前面一大堆英文( 意思就是 : 是否 Capture ?)
注意記住切換提示:
The host key is currently defined as Left ⌘.

三、在 Ubuntu Server 1804 下遠程安裝時,不會出現以上提示

老是會有 2 個鼠標箭頭
若是其中實際有效的鼠標老是到不了頂部的 「Done」,說明圖形化支持很差!須要重啓服務器!
切記: Ubuntu Server上安裝好 VisualBox 以後,必定要至少重啓一次!

CentOS 7 不分服務器版和桌面版!
在安裝過程當中,會出現一個圖形界面,用於設置時間、語言、安裝目標磁盤、安裝類型...
*** 安裝類型:缺省時最小化安裝!固然就是服務器版了!

四、首次啓動時,沒有 網卡地址 (最好直接以 root 登陸)

** 後續修改 ip 地址方式也是同樣

ip a
看到個人網卡名字:enp0s3 ,可是沒有分配 ip

虛擬機 : Network —Network setting —Bridget adapter
橋接方式也沒有 ip地址!

若是不是 root 登陸,先 su 切換到 root
cd /etc/sysconfig/network-scripts
sudo vim ifcfg-enp0s3
到最後一行,修改成YES
ONBOOT=YES

重啓網卡服務
	systemctl restart network.service

ip a
返回結果:
	1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
		link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
		inet 127.0.0.1/8 scope host lo
		   valid_lft forever preferred_lft forever
		inet6 ::1/128 scope host 
		   valid_lft forever preferred_lft forever
	2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
		link/ether 08:00:27:63:e6:f5 brd ff:ff:ff:ff:ff:ff
		inet 192.168.1.100/24 brd 192.168.1.255 scope global noprefixroute dynamic enp0s3
		   valid_lft 3253sec preferred_lft 3253sec
		inet6 fe80::ba3f:1d96:dc67:fbf3/64 scope link noprefixroute 
		   valid_lft forever preferred_lft forever
操做到這裏就能夠離開虛擬機 ,直接以 root 用戶身份 ssh 登陸!
能夠先確認一下 sshd 是否安裝、運行
ps -ef |grep sshd

如今能夠 ssh 到這個 dhcp 分配的地址去遠程操做了!
ssh root@192.168.1.100

在 Ubuntu Server 下沒有安裝 dhcp 服務,因此,我仍是直接設置了靜態地址
	BOOTPROTO=static
	IPADDR=192.168.0.184
	NETMASk="255.255.255.0"
	GATEWAY=192.168.0.1
	DNS1=223.5.5.5
	
再次重啓網卡服務
	sudo systemctl restart network.service
這時候 ssh 連接可能就死在那裏了,從新打開一個 ssh 終端
不放心的話, sudo reboot
ssh root@192.168.1.184

五、安裝基本工具,將 dhbm 加入 sudo

1)、yum install vim
雖然我沒有要求 update ,可是仍是看到他安裝了一大堆東西
摘錄一部分以下
......
	正在安裝:
 vim-enhanced                x86_64      2:7.4.160-5.el7        base      1.0 M
爲依賴而安裝:
 gpm-libs                    x86_64      1.20.7-5.el7           base       32 k
 perl                        x86_64      4:5.16.3-293.el7       base      8.0 M
 perl-Carp                   noarch      1.26-244.el7           base       19 k
 perl-Encode                 x86_64      2.51-7.el7             base      1.5 M
......
主要是一大堆依賴所需的工具,大部分都是 perlXXX

2)、yum install wget

3)、如今使用的 root ssh 登陸,爲了後續安全操做,先加入 dhbm 到 sudoer
vi /etc/sudoers
找到而且按照這行增長一行 dhbm 
	root    ALL=(ALL)       ALL
	dhbm 	ALL=(ALL)	ALL

操做到這裏就能夠 exit ,從新以 dhbm 用戶身份 ssh 登陸!

六、 切換國內源 (阿里雲)

1)、參考
https://blog.csdn.net/Pipcie/article/details/80005006

2)、查看目前 源 列表
yum repolist
返回結果:
	已加載插件:fastestmirror
	Determining fastest mirrors
	 * base: mirrors.163.com
	 * extras: mirrors.cn99.com
	 * updates: mirrors.163.com
	base                                                     | 3.6 kB     00:00     
	extras                                                   | 3.4 kB     00:00     
	updates                                                  | 3.4 kB     00:00     
	(1/4): extras/7/x86_64/primary_db                          | 156 kB   00:00     
	(2/4): base/7/x86_64/group_gz                              | 166 kB   00:00     
	(3/4): base/7/x86_64/primary_db                            | 6.0 MB   00:03     
	(4/4): updates/7/x86_64/primary_db                         | 1.3 MB   00:03     
	源標識                              源名稱                                狀態
	base/7/x86_64                       CentOS-7 - Base                       10,019
	extras/7/x86_64                     CentOS-7 - Extras                        321
	updates/7/x86_64                    CentOS-7 - Updates                       599
	repolist: 10,939

3)、下載、加載 阿里雲鏡像源
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

sudo yum clean all
sudo yum makecache

*** 若是發生:"Failed connect to mirrors.aliyuncs.com:80; 拒絕鏈接"
*** 以上 3 條指令都要 sudo ,從新來過

再次查看 yum repolist
返回結果:
	已加載插件:fastestmirror
	Loading mirror speeds from cached hostfile
	 * base: mirrors.aliyun.com
	 * extras: mirrors.aliyun.com
	 * updates: mirrors.aliyun.com
	源標識                   源名稱                                           狀態
	base/7/x86_64            CentOS-7 - Base - mirrors.aliyun.com             10,019
	extras/7/x86_64          CentOS-7 - Extras - mirrors.aliyun.com              321
	updates/7/x86_64         CentOS-7 - Updates - mirrors.aliyun.com             599
	repolist: 10,939

4)、添加第三方EPEL源 (仍是選 阿里雲)
sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sudo yum clean all
sudo yum makecache

再次查看 yum repolist
返回結果:
	已加載插件:fastestmirror
	Loading mirror speeds from cached hostfile
	 * base: mirrors.aliyun.com
	 * extras: mirrors.aliyun.com
	 * updates: mirrors.aliyun.com
	源標識                源名稱                                              狀態
	base/7/x86_64         CentOS-7 - Base - mirrors.aliyun.com                10,019
	epel/x86_64           Extra Packages for Enterprise Linux 7 - x86_64      12,746
	extras/7/x86_64       CentOS-7 - Extras - mirrors.aliyun.com                 321
	updates/7/x86_64      CentOS-7 - Updates - mirrors.aliyun.com                599
	repolist: 23,685

** 注意:多出來一個epel/x86_64  Extra Packages for Enterprise Linux 7 - x86_64

七、禁止root帳戶ssh遠程登陸

sudo vim /etc/ssh/sshd_config
找到 PermitRootLogin 
去掉這行的註釋 # 
yes更改成no 

從新加載 sshd 服務
	sudo systemctl restart sshd

再次嘗試 root ssh 遠程登陸
ssh root@192.168.1.100
	root@192.168.1.100's password: 
	Permission denied, please try again.
	root@192.168.1.100's password:

八、錯誤:Cannot find a valid baseurl for repo: base/7/x86_6

yum install vim 時出現 Cannot find a valid baseurl for repo: base/7/x86_6
ping www.baidu.com 不通

參考:
https://www.cnblogs.com/dadadechengzi/p/6670530.html

使用 nmcli 從新設置 DNS 地址
nmcli connection show
nmcli con mod enp0s3 ipv4.dns "114.114.114.114"

nmcli con up enp0s3
ping www.baidu.com 能夠了!
先安裝一下簡單工具
yum install vim
yum install wget

9 、修改主機名稱

參考:
https://blog.csdn.net/xuheng8600/article/details/79983927

查看當前的主機名稱 (3 種名稱!不知道都有什麼做用?)
hostnamectl --static
hostnamectl --transient
hostnamectl --pretty

重設主機名稱
sudo hostnamectl set-hostname centos7-77
sudo hostnamectl set-hostname centos7-77
sudo hostnamectl set-hostname centos7-77 --pretty

修改 hosts
sudo vim /etc/hosts

# 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
# ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1       centos7-77
::1             centos7-77

替換::%s/77/71/g

直接查看名稱已經改變
sudo reboot 才能看到顯示改變了?

疑問:127.0.0.1   localhost... 須要註釋掉嗎?會不會不認識 localhost?待處理

十、切換時區

命令是 timedatectlhtml

timedatectl --helplinux

查看當前時區 ** 直接 timedatectl ,沒有 timedatectl get-timezone 命令vim

timedatectl 返回結果以下:centos

Local time: 五 2019-04-05 21:21:56 EDT
	  Universal time: 六 2019-04-06 01:21:56 UTC
	        RTC time: 六 2019-04-06 01:21:55
	       Time zone: America/New_York (EDT, -0400)
	     NTP enabled: yes
	NTP synchronized: yes
	 RTC in local TZ: no
	      DST active: yes
	 Last DST change: DST began at
	                  日 2019-03-10 01:59:59 EST
	                  日 2019-03-10 03:00:00 EDT
	 Next DST change: DST ends (the clock jumps one hour backwards) at
	                  日 2019-11-03 01:59:59 EDT
	                  日 2019-11-03 01:00:00 EST

timedatectl list-timezones |grep Asia 找到 Asia/Shanghai安全

timedatectl set-timezone "Asia/Shanghai" ** 若是提示錯誤:Failed to set time zone: Invalid time zone '「Asia/Shanghai」',去掉引號!bash

timedatectl set-timezone Asia/Shanghai服務器

驗證一下 date 2019年 04月 06日 星期六 09:24:54 CSTdom

和本地時間對上了!ssh

十一、查看系統信息

  1. 查看版本信息位置 ll /etc/centos -rw-r--r--. 1 root root 38 11月 23 21:16 /etc/centos-release -rw-r--r--. 1 root root 51 11月 23 21:16 /etc/centos-release-upstreamtcp

  2. 查看版本信息 cat /etc/centos-release CentOS Linux release 7.6.1810 (Core)

  3. 查看內核版本 uname -r 3.10.0-957.el7.x86_64

  4. 查看 64位 仍是 32 位 getconf LONG_BIT 64

十二、 關閉 SELinux

查看 SELinux sestatus SELinux status: disabled getenforce Disabled

臨時關閉 setenforce 0

永久關閉 sudo vim /etc/selinux/config # by wzh 20190329 disable SELINUX SELINUX=disabled # SELINUX=enforcing

重啓才能生效!

查看 SELinux sestatus SELinux status: disabled

1三、 終端顯示bash-4.2$ 不顯示用戶名和主機名

參考 http://www.javashuo.com/article/p-ymojgcau-kt.html cp -a /etc/skel/. /home/登陸名

個人登陸帳戶是 dhbm,因此

cp -a /etc/skel/. /home/dhbm 退出後,從新打開一個 Terminal,再進來就 ok!

14 、防火牆操做

  1. 查看防火牆狀態 sudo systemctl status firewalld

    sudo firewall-cmd --state running

  2. 防火牆基本命令 # 開啓 service firewalld start # 重啓 service firewalld restart # 關閉 sudo service firewalld stop # 查看防火牆規則 sudo firewall-cmd --list-all sudo firewall-cmd --state

  3. 開啓 8080 端口 sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent

    重啓防火牆 sudo systemctl restart firewalld.service

    sudo firewall-cmd --reload

  4. 不知道爲何,就把本身關在外面了 ssh 鏈接不上去了! sudo firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: ssh dhcpv6-client ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:

    ** 能夠看到,ports 一個都沒有!
    ** 乾脆從新增長端口的時候,先加上 20,22 端口

    sudo firewall-cmd --zone=public --add-port=80/tcp --permanent sudo firewall-cmd --zone=public --add-port=22/tcp --permanent sudo firewall-cmd --zone=public --add-port=21/tcp --permanent sudo firewall-cmd --zone=public --add-port=20/tcp --permanent sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent sudo firewall-cmd --zone=public --add-port=4433/tcp --permanent

    重啓防火牆 sudo systemctl restart firewalld.service 從新查看防火牆規則 sudo firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: ssh dhcpv6-client ports: 80/tcp 22/tcp 21/tcp 20/tcp 8080/tcp 4433/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: ** 如今能夠安全的退出、從新 ssh 了

相關文章
相關標籤/搜索