Press "Enter" to skip to content

标签: linux

Linux/FreeBSD 下tar加密压缩命令

加密压缩

tar -czvf - file | openssl des3 -salt -k password -out kiccleaf.tar.gz

解密解压

openssl des3 -d -k password -salt -in kiccleaf.tar.gz | tar zxvf -

file:可以是文件或是目录,多文件/目录空格隔开
password:需要设定的密码

需要注意事项:
在命令行直接输入命令进行加密操作,一般系统在用户的命令历史Linux【.bash_history】/FreeBSD下【.history】文件里面会记录了命令行也就知道了密码,所以如果系统记录了操作的命令行则需要清掉涉及的历史记录或清空,也可以在加密时候不要使用 -k 参数以及后面的密码串,等询问时候再进行输入,解压输入 密码串,这样就不会泄漏密串。如下操作:

加密码提示输入密串,需要输入两次
[root@kiccleaf ~]# tar -czvf - kiccleaf | openssl des3 -salt -out kiccleaf.tar.gz
test.sh
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:

直接解压不可以咯
[root@kiccleaf ~]# tar zxvf kiccleaf.tar.gz 

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now

解压提示输入密串
[root@kiccleaf ~]# openssl des3 -d -salt -in kiccleaf.tar.gz | tar zxvf -
enter des-ede3-cbc decryption password:
test.sh

Leave a Comment

CentOS8系统时间同步解决方法

装了新的CentOS8,才发现有很多原来使用的工具在新版本中已经被其他工具替代,今天把常规的系统时间同步问题解决一下,CentOS7及以下的都是采用NTP来解决,《linux中rc.local设置开机自启没有生效解决方案》。

找了一下方法,原来是使用了另一个工具替代了,记录一下先

[root@kiccleaf home]# yum install -y chrony

Installed:
  chrony-3.5-1.el8.x86_64                                                                                            timedatex-0.5-3.el8.x86_64                                                                                           

Complete!
安装好工具,先启动
[root@kiccleaf home]# systemctl start chronyd
设为系统自动启动
[root@kiccleaf home]# systemctl enable chronyd
编辑一下配置文件
[root@kiccleaf home]# vim /etc/chrony.conf

/etc/chrony.conf配置文件内容:

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#pool 2.centos.pool.ntp.org iburst (这一行注释掉,增加以下两行)
server ntp.aliyun.com iburst
server cn.ntp.org.cn iburst
重新加载配置
[root@kiccleaf home]# systemctl restart chronyd.service
[root@kiccleaf home]# chronyc sources -v
210 Number of sources = 2

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* 203.107.6.88                  2   6     7     2   -188us[+6871us] +/-   24ms
^- 61.177.189.190                3   6    17    19   +663us[ +663us] +/-   97ms

[root@kiccleaf home]# date
Sat Aug 29 16:26:08 CST 2020
1 Comment

CentOS8安装PHP8

最新系统上来了这大半年都没有时间安装用用,php-8.0.0beta2 也发布出来了,先记录一下,CentOS8安装选择最小安装(跟原来安装差不多没变化),所以安装速度很快,因为是最小安装所以有些工具没有,能少则少的原则

简单说一下yum源修改

先安装wget工具:

yum install -y wget
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

或者用

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
yum makecache 生成缓存

系统缺少命令ifconfig,netstat,whois等命令需要安装net-tools.x86_64,另外习惯使用vim编辑器,所以每次都会安装,常用的screen也是要安装的,但在CentOS8系统下直接yum install screen是安装失败的

[root@kiccleaf ~]# yum install screen
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:01:32 ago on Tue 25 Aug 2020 02:16:39 PM CST.
No match for argument: screen
Error: Unable to find a match: screen
办法总是有的,先安装epel-release
[root@kiccleaf ~]# yum install -y epel-release
Installed:
  epel-release-8-8.el8.noarch                                                                                                                                                                                                               

Complete!
[root@kiccleaf ~]# yum install -y screen
Installed:
  screen-4.6.2-10.el8.x86_64                                                                                                                                                                                                                

Complete!
[root@kiccleaf ~]# 
安装成功了!测试一下
[root@kiccleaf ~]# screen -S kiccleaf
新的窗体里面了
[root@kiccleaf ~]#
Ctrl+ad  临时退出窗体
[detached from 35676.kiccleaf]

重新进入刚才的窗体
[root@kiccleaf ~]# screen -r kiccleaf
退出窗体
[root@kiccleaf ~]# exit
exit
[screen is terminating]
到此完美使用screen工具了。
接下去安装vim和网络命令
[root@kiccleaf ~]# yum install -y net-tools.x86_64 vim 
来看一下系统的版本吧
[root@kiccleaf ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core) 
[root@kiccleaf ~]# 

先下载PHP8源码包,下载网址:https://downloads.php.net/~pollita/

[root@kiccleaf ]# wget https://downloads.php.net/~pollita/php-8.0.0beta2.tar.gz
[root@kiccleaf ]# tar zxvf php-8.0.0beta2.tar.gz
[root@kiccleaf ]# cd php-8.0.0beta2
根据自己的需求进行配置安装相应的扩展
[root@kiccleaf php-8.0.0beta2]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-static --enable-sockets --with-zip --enable-calendar --enable-bcmath --enable-mbstring --with-zlib --with-iconv=/usr/local/libiconv --enable-gd --enable-mbstring --with-curl --with-freetype --disable-ipv6 --disable-debug --with-openssl --enable-intl --enable-opcache

[root@kiccleaf php-8.0.0beta2]# make 
[root@kiccleaf php-8.0.0beta2]# make install

在执行中可能会遇到一些问题,这里简单说明一下:

1. configure: error: iconv does not support errno

[root@kiccleaf ]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
[root@kiccleaf ]# tar zxvf libiconv-1.15.tar.gz
[root@kiccleaf libiconv-1.15]#  cd libiconv-1.15
[root@kiccleaf libiconv-1.15]# ./configure --prefix=/usr/local/libiconv
[root@kiccleaf libiconv-1.15]#  make 
[root@kiccleaf libiconv-1.15]#  make install
安装好PHP8后配置进行启动
[root@kiccleaf php-8.0.0beta2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@kiccleaf php-8.0.0beta2]# chmod a+x /etc/init.d/php-fpm
[root@kiccleaf php-8.0.0beta2]# service php-fpm start
[root@kiccleaf php-8.0.0beta2]# php -v
PHP 8.0.0beta2 (cli) (built: Aug 24 2020 13:47:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
Leave a Comment

Centos7安装php7.4.9+redis扩展

本文只讲php的编译及Redis扩展的安装,其他nginx的安装什么都相同方式无非就是配置需要修改一下。

php7.4.9安装包下载:https://www.php.net/downloads.php#v7.4.9

我下载了:https://www.php.net/distributions/php-7.4.9.tar.bz2

解压 tar jzvf php-7.4.9.tar.bz2,并打开php-7.4.9目录,需要安装的扩展自行增减,然后进行编译:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-zip --disable-fileinfo
进行make时会提示错误:
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

需要:make ZEND_EXTRA_LIBS=’-liconv’ 进行编译操作

等编译后make install安装完成!

把php-fpm做成系统启动,先复制 php-7.4.9目录下./sapi/fpm/init.d.php-fpm至/etc/init.d/目录下

cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

复制完,执行service php-fpm start 会提示错误:env: /etc/init.d/php-fpm: Permission denied,因为 init.d目录下需要给相应的权限才可执行:

chmod a+x /etc/init.d/php-fpm

执行service php-fpm start 提示:Starting php-fpm done 说明启动成功!

然后第二步安装Redis扩展,下载地址:https://pecl.php.net/package/redis 选择自己适合的扩展,我选择了最新的Redis5.3.1版本

wget https://pecl.php.net/get/redis-5.3.1.tgz
tar zxvf redis-5.3.1.tgz
cd redis-5.3.1
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

–with-php-config=/usr/local/php/bin/php-config 根据自己安装的位置找到php-config

编辑php.ini文件

vim /usr/local/php/etc/php.ini

找到extension区域,增加:extension=redis.so,然后保存退出

重启php进程 service php-fpm restart

查看php是否已经安装了redis模块:

[root@localhost php-7.4.9]# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
filter
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zlib

[Zend Modules]

这里特别注意:–with-config-file-path=/usr/local/php/etc编译PHP是指定目录 php.ini文件,如果非此目录的php.ini文件增加扩展,重启是不会加载扩展。新手要特别注意!!!

写一个php文件:phpinfo.php

<?php
  phpinfo();
?>

找到此配置信息项:

Configuration File (php.ini) Path/usr/local/php/etc
Loaded Configuration File/usr/local/php/etc/php.ini

转载请注明出处!

Leave a Comment

个性化Linux/FreeBSD字符界面,登录输出显示信息

很多年以前写过Linux登录时输出个性信息,被各大平台及个人博客转载,遗憾的是他们从来没有写上原文从哪里转载过来,我个人支持大家相互学习和转载,但请转载注明一下出处可以吗?怎么说也是我的小小劳动成果。

Linux及FreeBSD下编辑/etc/motd

vi /etc/motd

         Welcome to Linux
  _     _            _                 ___
 | |   (_)          | |               / __)
 | |  _ _  ____ ____| | _____ _____ _| |__
 | |_/ ) |/ ___) ___) || ___ (____ (_   __)
 |  _ (| ( (__( (___| || ____/ ___ | | |
 |_| \_)_|\____)____)\_)_____)_____| |_|

FreeBSD就添加相应的提示信息(清空原FreeBSD下/etc/motd文件自带的信息,会比较多,全清掉即可)

FreeBSD 12.1-RELEASE r354233 GENERIC
  
          Welcome to FreeBSD!
   _     _            _                 ___
  | |   (_)          | |               / __)
  | |  _ _  ____ ____| | _____ _____ _| |__
  | |_/ ) |/ ___) ___) || ___ (____ (_   __)
  |  _ (| ( (__( (___| || ____/ ___ | | |
  |_| \_)_|\____)____)\_)_____)_____| |_|

欢迎转载,请注明出处,谢谢!

原来《个性化Linux字符界面,登录输出显示信息》中有颜色更漂亮,但是针对使用WinSCP软件SFTP登录时会有错误提示:WinSCP登陆服务器提示收到了太大的SFTP包 支持的最大包大小1024000B,总有得失,看个人喜欢。

Leave a Comment

Linux md5sum校验文件是否被篡改

因为有些平台日常不会作更新操作,担心文件被非法修改自己又不知道,所以采用linux提供的简单命令来实现文件校验。

先把目录中的所有文件进行MD5,sort参数是排序后存放在md5.txt文件中,这个文件保存好,因为这是你历史的文件的md5,如果目录中某个文件被修改,在校验中就被找出来。

find /data -type f -print0 | xargs -0 md5sum | sort >md5.txt

校验文件是否被修改过,不显示正常的文件采用grep -v OK

root@kiccleaf data]# md5sum -c md5.txt | grep -v OK
/data/g.sh: FAILED
md5sum: WARNING: 1 computed checksum did NOT match

Comments closed

Linux中的chkconfig增加自己想要启动项

总有些需要自己配置启动项的,简单记录一下过程

#先写一个自己需要执行的软件或是其他要执行的事项,这里就拿同步系统时间作为例子
[root@localhost ~]# vim /root/syncDate.sh
#!/bin/bash
/usr/sbin/ntpdate cn.pool.ntp.org>/root/times.log
[root@localhost ~]# chmod +x /root/syncDate.sh

#开始写启动项文件kiccleaf
[root@localhost ~]# vim /etc/init.d/kiccleaf
#!/bin/bash
# chkconfig: 3 88 88
/bin/bash /root/syncDate.sh &>/dev/null 2&>/dev/null

注意:# chkconfig: 3 88 88 这一行很重要,如果不添加,
执行chkconfig –add kiccleaf 会提示失败

[root@localhost ~]# chkconfig --add kiccleaf
service kiccleaf does not support chkconfig
#以上是失败提醒,未增加# chkconfig: 3 88 88

#增加可执行权限
[root@localhost ~]# chmod +x /etc/init.d/kiccleaf

#添加到chkconfig,开机自启动
[root@localhost ~]# chkconfig --add kiccleaf
[root@localhost ~]# chkconfig --list kiccleaf

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

kiccleaf        0:off   1:off   2:off   3:on    4:off   5:off   6:off
#重启系统,查看结果

[root@localhost ~]# cat /root/times.log
12 Jun 11:38:34 ntpdate[10221]: step time server 203.107.6.88 offset -28799.359688 sec
操作成功

#关闭开机启动

[root@localhost ~]# chkconfig kiccleaf off
[root@localhost ~]# chkconfig --list kiccleaf
kiccleaf        0:off   1:off   2:off   3:off   4:off   5:off   6:off

#从chkconfig管理中删除kiccleaf
[root@localhost ~]# chkconfig --del kiccleaf
#查看列表中是否还存在kiccleaf启动项,结果已经没有
[root@localhost ~]# chkconfig --list kiccleaf
service kiccleaf supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add kiccleaf')

关于chkconfig更多内容,可以参考:Linux下chkconfig命令详解

Comments closed

linux中rc.local设置开机自启没有生效解决方案

经常在一些小细节方面卡壳,先查看一下文件是否有执行属性

[root@localhost ~]# ll /etc/rc.d/rc.local
-rw-r--r--  1 root root 507 Jun 12 11:01 /etc/rc.d/rc.local

#上面可以看出没有可执行权限,添加以下可执行权限即可
[root@localhost ~]# chmod +x  /etc/rc.d/rc.local
[root@localhost ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 507 Jun 12 11:01 /etc/rc.d/rc.local
#执行后,查看已经增加了可执行权限

想在系统启动后执行的命令可以添加到/etc/rc.d/rc.local文件
比如启动时同步系统时间

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
#同步系统时间
/usr/sbin/ntpdate cn.pool.ntp.org
Comments closed

发现大量的TIME_WAIT解决办法

netstat -ae|grep mysql

tcp        0      0 kiccleaf:46464      188.*.*.*:mysql    TIME_WAIT   root       0         
tcp        0      0 kiccleaf:42952      188.*.*.*:mysql    TIME_WAIT   root       0         
tcp        0      0 kiccleaf:46597      188.*.*.*:mysql    TIME_WAIT   root       0         
tcp        0      0 kiccleaf:45692      188.*.*.*:mysql    TIME_WAIT   root       0         
tcp        0      0 kiccleaf:44282      188.*.*.*:mysql    TIME_WAIT   root       0

—此处省略N行

tcp 0 0 kiccleaf:45692 188.*.*.*:mysql TIME_WAIT root 0
tcp 0 0 kiccleaf:44282 188.*.*.*:mysql TIME_WAIT root 0

发现系统存在大量TIME_WAIT状态的连接,通过调整内核参数解决:
vim /etc/sysctl.conf

编辑文件,加入以下内容:
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

然后执行 /sbin/sysctl -p 让参数生效。

net.ipv4.tcp_syncookies = 1 表示开启SYN Cookies。当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SYN攻击,默认为0,表示关闭;

net.ipv4.tcp_tw_reuse = 1 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;

net.ipv4.tcp_tw_recycle = 1 表示开启TCP连接中TIME-WAIT sockets的快速回收,默认为0,表示关闭。

net.ipv4.tcp_fin_timeout 修改系統默认的 TIMEOUT 时间

修改之后,再用
netstat -ae|grep mysql

到此突然间系统的性能提升了,访问的网站程序速度也越顺畅了。

Leave a Comment