# Linux 配置
# 一、Centos 常用设置
# 1.安装必要的软件
yum install -y perl lrzsz wget zsh git ebtables socat ipset conntrack yum-utils nfs-utils net-tools.x86_64 telnet gcc epel-release
1
# 2.处理乱码问题
[root@hdp1 ~]# vi /etc/environment
LANG="zh_CN.UTF-8"
LC_ALL="zh_CN.UTF-8"
1
2
3
2
3
# 3.免密登录
ssh-copy-id root@master01
1
# 4.zsh
# 5.设置hostname
hostnamectl set-hostname centos7base
1
# 6.关闭selinux
# 查看Selinux状态
getenforce
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
1
2
3
4
5
6
2
3
4
5
6
# 7.关闭swap
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
#sed -i 's$/dev/mapper/centos-swap$#/dev/mapper/centos-swap$g' /etc/fstab 同上
#echo "vm.swappiness=0" >> /etc/sysctl.conf
#sysctl -p /etc/sysctl.conf
1
2
3
4
5
2
3
4
5
# 8.关闭防火墙
# 查看防火墙状态
firewall-cmd --state
# 停止firewall
systemctl stop firewalld.service
# 禁止firewall开机启动
systemctl disable firewalld.service
# 新增开放端口
firewall-cmd --zone=public --add-port=端口号/tcp --permanent
# 移除开放端口
firewall-cmd --zone=public --remove-port=端口号/tcp --permanent
# 查看开放的端口
firewall-cmd --zone=public --list-ports
# 刷新防火墙
firewall-cmd --reload
#允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 9.时间同步
# 安装chrony
yum -y install chrony
# 修改同步服务器地址为阿里云
sed -i.bak '3,6d' /etc/chrony.conf && sed -i '3cserver ntp1.aliyun.com iburst' \
/etc/chrony.conf
# 启动chronyd及加入开机自启
systemctl start chronyd && systemctl enable chronyd
# 查看同步结果
chronyc sources
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 10 集群时间同步(不连外网状态下)
注意先调整好所有机器的时区
# 方法1
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 方法2
timedatectl list-timezones
sudo timedatectl set-timezone Asia/Shanghai
1
2
3
4
5
6
2
3
4
5
6
# master01 操作步骤
- 查看所有节点ntpd 服务状态和开机自启动状态
systemctl status ntpd
sudo systemctl start ntpd
sudo systemctl is-enabled ntpd
1
2
3
2
3
- 修改master01的
/etc/ntp.conf
配置文件
修改前
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
修改后
# 授权192.168.235.0 - 192.168.235.255 网段上的所有机器可以从这台机器上查询和同步时间
192.168.235.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 不用外网时间
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
# 添加属性 当该节点丢失网络连接,依然可以雌蛾用本地时间作为时间服务器为群集中的其他节点提供时间同步
server 127.127.1.0
fudge 127.127.1.0 stratum 10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- 修改mater01的
/etc/sysconfig/ntpd
文件
增加如下内容(让硬件时间与系统时间一起同步)
SYNC HWCLOCK=yes
1
- 重启启动ntpd服务
sudo systemctl start ntpd
sudo systemctl enable ntpd
1
2
2
# 其他节点操作步骤
- 关闭所有节点上的ntp服务和自启动
sudo systemctl stop ntpd
sudo systemctl disable ntpd
1
2
2
- 配置间隔1分钟与时间服务器同步一次
[tpxcer@slave01 hadoop-3.3.1]$ sudo crontab -e
*/1 * * * * /usr/sbin/ntpdate master01 >/dev/null 2>&1
1
2
2
- 测试一下
# 修改master01的时间
sudo date -s "2021-09-01 11:11:11"
# 1分钟后查看其他机器是否与时间服务器同步
date
1
2
3
4
5
2
3
4
5
# 11.同步执行命令脚本xcall
可以放在 /usr/local/bin
下
#!/bin/bash
# 获取控制台指令
cmd=$*
# 判断指令是否为空
if [ $# -eq 0 ];
then
echo "command can not be null !"
exit
fi
# 获取当前登录用户
user=`whoami`
# 在从机执行指令,这里需要根据你具体的集群情况配置,host与具体主机名一致
for host in ks.m1 ks.m2 ks.m3 ks.s1
do
echo "================current host is $host================="
echo "--> excute command \"$cmd\""
ssh $user@$host $cmd
done
echo "excute successfully !"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 12.同步复制文件脚本xsync
可以放在 /usr/local/bin
下
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]; then
echo "Not Enough Arguement!"
exit;
fi
#2. 遍历集群所有机器
for host in slave01 slave02 slave03
#for host in slave01
do
echo ==================== $host ====================
#3. 遍历所有目录,挨个发送
for file in $@
do
#4. 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exists!
fi
done
done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 13.安装JDK
# 卸载已安装的JDK
rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
1
# 安装JDK
从Oracle官方 (opens new window) 下载JDK然后解压到目录
tar -zxvf ~/jdk-8u301-linux-x64.tar.gz
1
# 配置JDK变量
创建新的变量文件,放到/etc/profile.d
中
cd /etc/profile.d
vim my_env.sh
source /etc/profile
1
2
3
2
3
文件内容
#JAVA_HOME
export JAVA_HOME=/opt/jdk1.8.0_311
export PATH=$PATH:$JAVA_HOME/bin
1
2
3
2
3
# 14 设置静态ip
修改/etc/sysconfig/network-scripts/ifcfg-ens33
,将网络改为静态ip
这里的ens33根据设备不同编号也不同
原内容:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
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="ens33"
UUID="47eb256e-1189-4dcb-b28b-cefb7dd76c18"
DEVICE="ens33"
ONBOOT="yes"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
修改后:
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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=ens33
UUID=47eb256e-1189-4dcb-b28b-cefb7dd76c18
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.235.5
PREFIX=24
GATEWAY=192.168.235.1
DNS1=192.168.235.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 15. nfs服务
1.安装nfs-server
# 在每个机器。
yum install -y nfs-utils
# 在master 执行以下命令
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports
# 执行以下命令,启动 nfs 服务;创建共享目录
mkdir -p /nfs/data
# 在master执行
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
# 使配置生效
exportfs -r
#检查配置是否生效
exportfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2.配置nfs-client(选做,所有节点)
showmount -e 192.168.50.3
mkdir -p /nfs/data
mount -t nfs 192.168.50.3:/mnt/Apps/k8s-data /nfs/data
# 开机自动挂载,编辑/etc/fstab
192.168.50.3:/mnt/Apps/zk-hdp1 /opt/apache-zookeeper/zkData nfs rw
1
2
3
4
5
6
2
3
4
5
6
# 16. 配置用户sudo权限
编辑/etc/sudoers
把用户tpxcer
加入sudo
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
## Same thing without a password
tpxcer ALL=(ALL) NOPASSWD: ALL
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 17. 安装dnf
yum install epel-release
yum install dnf
dnf install 'dnf-command(config-manager)'
1
2
3
2
3
# 二、Ubuntu 常用设置
# 1.中文支持
# 编码配置
dpkg-reconfigure locales
# 设置LC_ALL变量
export LC_ALL="en_US.UTF-8"
1
2
3
4
5
2
3
4
5
# 2.Mirror
# 3.SSH
sudo apt install openssh-server
sudo systemctl status ssh
1
2
2
export http_proxy=http://192.168.50.216:1087;export https_proxy=http://192.168.50.216:1087;export ALL_PROXY=socks5://192.168.50.216:1080
# 三、Debian 常用设置
# 3.1 增加sudo用户
编辑/etc/sudoers
user ALL=(ALL:ALL) ALL
1
# 3.2 把DVD源去掉
sudo vi /etc/apt/sources.list
1
# 3.3 终端显示中文
export LC_ALL=zh_CN.utf-8
dpkg-reconfigure locales
1
2
2
# 3.4 NFS(客户端)
apt-cache search showmount
apt-get install nfs-common
1
2
2
# 3.5 去掉安装系统时候使用的代理
编辑文件/etc/apt/apt.conf
,删除代理
Acquire::http::Proxy "http://192.168.50.216:1087";
1
# 四、通用配置
# 重新配置默认Java版本
update-alternatives --config java
1
# 禁Ping
修改/etc/sysctl.conf加一行
net.ipv4.icmp_echo_ignore_all = 1
1
执行sysctl -p
加载配置后生效。
临时启用Ping
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all
1
# 禁止IP
iptables -I INPUT -s 124.115.0.199 -j DROP
/etc/rc.d/init.d/iptables save
service iptables restart
1
2
3
2
3
# 修改DNS
vim /etc/resolv.conf
1
# 在PATH中添加一条新路径
export PATH="$PATH:/home/user/bin"
1
# 删除用户
# r 用于彻底删除,用户HOME目录下的档案会被移除,在其他位置上的档案也将一一找出并删除,比如路径/var/mail/用户名下的邮件。
userdel -r ubuntu
1
2
2
# 格式化硬盘
fdisk -l
fdisk /dev/sdc
mkfs.ext4 /dev/sdc
mkdir /mnt/M06
mount /dev/sdc /mnt/M06
df -h
1
2
3
4
5
6
2
3
4
5
6