一:机器分区及挂载mount点
对新机器分区,及挂载mount点:新机器分区中有很大空间未分配,可以用来做存储:
/dev/vda大小为161.1 GB,已有分区/dev/vda1大小是8G,剩余152G未分区,进行分区,且挂载到新建mount点/data上。
1、[root@host-10-20-16-27 /]# fdisk -l
Disk /dev/vda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b2f10
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 16777215 8387584 83 Linux
2、分区:/dev/vda盘是161G,/dev/vda1大小是8G,把剩余的空间分给一个新区的操作如下:
把/dev/vda剩下的盘进行分区,执行fdisk /dev/vda,然后执行n是新增一个分区,点p,如果剩余存储都给该分区,则后面就enter即可,最后w写入;
[root@host-10-20-16-27 /]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (16777216-314572799, default 16777216):
Using default value 16777216
Last sector, +sectors or +size{K,M,G} (16777216-314572799, default 314572799):
Using default value 314572799
Partition 2 of type Linux and of size 142 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
分区成功:
[root@host-10-20-16-27 /]# fdisk -l
Disk /dev/vda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b2f10
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 16777215 8387584 83 Linux
/dev/vda2 16777216 314572799 148897792 83 Linux
3、
遇到的问题:格式化新的分区时,有下面的报错:
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 16777215 8387584 83 Linux
/dev/vda2 16777216 314572799 148897792 83 Linux
[root@host-10-20-16-28 /]# mkfs -t ext4 /dev/vda2
mke2fs 1.42.9 (28-Dec-2013)
Could not stat /dev/vda2 --- No such file or directory
The device apparently does not exist; did you specify it correctly?
其实该磁盘是有的,可是报错不存在:
解决方法:
执行下partprobe 命令
查看是否安装该命令:
[root@db1 dev]# rpm -q parted
parted-1.8.1-23.el5
然后直接执行:
partprobe,下面再执行下格式化就OK了:
mkfs -t ext4 /dev/vda2
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
9306112 inodes, 37224448 blocks
1861222 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2185232384
1136 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
/etc/fstab文件中写入要挂载的信息:
mount点是/data
/dev/vda2 /data ext4 defaults 0 0
执行mount -a
然后查看下面就有该mount点了:
[root@host-10-20-16-28 /]# df -h |grep data
/dev/vda2 140G 61M 133G 1% /data
其中问题解决方法的相关链接是https://blog.youkuaiyun.com/zhangdaiscott/article/details/50057155
二:设置时间
tzselect命令:
执行tzselect命令-->选择Asia-->选择China-->选择east China - Beijing, Guangdong, Shanghai, etc-->然后输入1。
最后执行:
TZ='Asia/Shanghai';export TZ
修改配置文件来修改时区
1、修改/etc/sysconfig/clock ZONE=Asia/Shanghai
2、rm /etc/localtime
3、链接到上海时区文件
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
执行完上述过程后,重启机器,即可看到时区已经更改。
三:小操作:
设置sudo权限
为用户配置sudo权限
(现场如果未提供用户信息:新建用户、用户组、设置密码的方法:
groupadd --gid 1000 yunwei
useradd --uid 1000 yunwei -g yunwei
passwd yunwei 密码是yunwei)
例如现场提供的可操作用户为yunwei,给该用户添加sudo权限的方法:
/etc/sudoers中新增:
在## Allow root to run any commands anywhere下添加:
yunwei ALL=(ALL) ALL
在# %wheel ALL=(ALL) NOPASSWD: ALL下添加:
%yunwei ALL=(ALL) NOPASSWD: ALL (普通用户执行命令时不需要输入密码)
重新打开一个客户端,su yunwei后,执行sudo不必输入密码即可;
su root 与su - root是不一样的
su只是切换了root身份,但Shell环境仍然是普通用户的Shell;而su -连用户和Shell环境一起切换成root身份了。只有切换了Shell环境才不会出现PATH环境变量错误,报command not found的错误。
更改hostname
/etc/hostname 和/etc/sysconfig/network下的HOSTNAME变量 ,然后reboot,则可以永久生效
配置NTP服务:服务器和client
集群中的机器需要保持时间同步,否则会造成hbase和ganglia等服务的异常,安装系统时配置。
举例:
ntp的配置,如果182,183,184机器的时间需要和181的时间同步,那么在181开启ntpd服务,并且在181的/etc/ntp.conf中增加下面两句
yum install ntp
服务端添加:
server 127.127.1.0
fudge 127.127.1.0 stratum 8
客户端添加:
server ${服务端IP}
启动:
1、mask ntpd
2、systemctl restart ntpd
在ntp服务器查看ntp配置是否正常:
ntpq -p
在集群中除了ntp服务器以外的主机,执行命令和ntp服务器时间进行同步
ntpdate${ntp-server IP}
增加定时任务crontab -e[zl1]
0 8 * * * ntpdate ${ntp-server IP}; hwclock -w
[zl1]写入时间后,然后执行hwclock –w
主机内可以ssh无密码登录:
常见登录验证方式如下:
更改文件:/etc/ssh/sshd_config中下面的参数:
Passwordauthentication yes //启用密码验证
Pubkeyauthentication yes //启用秘钥验证
Authorsizedkeysfile .ssh/authorized_keys //指定公钥数据库文件
在集群每台服务器上执行
cd /root/.ssh/
ssh-keygen -t rsa 生成私钥和公钥
然后把生成的公钥 id_rsa.pub都拷贝到其他机器的authorized_keys中,其他机器的公钥也要拷贝到本台机器的authorized_keys中;
cat id_rsa.pub >authorized_keys
chmod 600 authorized_keys
对于安全加固的环境,端口不是22,则登录时,指定端口登录即可:
ssh -p22022 dcp27
20190428总结:统一删除目录的命令
只列出来本路径下的目录的命令:
ls -F |grep '/$'
[root@187 practice]# ls -F |grep '/$'
df1/
df2/
df3/
删除本路径下的所有目录的命令:
rm -rf `ls -F |grep '/$' |awk -F '/' '{print $1}'`
20190509用sed替换变量
直接替换整行的变量:
sed -i "s/isee.stream.kafka.brokers=192.168.1.6:19292/isee.stream.kafka.brokers=$kafka_ip:$kafka_port/g" filename
注意,不能是单引号,单引号下变量无法被解析出来;
替换filename中zookeeper.connect行里的任意IP为$zookeeper_ip
sed -r -i "/zookeeper.connect/s/[1-9]{1,3}(.[0-9]{1,3}){3}/$zookeeper_ip/g" filename