Recover LVM metadata

Recovery of lvm metadata in case of mishaps while modifying partition or corruption


root@myserver:~# apt install lvm2
root@myserver:~# head /root/lvm/archive/SIEM-vg_00002-106947711.vg

# Generated by LVM2 version 2.03.07(2) (2019-11-30): Wed Aug 4 14:54:30 2021



contents = "Text Format Volume Group"

version = 1



description = "Created *before* executing 'lvextend -l +100%FREE /dev/SIEM-vg/data'"



creation_host = "MC-UKHC1-LPSH-MAP" # Linux MC-UKHC1-LPSH-MAP 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64

creation_time = 1628088870 # Wed Aug 4 14:54:30 2021



root@myserver:~# head /root/lvm/archive/SIEM-vg_00002-106947711.vg -n 40

# Generated by LVM2 version 2.03.07(2) (2019-11-30): Wed Aug 4 14:54:30 2021



contents = "Text Format Volume Group"

version = 1



description = "Created *before* executing 'lvextend -l +100%FREE /dev/SIEM-vg/data'"



creation_host = "MC-UKHC1-LPSH-MAP" # Linux MC-UKHC1-LPSH-MAP 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64

creation_time = 1628088870 # Wed Aug 4 14:54:30 2021



SIEM-vg {

id = "fKhTFb-Uyy5-gnKu-R6Dv-keXh-73xZ-mRj31X"

seqno = 4

format = "lvm2" # informational

status = ["RESIZEABLE", "READ", "WRITE"]

flags = []

extent_size = 8192 # 4 Megabytes

max_lv = 0

max_pv = 0

metadata_copies = 0



physical_volumes {



pv0 {

id = "wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA"

device = "/dev/sda4" # Hint only



status = ["ALLOCATABLE"]

flags = []

dev_size = 156342272 # 74.5498 Gigabytes

pe_start = 2048

pe_count = 19084 # 74.5469 Gigabytes

}



pv1 {

id = "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd"

device = "/dev/sdb" # Hint only



status = ["ALLOCATABLE"]

flags = []

...





root@myserver:~# pvcreate --uuid "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" --restorefile /root/lvm/archive/SIEM-vg_00002-106947711.vg /dev/sdc

WARNING: Couldn't find device with uuid wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA.

WARNING: Couldn't find device with uuid FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd.

Cannot use /dev/sdc: device is partitioned

root@myserver:~# sfdisk -l /dev/sdc

Disk /dev/sdc: 2 TiB, 2199023255552 bytes, 4294967296 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disklabel type: gpt

Disk identifier: D174C1CF-EC08-42F9-A7E6-F9B838671444

root@myserver:~# sfdisk -d /dev/sdc >> sdcparttablebackup

root@myserver:~# cat sdcparttablebackup

label: gpt

label-id: D174C1CF-EC08-42F9-A7E6-F9B838671444

device: /dev/sdc

unit: sectors

first-lba: 34

last-lba: 4294967262

sector-size: 512

root@myserver:~# gdisk /dev/sdc



Command (? for help): x

z zap (destroy) GPT data structures and exit

Expert command (? for help): z

About to wipe out GPT on /dev/sdc. Proceed? (Y/N): Y

GPT data structures destroyed! You may now partition the disk using fdisk or

other utilities.

Blank out MBR? (Y/N): Y

root@myserver:~# pvcreate --uuid "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" --restorefile /root/lvm/archive/SIEM-vg_00002-106947711.vg /dev/sdc

WARNING: Couldn't find device with uuid wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA.

WARNING: Couldn't find device with uuid FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd.

Physical volume "/dev/sdc" successfully created.

root@myserver:~# pvscan

WARNING: PV /dev/sdc in VG SIEM-vg is missing the used flag in PV header.

PV /dev/sdb4 VG SIEM-vg lvm2 [<74.55 GiB / 0 free]

PV /dev/sdc VG SIEM-vg lvm2 [<1024.00 GiB / 0 free]

Total: 2 [1.07 TiB] / in use: 2 [1.07 TiB] / in no VG: 0 [0 ]



root@myserver:~# vgcfgrestore -f /root/lvm/backup/SIEM-vg SIEM-vg

Volume group SIEM-vg has active volume: app.

WARNING: Found 1 active volume(s) in volume group "SIEM-vg".

Restoring VG with active LVs, may cause mismatch with its metadata.

Do you really want to proceed with restore of volume group "SIEM-vg", while 1 volume(s) are active? [y/n]: y

Restored volume group SIEM-vg.



root@myserver:~# blkid

/dev/sda3: UUID="dfc2bdb0-6f36-470a-9dfc-c98924b332b1" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5e192eda-6b4c-4fa0-ae8d-8a53d91020ad"

/dev/loop0: TYPE="squashfs"

/dev/loop1: TYPE="squashfs"

/dev/loop2: TYPE="squashfs"

/dev/loop3: TYPE="squashfs"

/dev/loop4: TYPE="squashfs"

/dev/loop5: TYPE="squashfs"

/dev/loop6: TYPE="squashfs"

/dev/sdb2: UUID="43abf87d-d093-4a77-a3b6-e1faab8d0c65" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="9ddcbbe8-dca3-4236-9612-569eb7e13da0"

/dev/sdb3: UUID="3d066f7e-9ca3-46d7-afd0-021373bdb159" TYPE="swap" PARTUUID="a46bf250-cd06-4d6b-a965-1215d3610e73"

/dev/sdb4: UUID="wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA" TYPE="LVM2_member" PARTUUID="1f7270a4-0caa-4025-9d3c-2fae2a801ef0"

/dev/sda2: UUID="B474-DDD0" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="d413ec6f-39c4-47d2-8a5b-06b48847f215"

/dev/mapper/SIEM--vg-app: UUID="ac421fd4-dd0f-4aa0-874b-ae4a6554ff96" BLOCK_SIZE="4096" TYPE="ext4"

/dev/sdb1: PARTUUID="a95b528d-a529-4ea8-92de-ea8b46fd67f3"

/dev/sdc: UUID="FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" TYPE="LVM2_member"

/dev/sda1: PARTUUID="18b705bc-4c32-4391-ab95-0b47ab67e831"





root@myserver:~# vgchange -ay SIEM-vg

2 logical volume(s) in volume group "SIEM-vg" now active









Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: 7F434980-3FBB-4D7D-9770-F446936F74FE



Device Start End Sectors Size Type

/dev/sdb1 2048 63487 61440 30M BIOS boot

/dev/sdb2 63488 37746687 37683200 18G EFI System

/dev/sdb3 37746688 53370879 15624192 7.5G Linux swap

/dev/sdb4 53370880 209713151 156342272 74.5G Linux LVM





Disk /dev/sdc: 2 TiB, 2199023255552 bytes, 4294967296 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes





Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors

Disk model: Virtual Disk

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: gpt

Disk identifier: 12D18C3D-9E89-4B69-8FB3-E163A97BD783



Device Start End Sectors Size Type

/dev/sda1 2048 4095 2048 1M BIOS boot

/dev/sda2 4096 1054719 1050624 513M EFI System

/dev/sda3 1054720 209713151 208658432 99.5G Linux filesystem





Disk /dev/mapper/SIEM--vg-app: 18.63 GiB, 19998441472 bytes, 39059456 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 /dev/mapper/SIEM--vg-data: 1.05 TiB, 1159553089536 bytes, 2264752128 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

root@myserver:~# pvs

PV VG Fmt Attr PSize PFree

/dev/sdb4 SIEM-vg lvm2 a-- <74.55g 0

/dev/sdc SIEM-vg lvm2 a-- <1024.00g 0



root@myserver:~# pvre

pvremove pvresize

root@myserver:~# pvresize -t /dev/sdc

TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.

Physical volume "/dev/sdc" changed

1 physical volume(s) resized or updated / 0 physical volume(s) not resized

udev part1

Udev was created to respond to hotplug type of events. Much documentation refers to creating devices in response to new devices that have appeared. But, udev is more general; it can run arbitrary userspace commands in response to a new device appearing - or to whatever events it receives from the kernel.

udev 's main purpose is to act upon peripheral detection and hot-plugging, including actions that return control to the kernel, e.g., loading kernel modules or device firmware.

we can assign particular name to any interface name e.g based on pci address or mac address

here ill assign based on pci address. first query the device information

root@myserver:/etc/udev/rules.d# udevadm info -a /sys/class/net/eth0



Udevadm info starts with the device specified by the devpath and then

walks up the chain of parent devices. It prints for every device

found, all possible attributes in the udev rules key format.

A rule to match, can be composed by the attributes of the device

and the attributes from one single parent device.



looking at device '/devices/pci0000:00/0000:00:03.0/net/eth0':

KERNEL=="eth0"

SUBSYSTEM=="net"

DRIVER==""

ATTR{ifindex}=="2"

ATTR{addr_assign_type}=="0"

ATTR{address}=="08:00:27:19:4c:c3"

ATTR{carrier}=="1"

ATTR{gro_flush_timeout}=="0"

ATTR{operstate}=="up"

ATTR{carrier_up_count}=="1"

ATTR{proto_down}=="0"

ATTR{tx_queue_len}=="1000"

ATTR{dev_port}=="0"

ATTR{flags}=="0x1003"

ATTR{link_mode}=="0"

ATTR{carrier_changes}=="2"

ATTR{netdev_group}=="0"

ATTR{duplex}=="full"

ATTR{carrier_down_count}=="1"

ATTR{dormant}=="0"

ATTR{dev_id}=="0x0"

ATTR{type}=="1"

ATTR{mtu}=="1500"

ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"

ATTR{addr_len}=="6"

ATTR{iflink}=="2"

ATTR{ifalias}==""

ATTR{speed}=="1000"



looking at parent device '/devices/pci0000:00/0000:00:03.0':

KERNELS=="0000:00:03.0"

SUBSYSTEMS=="pci"

DRIVERS=="e1000"

ATTRS{local_cpus}=="f"

ATTRS{enable}=="1"

ATTRS{dma_mask_bits}=="32"

ATTRS{msi_bus}=="1"

ATTRS{subsystem_vendor}=="0x8086"

ATTRS{revision}=="0x02"

ATTRS{ari_enabled}=="0"

ATTRS{class}=="0x020000"

ATTRS{driver_override}=="(null)"

ATTRS{device}=="0x100e"

ATTRS{subsystem_device}=="0x001e"

ATTRS{local_cpulist}=="0-3"

ATTRS{vendor}=="0x8086"

ATTRS{consistent_dma_mask_bits}=="32"

ATTRS{broken_parity_status}=="0"

ATTRS{numa_node}=="-1"

ATTRS{d3cold_allowed}=="1"

ATTRS{irq}=="19"



looking at parent device '/devices/pci0000:00':

KERNELS=="pci0000:00"

SUBSYSTEMS==""

DRIVERS==""





root@myserver:/home/support# cat /etc/udev/rules.d/70-persistent-net.rules



ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:08.0", NAME:="eth0"





ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:03.0", NAME:="eth1"





ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:0a.0", NAME:="eth2"





ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:09.0", NAME:="backup"





If rules fail to reload automatically:

# udevadm control --reload
To manually force udev to trigger your rules:


# udevadm trigger
update-initramfs -u -k all






https://wiki.archlinux.org/title/udev#udev_rule_example

https://wiki.debian.org/udev




nxlog on windows 2000

When I tried to run Winbox on a Windows 2000 machine, I got the following error;

The procedure entry point freeaddrinfo could not be located in the dynamic link library WS2_32.DLL

This is the Winsock 2 library and support for freeaddrinfo wasn't added until Windows XP but there is a solution. You can download a modified WS2_32.DLL from here;

http://martin.brenner.de/files/winsock2_getaddrinfo.rar

You only need to extract the compiled WS2_32.DLL from the dllfiles folder, then place the DLL in the same folder as the Winbox executable. Leave the original Windows DLL alone.

Winbox now runs on Windows 2000

download here

nxlog drop specific message 


define ROOT C:\Program Files\nxlog
## define ROOT C:\Program Files (x86)\nxlog
Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data
LogFile %ROOT%\data\nxlog.log
 <Extension _syslog>
    Module xm_syslog
</Extension>
<Extension _charconv>
    Module          xm_charconv
    AutodetectCharsets
</Extension>
<Extension _json>
    Module xm_json
</Extension>
iso8859-2, utf-8, utf-16, utf-32
<Input in_win>
    Module im_msvistalog
Query <QueryList> \
    <Query Id="0"> \
                <Select Path="Application">*</Select> \
                <Select Path="System">*</Select> \
                <Select Path="Security">*</Select> \
            </Query> \
        </QueryList>

</Input>

<Output out_win>
    Module om_tcp
        Host 10.45.9.141
        Port 514
       Exec if $EventID == 4625 or ( $Message =~ /running/m ) drop ();
        Exec to_json();$Message=$raw_event;to_syslog_bsd();

</Output>

<Route 1>
    Path in_win => out_win
</Route>

Exec if $EventID == 4625 or ( $Message =~ /running/m ) drop (); line inside the <Output out_win> block drops the logs with the event id 4625 or any message containing the word running in them.


find which thread is consuming CPU in a Java process

Identifying the thread

You can identify which thread is consuming CPU in a Java process as follows:

  1. Determine the process ID (PID) of the affected server process using the following command: $ jps -v
  2. Determine which thread in the PID identified in step 1 is consuming the CPU:
    • On Unix® and Linux® systems, you can use the top command: $ top -n 1 -H -p [pid]replacing [pid] with the process ID of the affected process.
    • On Solaris®, you can use the prstat command: $ prstat -L -p [pid]replacing [pid] with the process ID of the affected process.
    • On Microsoft® Windows®, you can use the Process Monitor.

These commands all give an output listing all the threads in the selected process along with various details, including the CPU usage percentage. For example, the top command gives an output similar to this:Tasks: 152 total, 0 running, 152 sleeping,   0 stopped,   0 zombie  Cpu(s):  2.0%us,  1.4%sy,  0.0%ni, 94.7%id,  0.8%wa,  0.0%hi,  1.1%si,  0.0%st  Mem:   5008484k total,  4854428k used,   154056k free,    85624k buffers  Swap:  5013496k total,     6516k used,  5006980k free,  3393948k cached PID  USER     PR  NI  VIRT  RES  SHR S  %CPU  %MEM   TIME+  COMMAND               8706 user.1   20   0 2433m 561m  10m R  32.0  11.5  0:35.45 java 8624 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:00.01 java                  8625 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:10.12 java                  8626 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:35.60 java                  8627 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:00.01 java                  8628 user.1   20   0 2433m 561m  10m S   0.0  11.5  0:00.02 java 

In this example, we can see that thread ID 8706 is consuming 32% of the CPU.

  1. Produce a stack trace for the PID identified in step 1 using one of the following commands:
    • jstack command: $ jstack [PID] > jstack-output.txt
    • kill -3 command (Unix® and Linux® systems only), which consistently produces better results: $ kill -3 [pid]The kill -3 command outputs the stack trace to the log file where the standard output is directed (typically the error log file). The kill -3 command does not stop the running process; it will continue to run after outputting the stack trace.
  2. Convert the thread ID identified as problematic in step 2 to a hex value. In our example output, the thread ID decimal value 8706 converts to hex value 2202.
  3. Search the stack trace output for this hex value using grep. You are looking for a thread nid that matches this hex value: $ cat jstack-output.txt | grep -i 2202This command gives an output similar to this: "Concurrent Mark-Sweep GC Thread" prio=10 tid=0x00007f1448029800 nid=0x2202 runnableIn this example, we can see that the problem is a Garbage Collector (GC) thread, which suggests that GC is not properly tuned.

selfsigned certificates and selfsigned CA root certificate

Option 1 (setting up your own CA) is preferable when you need multiple certificates. In a company you might set up your own CA and install that CA's certificate in the root keystore of all clients. Those clients will then accept all certificates signed by your CA.

Option 2 (self-signing a certificate without a CA) is easier. If you just need a single certificate, then this is sufficient. Install it in the keystores of your clients and you are done. But when you need a second certificate, you need to install that again on all clients.

 Self-signing is the simpler route to take, but making one's own CA allows the signing of multiple server certificates using the same CA and involves only a few extra steps. 


https://web.archive.org/web/20160403100211/https://metabrot.rocho.org/jan/selfsign.html

zfs tunables SSD

 ####

# ZFS tuning

# https://www.svennd.be/tuning-of-zfs-module/

###

echo > /etc/modprobe.d/zfs.conf

echo -e "\

# ---------------- BEGIN ----------------  \r

# ZFS tuning for SAS3 ALL SSD + nVME Storage Tank \r

# total arc size limited to 90% of free -m - factor is 1024  \r

# zfs_arc_max={{ '%d' | format(memtotal_mb*1024*1024*0.9) }} \r

options zfs zfs_arc_min=262144000000 \r

options zfs zfs_arc_max=283115520000 \r

options zfs zfs_compressed_arc_enabled=0 \r

###\r

# txg timeout \r

options zfs zfs_txg_timeout=5 \r

###\r

# disable prefetch \r

options zfs zfs_prefetch_disable=1 \r

###\r

# tune l2arc \r

# max write speed to l2arc \r

# default : 8 * 1024 * 1024 \r

# setting here : 500 * 1024 * 1024 \r

options zfs l2arc_write_max=524288000 \r

options zfs l2arc_write_boost=524288000 \r

options zfs l2arc_noprefetch=0 \r

options zfs l2arc_headroom=24 \r

###\r

# dirty pages \r

options zfs zfs_dirty_data_max_percent=40 \r

###\r

# sync zfs_vdev_* \r

# increase them so scrub/resilver is more quickly at the cost of other work \r

options zfs zfs_vdev_scrub_min_active=24 \r

options zfs zfs_vdev_scrub_max_active=64 \r

# sync write \r

options zfs zfs_vdev_sync_write_min_active=8 \r

options zfs zfs_vdev_sync_write_max_active=32 \r

# sync reads (normal) \r

options zfs zfs_vdev_sync_read_min_active=8 \r

options zfs zfs_vdev_sync_read_max_active=32 \r

# async reads : prefetcher \r

options zfs zfs_vdev_async_read_min_active=8 \r

options zfs zfs_vdev_async_read_max_active=32 \r

# async write : bulk writes \r

options zfs zfs_vdev_async_write_min_active=8 \r

options zfs zfs_vdev_async_write_max_active=32 \r

###\r

# scrub \r

options zfs zfs_top_maxinflight=320 \r

options zfs zfs_resilver_delay=0 \r

options zfs zfs_scrub_delay=0 \r

options zfs zfs_resilver_min_time_ms=5000 \r

###\r

# scheduler \r

options zfs zfs_vdev_scheduler=deadline \r

###\r

# cpu limits \r

options zfs zio_taskq_batch_pct=85 \r

options zfs zfs_sync_taskq_batch_pct=85 \r

###\r

# history \r

options zfs zfs_read_history=100 \r

options zfs zfs_read_history_hits=100 \r

options zfs zfs_txg_history=10 \r

###\r

# other tuning\r

options zfs zfs_nocacheflush=1 \r

###\r

# --------------- END ------------------" \

> /etc/modprobe.d/zfs.conf

cat /etc/modprobe.d/zfs.conf

/sbin/modprobe zfs


cat /proc/spl/kstat/zfs/arcstats

zfs tunable SAS

zfs tunables


####

# ZFS tuning

###

echo > /etc/modprobe.d/zfs.conf

echo -e "\

# ---------------- BEGIN ----------------  \r

# ZFS tuning for SAS3 12GE Storage Tank \r

# tank-a  Total Memory: 327680 MB

# tank-b  Total Memory: 393216 MB

# total arc size limited to 90% of free -m - factor is 1024  \r

# zfs_arc_max={{ '%d' | format(memtotal_mb*1024*1024*0.9) }} \r

options zfs zfs_arc_min=262144000000 \r

options zfs zfs_arc_max=314572800000 \r

options zfs zfs_compressed_arc_enabled=0 \r

###\r

# txg timeout \r

options zfs zfs_txg_timeout=5 \r

###\r

# disable prefetch \r

options zfs zfs_prefetch_disable=1 \r

###\r

# tune l2arc \r

# max write speed to l2arc \r

# default : 8 * 1024 * 1024 \r

# setting here : 500 * 1024 * 1024 \r

options zfs l2arc_write_max=524288000 \r

options zfs l2arc_write_boost=524288000 \r

options zfs l2arc_noprefetch=0 \r

options zfs l2arc_headroom=24 \r

###\r

# dirty pages \r

options zfs zfs_dirty_data_max_percent=40 \r

###\r

# sync zfs_vdev_* \r

# increase them so scrub/resilver is more quickly at the cost of other work \r

options zfs zfs_vdev_scrub_min_active=24 \r

options zfs zfs_vdev_scrub_max_active=64 \r

# sync write \r

options zfs zfs_vdev_sync_write_min_active=8 \r

options zfs zfs_vdev_sync_write_max_active=32 \r

# sync reads (normal) \r

options zfs zfs_vdev_sync_read_min_active=8 \r

options zfs zfs_vdev_sync_read_max_active=32 \r

# async reads : prefetcher \r

options zfs zfs_vdev_async_read_min_active=8 \r

options zfs zfs_vdev_async_read_max_active=32 \r

# async write : bulk writes \r

options zfs zfs_vdev_async_write_min_active=8 \r

options zfs zfs_vdev_async_write_max_active=32 \r

###\r

# scrub \r

options zfs zfs_top_maxinflight=320 \r

options zfs zfs_resilver_delay=0 \r

options zfs zfs_scrub_delay=0 \r

options zfs zfs_resilver_min_time_ms=5000 \r

###\r

# scheduler \r

options zfs zfs_vdev_scheduler=deadline \r

###\r

# cpu limits \r

options zfs zio_taskq_batch_pct=85 \r

options zfs zfs_sync_taskq_batch_pct=85 \r

###\r

# history \r

options zfs zfs_read_history=100 \r

options zfs zfs_read_history_hits=100 \r

options zfs zfs_txg_history=10 \r

###\r

# other tuning\r

options zfs zfs_nocacheflush=1 \r

###\r

# --------------- END ------------------" \

> /etc/modprobe.d/zfs.conf

cat /etc/modprobe.d/zfs.conf

/sbin/modprobe zfs


cat /proc/spl/kstat/zfs/arcstats

multiple network interface and gateway

 

Problem Description

You have built two or more network cards into one Linux system and each of these cards has its own default gateway. By default, you can only have one default gateway on a system. The case described would lead to asynchronous routing, whereby the router would reject the packets as appropriate.

Solution

The iproute2 program, which is included in all current Linux distributions and already installed even, as a rule, can be used for the solution of this problem. Normally, a Linux system only has one routing table, in which only one default gateway can make entries. With iproute2, you have the ability to setup an additional routing table, for one thing, and allow this table to be used by the system based on rules, for another.

Initial Position

We will assume that we have two interfaces: eth0 and eth1. The two networks that should be used are 192.168.0.0/24 and 10.10.0.0/24, whereby the first IP address in each respective network should be the gateway. Under Debian, the initial configuration would appear as follows. /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface

auto lo
iface lo inet loopback

# The primary network interface

allow-hotplug eth0
iface eth0 inet static
    address 192.168.0.10
    netmask 255.255.255.0
    gateway 192.168.0.1

# The secondary network interface
allow-hotplug eth1
iface eth1 inet static
    address 10.10.0.10
    netmask 255.255.255.0

Adding a Second Routing Table

To add a new routing table, the file, /etc/iproute2/rt_tables must be edited. We will call the routing table “rt2” and set its preference to 1. The named file should then appear as follows.

#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
1 rt2

Configuring the New Routing Table

From this point, four commands are needed to achieve our goal. First, the new routing table needs to be populated, which is done using the following command.

ip route add 10.10.0.0/24 dev eth1 src 10.10.0.10 table rt2
ip route add default via 10.10.0.1 dev eth1 table rt2

The first command says that the network, 10.10.0.0/24, can be reached through the eth1 interface. The second command sets the default gateway.

Routing Rules

So that the system knows when to use our new routing table, two rules must be configured.

ip rule add from 10.10.0.10/32 table rt2
ip rule add to 10.10.0.10/32 table rt2

These rules say that both traffic from the IP address, 10.10.0.10, as well as traffic directed to or through this IP address, should use the rt2 routing table.

Making the Configuration permanent

The ip rule and ip route commands will become invalid after a re-boot, for which reason they should become part of a script (for example, /etc/rc.local) that will be executed once the network has been started after booting. For Debian, these command can also be written directly into the /etc/network/interfaces file, which would then appear as follows.

iface eth1 inet static
    address 10.10.0.10
    netmask 255.255.255.0
    post-up ip route add 10.10.0.0/24 dev eth1 src 10.10.0.10 table rt2
    post-up ip route add default via 10.10.0.1 dev eth1 table rt2
    post-up ip rule add from 10.10.0.10/32 table rt2
    post-up ip rule add to 10.10.0.10/32 table rt2

More than Two Network Cards or Gateways

If there are more than two networks, a routing table can be created for each additional network analogous to the example presented above.

Testing the Configuration

The following commands can be used to ensure that the rules as well as the routing entries are working as expected.

ip route list table rt2
ip rule show

debug node

 The worst has happened. Your Node.js app is stuck in a good old-fashioned infinite loop. Express is listening for connections, but never responds. top shows 100% CPU.

You chose Node.js for its single-threaded performance and most days you’re very happy about that. This is not one of those days. Since there is just one thread of execution, all requests reaching this particular process are stuck.

Sure, you’re running one process per core and even on multiple servers. But if a common operation is the cause, all of the processes encounter it before long, and the application is effectively down. You are not having a good day.

No problem, you say as you sync your database down to a dev environment and try to reproduce the issue. Here in dev, you can console.log your way through it if you have to, following a “divide and conquer” strategy.

Except… you can’t. Something is happening in production that you have never thought of, and you don’t know what it is. So you can’t reproduce it. You need to debug this in production. 🙀

You could redeploy your app with lots of additional logging, and that’s not a bad thing. But what if you could find out exactly what code is running right now? Then you could see the problem immediately and save a great deal of downtime.

There’s a way: the Node.js command line debugger.

First, ssh into the server or open a shell in your container, if that’s how you roll. Then run top and find your runaway process. It’ll sort right to the top of the list:

runaway process
Process 4702, using close to 100% of CPU.

Gee, think maybe that’s the one?

Now, let’s tell the process to listen for debugging requests.

Yes, we’re using a command called kill. No, we’re not killing the process. We’re sending it a different signal.

kill -SIGUSR1 4702

Once you do this, the process is open to a debugger connection. In fact, it will print a special URL to its console log, and you can open that URL in Chrome to debug the process! But, maybe you don’t want to drill a hole through a firewall and a container configuration just to make that connection. Yeah, me neither.

So let’s debug at the command line instead:

node inspect -p 4702

You’ll see this prompt:

debug>

Holy smokes, you’re in the debugger! Let’s print a stack trace to see where you are in the code:

backtrace

But you just get back:

null

Hmm, that’s not very useful. Let’s type help and see if there’s anything about how to pause the process… nope!

Fortunately, I was able to find the command eventually. Sure enough, you just type:

pause

And you get back:

break in file:///somewhere/something.js:555
>555 for (prop in inputObject) {

Yes! We have our first hint. The app was executing line 555 in file something.js.

That might be enough to see the bug right away. But usually we need more information than that. You can type backtrace to get a complete stack trace:

#0 someFunctionName file:///somewhere/somefile.js:444:22

… And so on.

By now you often have enough information to solve the problem. But if not, you can set breakpoints and continue execution to see if they are indeed hit over and over:

setBreakpoint('file:///somewhere/somefile.js', 444)
cont

Sure enough, you come right back to that line of code when cont continues execution. Hit cont a few times and it becomes clear you’re looping there. You can set breakpoints on other lines to figure out if it’s stuck in this inner loop here, or that outer one there, and so on.

This is helpful, but you still don’t know why you’re stuck in the loop. So let’s watch a variable to find out its value the next time you reach a breakpoint:

watch('counter')

And when you reach the breakpoint again, you see:

break in file:///somewhere/something.js:444

Gotcha! The counter variable is NaN (“not a number”), so it can’t be incremented and will never reach the end condition for a for loop or while loop.

Now you have enough information to go back to your dev environment, fix the bug, test a fix (forcing the NaN case as a test if you have to!) and ship it to production.

To close the debugger, just press control-D to exit.

nginx loadbalancer tcp/udp syslog part 1

 http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html#proxy_bind

https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/#proxy_pass


Directives

Syntax:proxy_bind address [transparent] | off;
Default:—
Context:stream, server

This directive appeared in version 1.9.2.

Makes outgoing connections to a proxied server originate from the specified local IP address. Parameter value can contain variables (1.11.2). The special value off cancels the effect of the proxy_bind directive inherited from the previous configuration level, which allows the system to auto-assign the local IP address.

The transparent parameter (1.11.0) allows outgoing connections to a proxied server originate from a non-local IP address, for example, from a real IP address of a client:

proxy_bind $remote_addr transparent;

In order for this parameter to work, it is usually necessary to run nginx worker processes with the superuser privileges. On Linux it is not required (1.13.8) as if the transparent parameter is specified, worker processes inherit the CAP_NET_RAW capability from the master process. It is also necessary to configure kernel routing table to intercept network traffic from the proxied server.