ssh保持长连接的方式

方法有以下三种:

1.修改server端的etc/ssh/sshd_config

ClientAliveInterval 60 #server每隔60秒发送一次请求给client,然后client响应,从而保持连接
ClientAliveCountMax 3 #server发出请求后,客户端没有响应得次数达到3,就自动断开连接,正常情况下,client不会不响应

systemctl reload sshd

2.修改client端的etc/ssh/ssh_config添加以下:(在没有权限改server配置的情形下)

ServerAliveInterval 60 #client每隔60秒发送一次请求给server,然后server响应,从而保持连接
ServerAliveCountMax 3 #client发出请求后,服务器端没有响应得次数达到3,就自动断开连接,正常情况下,server不会不响应

3.在命令参数里ssh -o ServerAliveInterval=60 这样子只会在需要的连接中保持持久连接, 毕竟不是所有连接都要保持持久的

来自:https://www.cnblogs.com/bignode/p/9249893.html

CentOS 创建RAID5 并加入 LVM

安装mdadm
yum install -y mdadm

查看磁盘
fdisk -l

磁盘分区
这里需要注意下,分区格式更改为Raid5类型的,为fd类型
[root@localhost ~]# fdisk /dev/sdb
请按照下面的说明在 /dev/sdc 硬盘上创建分区。
按 n 创建新的分区。
然后按 P 选择主分区。选择主分区是因为还没有定义过分区。
接下来选择分区号为1。默认就是1。
这里是选择柱面大小,我们没必要选择指定的大小,因为我们需要为 RAID 使用整个分区,所以只需按两次 Enter 键默认将整个容量分配给它。
然后,按 P 来打印创建好的分区。
改变分区类型,按 L可以列出所有可用的类型。
按 t 修改分区类型。
这里使用fd设置为 RAID 的类型。
然后再次使用p查看我们所做的更改。
使用w保存更改。

创建Raid分区
mdadm --create --auto=yes /dev/md0 --level=5 --raid-devices=3 --spare-devices=1 /dev/sd[b-e]
可以缩写为
mdadm -C /dev/md0 -l5 –n3 -x1 /dev/sd[b-e]

参数解释

--create
表示要创建raid
--auto=yes /dev/md0
新建立的软件磁盘陈列设备为md0,md序号可以为0-9
--level=5
磁盘阵列的等级,这里是RAID5
--raid-devices=5
用于构建RAID的磁盘的个数
--spare-devices=1
添加作为预备(spare)磁盘的个数
/dev/sd[b-e]
磁盘阵列所使用的设备,还可以写成: /dev/sdb /dev/sdc /dev/sdd /dev/sde

创建Raid分区
mkfs.ext4 /dev/md0

查看磁盘阵列详情
mdadm -D /dev/md0

创建磁盘阵列配置
echo DEVICE /dev/sd[b-e]>> /etc/mdadm.conf
mdadm --detail --scan >> /etc/mdadm.conf
该配置文件的主要作用是系统启动的时候能够自动加载软RAID,同时也方便日后管理。但不是必须的,推荐对该文件进行配置。
我们这里需要创建这个文件,测试中发现,如果没有这个文件,则reboot 后,已经创建好的md0 会自动变成md127。

Raid测试[非必要步骤]
mdadm /dev/md0 -f /dev/sdb # 在之前创建的md0中分区/dev/sdb出现故障
cat /proc/mdstat . # 查看重构过程
mdadm /dev/md0 -r /dev/sdb # 删除出现问题的磁盘
mdadm /dev/md0 -a /dev/sdb # 添加磁盘会成为热备盘,让热备盘转变为活动磁盘需要执行命令:mdadm -G /dev/md0 -n4 将序号为4的热备盘转转变为活动磁盘

加入LVM

vgextend centos /dev/md0 # 将创建的RAID分区加入卷组centos, 可使用vgs(简洁)或vgdisplay(详细)查看卷组情况
lvextend -L +80G /dev/centos/home # 扩容home逻辑分区, 可使用lvs(简洁)或lvdisplay(详细)查看逻辑分区情况
lvresize -l +100%FREE /dev/centos/root # 将剩余容量全部分配给逻辑分区root

cat /etc/fstab # 查看分区表,确定当前分区格式,如果是fs格式文件系统,则使用resize2fs,如果是xfs,使用xfs_growfs扩容文件系统

如果是fs格式

resize2fs /dev/centos/home
resize2fs /dev/centos/root

如果是xfs格式

xfs_growfs /dev/centos/root
xfs_growfs /dev/centos/home
df -h # 查看文件系统容量

【转】Increase Open File Limit Tomcat CentOS 7

转自:https://www.malasuk.com/linux/increase-open-file-limit-tomcat-centos-7/

Recently I ran into an issue where Tomcat hit an open file limit on a CentOS 7 server. I found documentation on raising the limit lacking when I googled. Historically in initrd systems you could increase the limits for the tomcat user in /etc/security/limits.conf, however with systemd the process has changed.

First you can see your open file limit based on the running process

[root@server ~]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/tomcat.service.d
└─limits.conf
Active: active (running) since Sat 2018-10-20 20:44:27 UTC; 4s ago
Main PID: 19577 (java)
CGroup: /system.slice/tomcat.service
└─19577 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat ...

[root@server ~]# cat /proc/19577/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 3878 3878 processes
Max open files 4096 4096 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 3878 3878 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
In this case we wanted to double the open file limit for the tomcat process. Since we are running a systemd based system, we needed to increase the open file limit in the unit file for the service.

We don't want our change to be overridden when Tomcat updates, so we will add the option in /etc/systemd rather than the default unit file in /usr/lib/systemd/system/tomcat.service

The following steps will add a new unit file for us to increase the open file limit

[root@server ~]# mkdir -p /etc/systemd/system/tomcat.service.d/
[root@server ~]# vim /etc/systemd/system/tomcat.service.d/limits.conf
[Service]
LimitNOFILE=8192
Once we increase the limit, reload systemctl to apply the change

[root@server ~]# systemctl daemon-reload
Now the last step is to restart Tomcat to apply the new change.

[root@server ~]# systemctl restart tomcat
Now lets check and validate the new open file limit

[root@server ~]# systemctl status tomcat
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/usr/lib/systemd/system/tomcat.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/tomcat.service.d
└─limits.conf
Active: active (running) since Sat 2018-10-20 20:50:54 UTC; 25s ago
Main PID: 19900 (java)
CGroup: /system.slice/tomcat.service
└─19900 /usr/lib/jvm/jre/bin/java -classpath /usr/share/tomcat/bin/bootstrap.jar:/usr/share/tomcat/bin/tomcat-juli.jar:/usr/share/java/commons-daemon.jar -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomcat ...

[root@server ~]# cat /proc/19900/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 3878 3878 processes
Max open files 8192 8192 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 3878 3878 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
And thats it! This is the same process as raising the open file limit for MySQL/MariaDB on CentOS 7.