安装CentOS后的基本配置
1、网络配置
1.1 CentOS 6
1) vi /etc/sysconfig/network-scripts/ifcfg-eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.153.136
NETMASK=255.255.255.0
GATEWAY=192.168.153.2(网关在虚拟机网络编辑器->NET设置中可以看到)
DNS1=192.168.153.2
2) service network restart
3) ifconfig,查看IP是否配置好
4) ping www.baidu.com,验证是否可以访问外网
1.2 CentOS 7
1) vi /etc/sysconfig/network-scripts/ifcfg-eno16777728
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.255.136
NETMASK=255.255.255.0
GATEWAY=192.168.255.2
DNS1=192.168.255.2
2) service network restart(新命令:systemctl restart network.service)
3) 最小化安装时,没有ifconfig
4) ping www.baidu.com,验证是否可以访问外网
2、修改主机名
2.1 修改hosts
[root@localhost ~]# vi /etc/hosts
默认值值不要删除,添加一行
192.168.153.136 node1
2.2 修改hostname
[root@localhost ~]# vi /etc/hostname
node1
2.3 重启
[root@localhost ~]#shutdown -r now
查看主机名是否改变
3、更改镜像源
3.1 安装wget
[root@node1 ~]#yum install -y wget
3.2 下载aliyun的repo
[root@node1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.3 更新镜像源
[root@node1 ~]#yum clean all
[root@node1 ~]#yum makecache
3.4 测试
[root@node1 ~]#yum install -y vim
4、关闭防火墙和Selinux
4.1 CentOS6
[root@node1 ~]#chkconfig iptables off
[root@node1 ~]#vi /etc/selinux/config
修改:SELINUX=disabled
4.2 CentOS7
[root@node1 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@node1 ~]# systemctl stop firewalld
[root@node1 ~]# setenforce 0
[root@node1 ~]# vi /etc/selinux/config
SELINUX=disabled
5、SSH无密钥配置
5.1 安装SSH
[root@node1 ~]#yum install -y openssh-clients
5.2 配置无密码登录
[root@cnode1 ~]# ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
Generating public/private dsa key pair.
Created directory '/root/.ssh'.
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
cf:04:68:7d:57:0c:a0:3e:63:31:fa:53:66:72:0c:80 root@cnode1
The key's randomart image is:
+--[ DSA 1024]----+
| .. ...o. |
| E + . .. |
| o B . . |
| . o B . |
| . S B |
| o % |
| o o |
| . |
| |
+-----------------+
[root@cnode1 ~]# cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
将公钥写到远程机器的 ~/ .ssh/authorized_key.文件中
[root@cnode0 ~]# ssh-copy-id -i ~/.ssh/id_dsa.pub vnode0
The authenticity of host 'vnode0 (192.168.1.180)' can't be established.
ECDSA key fingerprint is 3d:7a:15:7e:bc:79:63:33:b9:a9:3d:5b:3c:53:16:78.
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@vnode0's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'vnode0'"
and check to make sure that only the key(s) you wanted were added.
[root@cnode0 ~]# ssh vnode0
Last login: Mon Mar 6 03:15:45 2017 from east81
[root@vnode0 ~]# exit
logout
Connection to vnode0 closed.
[root@cnode0 ~]#
6、安装JDK
6.1 卸载旧的JDK
[root@node1 ~]#rpm -qa|grep jdk
[root@node1 ~]#yum -y remove java java-1.7.0-openjdk-1.7.0.79-2.5.5.4.el6.x86_64
[root@node1 ~]#rpm -qa|grep java
[root@node1 ~]#yum -y remove java tzdata-java-2015e-1.el6.noarch
[root@node1 ~]#rpm -qa|grep gcj
6.2 配置新JDK
[root@node1 ~]# mkdir /opt/java
[root@node1 ~]# tar -zxvf jdk-8u112-linux-x64.tar.gz -C /opt/java
[root@node1 ~]# cd /opt/java/jdk1.8.0_112/
[root@node1 jdk1.8.0_112]# pwd
/opt/java/jdk1.8.0_112
6.3 配置环境变量
[root@node1 ~]#vim /etc/profile
#set Java Path
export JAVA_HOME=/opt/java/jdk1.8.0_101
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
[root@node1 ~]# source /etc/profile
[root@node1 ~]# java -version
重启,再次运行 java -version,检测Java环境变量是否配置好?
6.4 可能存在的问题
针对CentOS7,在 /etc/profile配置全局环境变量可能会失效,一个解决的办法就是在 /etc/bashrc中配置
[root@node1 ~]# source /etc/bashrc
#set java path
export JAVA_HOME=/opt/jdk1.8.0_112
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
[root@node1 ~]# vi /etc/bashrc
[root@node1 ~]# java -version
以下为按照ambari做准备
7、安装ntp
[root@cnode1 ~]# yum install -y ntp
[root@cnode1 ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@cnode1 ~]# systemctl start ntpd
[root@cnode1 ~]# echo umask 0022 >> /etc/profile