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.

[转] Gitlab库已损坏前端显示500错误解决方法:remote: fatal: loose object xxx is corrupt

转自: https://johng.cn/gitlab-object-corrupt/

  1. $ cd gitlab/repositories//.git

  2. $ git fsck
    If any error like below
    error: object file objects/11/fbf0dfb1a54283e84044b5e99230efbafd77d8 is empty
    error: object file objects/11/fbf0dfb1a54283e84044b5e99230efbafd77d8 is empty
    fatal: loose object 11fbf0dfb1a54283e84044b5e99230efbafd77d8 (stored in objects/11/fbf0dfb1a54283e84044b5e99230efbafd77d8) is corrupt

  3. $ find . -size 0 -delete
    This will delete all files which has 0 byte size and corrupt

  4. $ git fsck
    Checking object directories: 100% (256/256), done.
    Checking objects: 100% (4970/4970), done.
    error: HEAD: not a commit
    error: refs/heads/master: not a commit
    dangling commit de516dd3d99d13147b6e2f946fe5b8c0660e4eed

  5. Try to push code from local without add and commit
    $ git push origin
    If got below error
    remote: error: Could not read 5329f756010fad47026f112dc7126bdaa2f9ad7f
    remote: fatal: Failed to traverse parents of commit 8eecd866caa916a3b2e8550153f0bb5a54a28919
    remote: aborting due to possible repository corruption on the remote side.
    fatal: protocol error: bad pack header

  6. Go to cd gitlab/repositories//.git
    $ rm -fr ref/head/
    $ git fsck
    notice: HEAD points to an unborn branch (master)
    Checking object directories: 100% (256/256), done.
    notice: No default references
    dangling commit eb84ebc9010ea3d3d5646b4eab1bacd358178fbd

  7. Try to push code from local without add and commit
    $ git push origin

Done your code updated successfully !!!

Centos 7 LVM xfs文件系统修复【转】

来自:https://blog.csdn.net/qq_35161159/article/details/86471859

情况1:

[sda] Assuming drive cache: write through

Internal error xfs XFS_WANT_CORRUPTED_GOTO at line 1662 of file fs/xfs/libxfs/xfs_alloc.c Caller xfs_free_extent+0x130 [xfs]

Internal error xfs_trans_cancel at line 990 of file fs/xfs/xfs_trans.c.Caller xlog_recover_process_efi +0x16b/0x190 [xfs]

Corruption of in-memory data detected. Shutting down filesystem

Please umount the filesystem and rectify the problem(s)

Failed to recover EFIs

 

Generating "/run/initramfs/rdsosreport.txt"

如果是LVM管理分区的

  1. ls -l /dev/mapper

2.xfs_repair /dev/mapper/centos-root

3.xfs_repair -L /dev/mapper/centos-root

4.重启: init 6 

 

 

情况2:

[sda] Assuming drive cache: write through

Metadata corruption detected at xfs_agi_read_verify+0x5e/0x110 [xfs], xfs_agi block 0x2

Unmount and run xfs_repair

First 64 bytes of corrupted metadata buffer:

XFS (dm-0):metadata I/O error: block 0x2 ("xfs_trans_read_buf_map") error 117 numblks 1

 

  1. ls -l /dev/mapper

  2. mkdir /mnt

  3. mount /dev/mapper/centos-root /mnt            # 这里也可以操作 提示中的 dm-0 (即 /dev/dm-0,其实/dev/mapper/centos-root是链接到 /dev/dm-0  )

  4. umount /mnt

  5. xfs_repair /dev/mapper/centos-root     # 或  xfs_repair  /dev/dm-0

  6. init 6 (reboot重启系统)

Linux服务器双IP永久静态路由设置方法【转】

原文: https://blog.csdn.net/xht555/article/details/43408185

现有一台Linux服务器,服务器上的两块网卡各设置了一个静态IP 202.65.219.90和152.104.201.58。IP地址202.65.219.90走的是海外路由,方便海外用户可以快速访问到该服务器;IP地址152.104.201.58走的是国内BGP路由,方便国内用户可以快速访问到该服务器。服务器的IP地址配置如下:

ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:50:56:b7:01:ff brd ff:ff:ff:ff:ff:ff
inet 202.65.219.90/27 brd 202.65.219.95 scope global eth0
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:50:56:b7:02:00 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.104/24 brd 10.0.0.255 scope global eth1
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:50:56:b7:02:01 brd ff:ff:ff:ff:ff:ff
inet 152.104.201.58/27 brd 152.104.201.63 scope global eth2
然而,在默认情况下,Linux系统会自动生成一条默认路由,言下之意,第一个IP地址是没有路由的,因此也就无法Ping通IP地址152.104.201.58,这时就需要我们手动来添加一条指向IP地址152.104.201.58的静态路由,操作方法如下:

  1. vi /etc/iproute2/rt_tables,添加一条路由表:

252 china

  1. 执行下述添加静态路由的shell命令。命令中IP地址及子网掩码根据实际情况进行计算并修改:

ip rule add from 152.104.201.58/27 table china
ip route add 0/0 via 152.104.201.58 dev eth2 table china
上述命令执行后会即时生效,这时就可以Ping通IP地址152.104.201.58了。不过,上述路由设置并非永久生效,在服务器重启或network服务重启后,路由信息也就失效了,这时也就无法Ping通IP地址152.104.201.58了。因此接下来的两步操作可以解决系统重启后路由失效的这个问题:

  1. 在/etc/rc.local增加静态路由添加命令,系统启动时就自动添加路由。

vi /etc/rc.local,插入

ip rule add from 152.104.201.58/27 table china
ip route add 0/0 via 152.104.201.58 dev eth2 table china

  1. 解决network服务重启后路由失效的问题

vi /etc/sysconfig/network-scripts/route-eth2,新建静态路由配置文件route-eth2,文件命名规则:route-devName,即对应网卡设备名的路由配置文件。然后添加路由信息(注意修改实际情况下的IP地址):

0/0 via 152.104.201.58 dev eth2 table china
OK,至此大功告成!


作者:记录的习惯
来源:CSDN
原文:https://blog.csdn.net/xht555/article/details/43408185
版权声明:本文为博主原创文章,转载请附上博文链接!