From d45048e43945e092f375ff659ab4d8062d84aa3e Mon Sep 17 00:00:00 2001 From: root Date: Sat, 27 Jan 2024 07:49:05 +1200 Subject: [PATCH] Initial --- .editorconfig | 6 ++++ .gitignore | 23 +++++++++++++ README.MD | 14 ++++++++ docs/linux/common.md | 54 +++++++++++++++++++++++++++++ docs/linux/fedora.md | 13 +++++++ docs/linux/filesystems.md | 41 ++++++++++++++++++++++ docs/linux/rsyslog.md | 64 +++++++++++++++++++++++++++++++++++ docs/linux/selinux.md | 9 +++++ docs/other/math.md | 3 ++ docs/progs/crontab.md | 28 +++++++++++++++ docs/progs/kubernetes.md | 22 ++++++++++++ docs/progs/mariadb.md | 8 +++++ docs/progs/mc.md | 53 +++++++++++++++++++++++++++++ docs/progs/nmcli.md | 71 +++++++++++++++++++++++++++++++++++++++ docs/progs/php.md | 5 +++ docs/progs/socat.md | 4 +++ docs/progs/ssh.md | 17 ++++++++++ 17 files changed, 435 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 README.MD create mode 100644 docs/linux/common.md create mode 100644 docs/linux/fedora.md create mode 100644 docs/linux/filesystems.md create mode 100644 docs/linux/rsyslog.md create mode 100644 docs/linux/selinux.md create mode 100644 docs/other/math.md create mode 100644 docs/progs/crontab.md create mode 100644 docs/progs/kubernetes.md create mode 100644 docs/progs/mariadb.md create mode 100644 docs/progs/mc.md create mode 100644 docs/progs/nmcli.md create mode 100644 docs/progs/php.md create mode 100644 docs/progs/socat.md create mode 100644 docs/progs/ssh.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c651587 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ + + + [*] + end_of_line = lf + indent_style = tab + tab_width = 4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3716c41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ + +**/*_ +**/.#* +**/0* +**/1* +**/2* +**/3* +**/4* +**/5* +**/6* +**/7* +**/8* +**/9* + +**/*.log* +**/*log +**/LOG* + +cache/** +data/** +old/** +outer/** +secret/** diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..062314c --- /dev/null +++ b/README.MD @@ -0,0 +1,14 @@ + + +| A | B | +|-----------------------------------------|-----------------------------------------| +| | [Linux](docs/linux/common.md) | +| | [MariaDB](docs/progs/mariadb.md) | +| | [MC](docs/progs/mc.md) | +| | [Socat](docs/progs/socat.md) | +| [Math](docs/math.md) | [Crontab](docs/progs/crontab.md) | +| | [Kubernetes](docs/progs/kubernetes.md) | +| | [NMCli](docs/progs/nmcli.md) | +| [Math](docs/math.md) | [SSH](docs/progs/ssh.md) | +| | [GIT](docs/progs/git.md) | +| | [PHP](docs/progs/php.md) | diff --git a/docs/linux/common.md b/docs/linux/common.md new file mode 100644 index 0000000..6b4063a --- /dev/null +++ b/docs/linux/common.md @@ -0,0 +1,54 @@ + +[File systems](filesystems.md) + +[Fedora / CentOS](fedora.md) + +[SELinux](selinux.md) + +# Common + +## find +``` +find /var -maxdepth 2 -type d -printf "%TY-%Tm-%Td %TH:%TM:%TS %Tz %p\n" +``` + +## bash +``` +# cat > /etc/profile.d/cmp.sh + +export EDITOR=mcedit +export HISTFILESIZE=10485760 +export HISTSIZE=500000 +export HISTCONTROL=ignoreboth:erasedups +export HISTIGNORE="history:reboot:poweroff:cd:ls:pwd:mc:ps:m:e:l" +export SSH_ASKPASS= + +alias ffi='ffmpeg -hide_banner -i' + +alias m='cd /mnt' +alias e='cd /etc' +alias l='cd /var/log' + +tabs -4 + +``` + +## reboot +```bash +echo 1 > /proc/sys/kernel/sysrq +echo b > /proc/sysrq-trigger +``` + +## Motherboard name +```bash +cat /sys/devices/virtual/dmi/id/board_name +``` + +## grab video from screen +```bash +ffmpeg -s 1920x1080 -framerate 10 -f x11grab -i :0 -qscale 6 out.mkv +``` + +```bash +ps --ppid 2 -p 2 --deselect +``` diff --git a/docs/linux/fedora.md b/docs/linux/fedora.md new file mode 100644 index 0000000..a01dffb --- /dev/null +++ b/docs/linux/fedora.md @@ -0,0 +1,13 @@ +# Fedora / CentOS / Etc + +## Relabel +```bash +touch /.autorelabel +``` + +## Install PHP 8 +``` +dnf install https://rpms.remirepo.net/fedora/remi-release-38.rpm +dnf module reset php +dnf module install php:remi-8.2 +``` diff --git a/docs/linux/filesystems.md b/docs/linux/filesystems.md new file mode 100644 index 0000000..411ad24 --- /dev/null +++ b/docs/linux/filesystems.md @@ -0,0 +1,41 @@ + +# LVM +#### Extend +```bash +lvextend -L+1G /dev/vg4/homevol +``` + +# Btrfs +#### Resize +```bash +btrfs filesystem resize max /mnt/dmp/ +``` +#### Defragment / compress +```bash +btrfs filesystem defragment -v -clzo /boot/* +``` +#### Set RO / RW +```bash +btrfs property set -f . ro false +btrfs property set -f . ro true +``` +#### Create shapshot +```bash +btrfs subvolume snapshot xyz xyz-snapshot-path-name +``` +#### Delete shapshot +```bash +btrfs subvolume delete xyz-snapshot-path-name +``` + +# Ext4 +#### Resize +```bash +resize2fs /dev/device [size] +``` + +#### if superblock fail +```bash +dumpe2fs /dev/sda5 | grep -i backup +fsck -b 32768 /dev/sda5 +``` diff --git a/docs/linux/rsyslog.md b/docs/linux/rsyslog.md new file mode 100644 index 0000000..eb1b654 --- /dev/null +++ b/docs/linux/rsyslog.md @@ -0,0 +1,64 @@ +``` +$ModLoad imudp +$UDPServerRun 514 + + template(name="cmpDate" type="list") { + property(name="timereported" dateformat="year") + constant(value="-") + property(name="timereported" dateformat="month") + constant(value="-") + property(name="timereported" dateformat="day") + } + + + set $.cmpDate = exec_template("cmpDate"); + set $.cmpSuff = "default"; + + template(name="cmpOutFile" type="list") { + constant(value="/mnt/netlog/zzz/") + + property(name="$.cmpDate") + + constant(value="/") + # property(name="hostname") + property(name="fromhost-ip") + constant(value="-") + property(name="$.cmpSuff") + constant(value=".log") + } + + template(name="cmpOutFmt" type="list") { + property(name="$.cmpDate") + + constant(value=" ") + property(name="timereported" dateformat="hour") + constant(value=":") + property(name="timereported" dateformat="minute") + constant(value=":") + property(name="timereported" dateformat="second") + + constant(value=" ") + property(name="hostname") + constant(value=" ") + + property(name="syslogtag") + property(name="msg" spifno1stsp="on" ) + property(name="msg" droplastlf="on" ) + constant(value="\n") + } + + + if( $fromhost-ip == "127.0.0.1" ) then { + stop + } + + if ( $fromhost-ip == "172.16.1.1" ) then { + if ( $syslogtag contains "teg3" ) then { + set $.cmpSuff = "teg3"; + } + } + + action(type="omfile" dynafile="cmpOutFile" template="cmpOutFmt") + + stop +``` diff --git a/docs/linux/selinux.md b/docs/linux/selinux.md new file mode 100644 index 0000000..ea5a586 --- /dev/null +++ b/docs/linux/selinux.md @@ -0,0 +1,9 @@ + +# Nginx +``` +# Allow open local port +semanage port -a -t http_port_t -p tcp 28081 + +# Allow open remote port +setsebool -P httpd_can_network_connect 1 +``` diff --git a/docs/other/math.md b/docs/other/math.md new file mode 100644 index 0000000..83c0292 --- /dev/null +++ b/docs/other/math.md @@ -0,0 +1,3 @@ + +# Аппроксимация функции одной переменной +[https://planetcalc.ru/5992/](https://planetcalc.ru/5992/) diff --git a/docs/progs/crontab.md b/docs/progs/crontab.md new file mode 100644 index 0000000..6a0e514 --- /dev/null +++ b/docs/progs/crontab.md @@ -0,0 +1,28 @@ + +# Crontab + +``` +# PATH=$PATH:/usr/local/bin +# LANG= +# LC_ALL= + +### on reboot +# @reboot command + +### on time +# * * * * * command +### | | | | | +### | | | | | +### | | | | | +### | | | | |--| 0-7 день недели +### | | | | | +### | | | |----| 1-12 месяц +### | | | | +### | | |------| 1-31 день месяца +### | | | +### | |--------| 0-23 часы +### | | +### |----------| 0-59 минуты + +``` + diff --git a/docs/progs/kubernetes.md b/docs/progs/kubernetes.md new file mode 100644 index 0000000..abb1826 --- /dev/null +++ b/docs/progs/kubernetes.md @@ -0,0 +1,22 @@ + +```bash +mkdir -p $HOME/.kube +sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config +sudo chown $(id -u):$(id -g) $HOME/.kube/config +``` + +Alternatively, if you are the root user, you can run: +```bash +export KUBECONFIG=/etc/kubernetes/admin.conf +``` + +You should now deploy a pod network to the cluster. +Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: +https://kubernetes.io/docs/concepts/cluster-administration/addons/ + +Then you can join any number of worker nodes by running the following on each as root: + +```bash +kubeadm join 10.0.0.1:6443 --token 000000.0000000000000000 \ +--discovery-token-ca-cert-hash sha256:0000000000000000000000000000000000000000000000000000000000000000 +``` diff --git a/docs/progs/mariadb.md b/docs/progs/mariadb.md new file mode 100644 index 0000000..80e9f18 --- /dev/null +++ b/docs/progs/mariadb.md @@ -0,0 +1,8 @@ + +# MariaDB + +## Create database, user and grand permission +```sql +CREATE DATABASE dbn CHARACTER SET utf8 COLLATE utf8_general_ci; +CREATE USER 'usr'@'localhost' IDENTIFIED BY 'pwd'; GRANT ALL PRIVILEGES ON dbn.* TO usr@localhost; +``` diff --git a/docs/progs/mc.md b/docs/progs/mc.md new file mode 100644 index 0000000..5049962 --- /dev/null +++ b/docs/progs/mc.md @@ -0,0 +1,53 @@ +# MC + +## ~/.config/mc/ini +```ini +[Layout] +command_prompt=1 +free_space=1 +horizontal_equal=1 +horizontal_split=0 +keybar_visible=0 +left_panel_size=104 +menubar_visible=0 +message_visible=0 +output_lines=0 +top_panel_size=1 +vertical_equal=1 +xterm_title=0 + +[Midnight-Commander] +use_internal_view=1 +use_internal_edit=1 +alternate_plus_minus=1 +skin=darkfar + +editor_ask_filename_before_edit=false +editor_backspace_through_tabs=false +editor_backup_extension=~ +editor_check_new_line=false +editor_cursor_after_inserted_block=false +editor_cursor_beyond_eol=false +editor_drop_selection_on_copy=true +editor_edit_confirm_save=true +editor_fake_half_tabs=false +editor_filesize_threshold=64M +editor_fill_tabs_with_spaces=false +editor_group_undo=false +editor_line_state=false +editor_option_auto_para_formatting=false +editor_option_save_mode=0 +editor_option_save_position=true +editor_option_typewriter_wrap=false +editor_persistent_selections=true +editor_return_does_auto_indent=true +editor_show_right_margin=false +editor_simple_statusbar=false +editor_state_full_filename=false +editor_stop_format_chars=-+*\\,.;:&> +editor_syntax_highlighting=true +editor_tab_spacing=4 +editor_visible_spaces=true +editor_visible_tabs=false +editor_word_wrap_line_length=72 +``` diff --git a/docs/progs/nmcli.md b/docs/progs/nmcli.md new file mode 100644 index 0000000..10e6ad4 --- /dev/null +++ b/docs/progs/nmcli.md @@ -0,0 +1,71 @@ + +# Connection start +```bash +nmcli con up ens18 +``` + +# Connection modifity +```bash +ifc=eth0 \ +nmcli con mod $ifc ipv4.addresses 172.16.23.56/24 && \ +nmcli con mod $ifc ipv4.gateway 172.16.23.1 && \ +nmcli con mod $ifc ipv4.dns 172.16.20.130 && \ +nmcli con mod $ifc ipv4.method manual && \ +nmcli con mod $ifc ipv6.method disable && \ +nmcli con up $ifc restart && \ +true +``` + +# Disable IPv6 for all +``` +nmcli con show | awk '{if(NR > 1) { print $1; system("nmcli con mod " $1 " ipv6.method disable"); } }' +``` + +# Connection event +```bash +#!/bin/bash + +# This is /etc/NetworkManager/dispatcher.d/0167-cmp.sh + +# IFACE="$1" # DEVICE_IFACE +# EVENT="$2" # NM_DISPATCHER_ACTION +# - connectivity-change +# - down +# - up +# - vpn-down +# - vpn-up +# +# + + if [ "${NM_DISPATCHER_ACTION}" = "connectivity-change" ]; then + if [ "${CONNECTIVITY_STATE}" = "FULL" ]; then + nmcli conn up ssh-37 + exit 0 + fi + + if [ "${CONNECTIVITY_STATE}" = "LIMITED" ]; then + nmcli conn up ssh-37 + exit 0 + fi + + if [ "${CONNECTIVITY_STATE}" = "NONE" ]; then + exit 0 + fi + + # exit 0 + fi + + if true; then + logger -t 0167-cmp.sh @=$@ "ENV" \ + NM_DISPATCHER_ACTION=$NM_DISPATCHER_ACTION \ + CONNECTION_UUID=$CONNECTION_UUID \ + CONNECTION_ID=$CONNECTION_ID \ + CONNECTION_DBUS_PATH=$CONNECTION_DBUS_PATH \ + CONNECTION_FILENAME=$CONNECTION_FILENAME \ + CONNECTION_EXTERNAL=$CONNECTION_EXTERNAL \ + DEVICE_IFACE=$DEVICE_IFACE \ + DEVICE_IP_IFACE=$DEVICE_IP_IFACE \ + CONNECTIVITY_STATE=$CONNECTIVITY_STATE + fi + +``` diff --git a/docs/progs/php.md b/docs/progs/php.md new file mode 100644 index 0000000..b465271 --- /dev/null +++ b/docs/progs/php.md @@ -0,0 +1,5 @@ + +## Set default timezone +``` + printf '[Date]\ndate.timezone = Asia/Katmandu\n' > /etc/php.d/17-cmp-timezone.ini +``` diff --git a/docs/progs/socat.md b/docs/progs/socat.md new file mode 100644 index 0000000..0c5a462 --- /dev/null +++ b/docs/progs/socat.md @@ -0,0 +1,4 @@ + +```bash +socat PTY,link=/dev/vmodem0,echo=0,waitslave TCP:10.0.0.1:333 +``` diff --git a/docs/progs/ssh.md b/docs/progs/ssh.md new file mode 100644 index 0000000..19a7c91 --- /dev/null +++ b/docs/progs/ssh.md @@ -0,0 +1,17 @@ +# SSH + +## Generate public key from private +``` +ssh-keygen -f id_rsa -y > id_rsa.pub +``` + +## Port forwarding +```bash +# forward : 172.16.0.1:80 -> 172.16.0.2 -> 127.0.0.1:4080 +ssh -f -N -L 4080:172.16.0.1:80 172.16.0.2 +``` + +## Allow old algorithm +```bash +ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-dss 172.16.0.1 +```