VirtualBox 安装 CentOS 6 全记录

本文基于 VirtualBox 5.2.16、CentOS 6.10(CentOS-6.10-x86_64-minimal.iso)编写。

下载

安装

略。

网络配置

VirtualBox 配置

VirtualBox 网络配置页面
  • 连接方式:选择【桥接网卡】,此时 CentOS 相当于一台新的电脑直接接入局域网
  • 界面名称:选择当前电脑连接网络使用的网卡

CentOS 配置

修改 /etc/sysconfig/network-scripts/ifcfg-eth0 配置文件,将 ONBOOT=no 改为 ONBOOT=yes,并重启 network 服务:

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
HWADDR=此处为马赛克
TYPE=Ethernet
UUID=9e8e00ed-1dfd-4eb7-bd83-468500b29f4e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
[root@localhost ~]# service network restart
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0: 
正在决定 eth0 的 IP 信息...完成。
                                                           [确定]

如需配置静态 IP 地址,修改 /etc/sysconfig/network-scripts/ifcfg-eth0 配置文件,将 BOOTPROTO=dhcp 改为 BOOTPROTO=static,添加静态 IP 信息(IPADDRNETMASKGATEWAY),并重启 network 服务:

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
HWADDR=此处为马赛克
TYPE=Ethernet
UUID=9e8e00ed-1dfd-4eb7-bd83-468500b29f4e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.233
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1

测试网络

使用 ifconfig -a 命令查询 CentOS 的 IP 地址,使用 ping 命令测试是否可以访问互联网:

[root@localhost ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 此处为马赛克
          inet addr:192.168.1.233  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: 此处为马赛克 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:893 errors:0 dropped:0 overruns:0 frame:0
          TX packets:565 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:85898 (83.8 KiB)  TX bytes:88679 (86.6 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@localhost ~]# ping www.baidu.com
PING www.baidu.com (180.97.33.108) 56(84) bytes of data.
64 bytes from 180.97.33.108: icmp_seq=1 ttl=52 time=4.12 ms
64 bytes from 180.97.33.108: icmp_seq=2 ttl=52 time=6.76 ms
64 bytes from 180.97.33.108: icmp_seq=3 ttl=52 time=13.2 ms
64 bytes from 180.97.33.108: icmp_seq=4 ttl=52 time=13.1 ms
^C
--- www.baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3172ms
rtt min/avg/max/mdev = 4.128/9.341/13.277/4.006 ms

在本机使用 ssh 命令连接 CentOS:

[C:\~]$ ssh root@192.168.1.32


Connecting to 192.168.1.32:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Fri Jul 27 15:24:00 2018 from 192.168.1.14
[root@localhost ~]# 

软件安装

  1. 安装 EPEL 扩展源

    [root@localhost download]# yum install epel-release
    
  2. 安装 wget 工具

    [root@localhost download]# yum install wget
    
  3. 安装 JDK 8

    [root@localhost download]# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.rpm
    [root@localhost download]# ll
    总用量 166040
    -rw-r--r--. 1 root root 170023183 7月   9 10:05 jdk-8u181-linux-x64.rpm
    [root@localhost download]# rpm -ivh jdk-8u181-linux-x64.rpm 
    warning: jdk-8u181-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
    Preparing...                ########################################### [100%]
       1:jdk1.8                 ########################################### [100%]
    Unpacking JAR files...
        tools.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...
    [root@localhost download]# java -version
    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
    
  4. 安装 MySQL 5.7

    MySQL 最新版本为 8.0,使用 yum 安装时,可以使用 yum-config-manager 设置激活版本号。

    [root@localhost download]# wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
    [root@localhost download]# rpm -ivh mysql80-community-release-el6-1.noarch.rpm 
    [root@localhost download]# yum repolist all | grep mysql
    mysql-cluster-7.5-community        MySQL Cluster 7.5 Community       禁用
    mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - Sou 禁用
    mysql-cluster-7.6-community        MySQL Cluster 7.6 Community       禁用
    mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - Sou 禁用
    mysql-connectors-community         MySQL Connectors Community        启用:    59
    mysql-connectors-community-source  MySQL Connectors Community - Sour 禁用
    mysql-tools-community              MySQL Tools Community             启用:    65
    mysql-tools-community-source       MySQL Tools Community - Source    禁用
    mysql-tools-preview                MySQL Tools Preview               禁用
    mysql-tools-preview-source         MySQL Tools Preview - Source      禁用
    mysql55-community                  MySQL 5.5 Community Server        禁用
    mysql55-community-source           MySQL 5.5 Community Server - Sour 禁用
    mysql56-community                  MySQL 5.6 Community Server        禁用
    mysql56-community-source           MySQL 5.6 Community Server - Sour 禁用
    mysql57-community                  MySQL 5.7 Community Server        禁用
    mysql57-community-source           MySQL 5.7 Community Server - Sour 禁用
    mysql80-community                  MySQL 8.0 Community Server        启用:    29
    mysql80-community-source           MySQL 8.0 Community Server - Sour 禁用
    [root@localhost download]# yum install yum-utils
    [root@localhost download]# yum-config-manager --disable mysql80-community
    [root@localhost download]# yum-config-manager --enable mysql57-community
    [root@localhost download]# yum install mysql-community-server
    [root@localhost download]# service mysqld status
    mysqld 已停
    [root@localhost download]# service mysqld start
    正在启动 mysqld:                                          [确定]
    [root@localhost download]# grep 'temporary password' /var/log/mysqld.log
    2018-07-27T17:05:25.224648Z 1 [Note] A temporary password is generated for root@localhost: 5y>Xwt&dr%qM
    [root@localhost download]# mysql -uroot -p5y>Xwt&dr%qM
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 5
    Server version: 5.7.23 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> CREATE USER 'user'@'%' IDENTIFIED BY 'MyNewPass4!';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> quit
    Bye
    [root@localhost download]# vi /etc/sysconfig/iptables
    [root@localhost download]# cat /etc/sysconfig/iptables
    # Firewall configuration written by system-config-firewall
    # Manual customization of this file is not recommended.
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT [0:0]
    :OUTPUT ACCEPT [0:0]
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    -A INPUT -p icmp -j ACCEPT
    -A INPUT -i lo -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    -A INPUT -m state --state NEW,ESTABLISHED -m tcp -p tcp --dport 3306 -j ACCEPT
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    COMMIT
    [root@localhost download]# service iptables restart
    iptables:将链设置为政策 ACCEPT:filter                    [确定]
    iptables:清除防火墙规则:                                 [确定]
    iptables:正在卸载模块:                                   [确定]
    iptables:应用防火墙规则:                                 [确定]
    

    此时,便可以通过局域网,使用 3306 端口、用户名 user、密码 MyNewPass4! 连接该 MySQL。

  5. 安装 Redis 4.0

    [root@localhost download]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz
    [root@localhost download]# cd /opt
    [root@localhost opt]# tar -xzf /home/download/redis-4.0.10.tar.gz
    [root@localhost opt]# cd redis-4.0.10/
    [root@localhost redis-4.0.10]# yum install gcc
    [root@localhost redis-4.0.10]# make
    [root@localhost redis-4.0.10]# yum install tcl
    [root@localhost redis-4.0.10]# make test
    [root@localhost redis-4.0.10]# make install
    [root@localhost redis-4.0.10]# make clean
    [root@localhost redis-4.0.10]# mkdir /var/lib/redis
    [root@localhost redis-4.0.10]# cp redis.conf /etc/redis.conf
    [root@localhost redis-4.0.10]# vi /etc/redis.conf
    

    修改如下配置信息:

    # 开启守护线程模式
    daemonize yes
    # 指定生成的日志文件
    logfile /var/log/redis.log
    # 指定持久化数据保存目录
    dir /var/lib/redis
    
    [root@localhost redis-4.0.10]# cp utils/redis_init_script /etc/init.d/redis
    [root@localhost redis-4.0.10]# vi /etc/init.d/redis
    

    修改如下配置信息:

    # 指定Redis配置文件位置
    CONF="/etc/redis.conf"
    

    现在就可以使用 service 命令启动、关闭 Redis 服务器:

    [root@localhost redis-4.0.10]# service redis start
    Starting Redis server...
    [root@localhost redis-4.0.10]# service redis stop
    Stopping ...
    Waiting for Redis to shutdown ...
    Redis stopped
    

    设置开机自启:

    [root@localhost redis-4.0.10]# chkconfig --add redis
    

    跟踪日志:

    [root@localhost redis-4.0.10]# tailf /var/log/redis.log
    
  6. 安装 RabbitMQ 3.7

    [root@localhost download]# wget https://github.com/rabbitmq/erlang-rpm/releases/download/v20.3.8.4/erlang-20.3.8.4-1.el6.x86_64.rpm
    [root@localhost download]# yum install erlang-20.3.8.4-1.el6.x86_64.rpm
    [root@localhost download]# wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.7/rabbitmq-server-3.7.7-1.el6.noarch.rpm
    [root@localhost download]# yum install rabbitmq-server-3.7.7-1.el6.noarch.rpm
    [root@localhost download]# service rabbitmq-server start
    

    查看日志:

    [root@localhost download]# more /var/log/rabbitmq/rabbit\@localhost.log 
    
  7. 安装 ZooKeeper

    [root@localhost download]# wget http://mirrors.shu.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz
    [root@localhost download]# cd /opt
    [root@localhost opt]# tar -xzf /home/download/zookeeper-3.4.12.tar.gz
    [root@localhost opt]# cd zookeeper-3.4.12
    [root@localhost zookeeper-3.4.12]# cp conf/zoo_sample.cfg conf/zoo.cfg
    [root@localhost zookeeper-3.4.12]# vi conf/zoo.cfg
    

    修改 dataDir,并增加 dataLogDir 配置:

    dataDir=/var/lib/zookeeper
    dataLogDir=/var/log/zookeeper
    
    [root@localhost zookeeper-3.4.12]# cd /etc/init.d
    [root@localhost init.d]# touch zookeeper
    [root@localhost init.d]# chmod +x zookeeper
    [root@localhost init.d]# vi zookeeper
    

    增加如下配置信息:

    #!/bin/sh
    
    # Purpose: This script starts and stops the Zookeeper daemon
    # chkconfig: - 90 10
    # description: Zookeeper daemon
    
    ZOO_LOG_DIR=/var/log/zookeeper
    ZOO_LOG4J_PROP=INFO,ROLLINGFILE
    
    export ZOO_LOG_DIR
    export ZOO_LOG4J_PROP
    
    source /etc/profile
    
    cd /opt/zookeeper-3.4.12
    bin/zkServer.sh $1
    
    [root@localhost init.d]# service zookeeper start
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper-3.4.12/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
    [root@localhost init.d]# service zookeeper status
    ZooKeeper JMX enabled by default
    Using config: /opt/zookeeper-3.4.12/bin/../conf/zoo.cfg
    Mode: standalone
    [root@localhost init.d]# chkconfig --add zookeeper
    [root@localhost init.d]# chkconfig zookeeper on
    [root@localhost init.d]# chkconfig|grep zookeeper
    zookeeper       0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
    

附录

CentOS 常用系统目录结构

  • /bin bin 是 Binary 的缩写, 这个目录存放着最经常使用的命令。
  • /etc 这个目录用来存放所有的系统管理所需要的配置文件和子目录。
  • /home 用户的主目录,在 Linux 中,每个用户都有一个自己的目录,一般该目录名是以用户的账号命名的。
  • /opt 这是给主机额外安装软件所摆放的目录。比如你安装一个 ORACLE 数据库则就可以放到这个目录下。默认是空的。
  • /root 该目录为系统管理员,也称作超级权限者的用户主目录。
  • /sbin s 就是 Super User 的意思,这里存放的是系统管理员使用的系统管理程序。
  • /tmp 这个目录是用来存放一些临时文件的。
  • /usr 这是一个非常重要的目录,用户的很多应用程序和文件都放在这个目录下,类似于 windows 下的 program files 目录。
  • /var 这个目录中存放着在不断扩充着的东西,我们习惯将那些经常被修改的目录放在这个目录下。包括各种日志文件。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容