本文基于 VirtualBox 5.2.16、CentOS 6.10(CentOS-6.10-x86_64-minimal.iso)编写。
下载
- VirtualBox 下载地址:https://www.virtualbox.org/wiki/Downloads
- CentOS 下载地址:https://www.centos.org/download/
安装
略。
网络配置
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 信息(IPADDR
、NETMASK
、GATEWAY
),并重启 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 ~]#
软件安装
-
安装 EPEL 扩展源
[root@localhost download]# yum install epel-release
-
安装 wget 工具
[root@localhost download]# yum install wget
-
安装 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)
-
安装 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。 -
安装 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
-
安装 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
-
安装 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
这个目录中存放着在不断扩充着的东西,我们习惯将那些经常被修改的目录放在这个目录下。包括各种日志文件。