分类 Linux 下的文章

EPEL(Extra Packages for Enterprise Linux) 是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS等提供高质量软件包的项目。装上了 EPEL,就像在 Fedora 上一样,可以通过 yum install 软件包名,即可安装很多以前需要编译安装的软件、常用的软件或一些比较流行的软件,比如现在流行的nginx, openvpn等等,都可以使用EPEL很方便的安装更新。

安装EPEL源

CentOS/RHEL 5 :

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm

CentOS/RHEL 6 :

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

CentOS/RHEL 7 :

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Ok,安装完毕。

使用EPEL源安装软件
现在就可以执行:yum install 软件包名进行安装了,nginx、openvpn、htop、ncdu等等一些常用的软件都灰常简单的装上了。

原文:http://www.vpser.net/manage/centos-rhel-linux-third-party-source-epel.html

404

如图,有时候我们检查Apache日记的时候会发现大量这样的单IP或多IP在短时间内请求大量不存在的目录/文件,Apache返回404状态,这不仅消耗服务器资源还可能有安全隐患。我们可以通过CSF防火墙解决,CSF可以根据返回状态次数来屏蔽请求IP访问,相关设置和说明:

# This option will keep track of the number of "File does not exist" errors in
# HTACCESS_LOG. If the number of hits is more than LF_APACHE_404 in LF_INTERVAL
# seconds then the IP address will be blocked
#
# Care should be used with this option as it could generate many
# false-positives, especially Search Bots (use csf.rignore to ignore such bots)
# so only use this option if you know you are under this type of attack
#
# A sensible setting for this would be quite high, perhaps 200
#
# To disable set to "0"
LF_APACHE_404 = "200"

# If this option is set to 1 the blocks will be permanent
# If this option is > 1, the blocks will be temporary for the specified number
# of seconds
LF_APACHE_404_PERM = "3600"

scp是有Security的文件copy,基于ssh登录。操作起来比较方便,适合大文件的传输等。

比如要把当前服务器的一个文件copy到远程另外一台主机上,可以如下命令。
注意:-rp 可循环拷贝目录,参数-p 1111为端口,默认ssh 22端口可不加该参数

scp /home/daisy/full.tar.gz root@111.111.111.111:/home/root/

把远程服务器的文件copy到当前服务器

scp root@111.111.111.111:/home/daisy/full.tar.gz /home/root/

root@111.111.111.111:/home/daisy/full.tar.gz 为远程服务器的信息与文件位置
/home/root/ 为当前服务器保存目录

部分参考:http://blog.csdn.net/cncdns/article/details/8809784

环境:centos6.6,带有CSF的服务器;该安装方法也适用于XEN、KVM虚拟化结构VPS

首先编辑 /etc/csf/csf.conf ,打开1723、1356端口;

vi /etc/csf/csfpre.sh

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -A INPUT -p gre -j ACCEPT
iptables -A OUTPUT -p gre -j ACCEPT
iptables -A FORWARD -i ppp+ -o eth1 -p ALL -j ACCEPT
iptables -A FORWARD -i eth1 -o ppp+ -p ALL -j ACCEPT
iptables -t nat -A POSTROUTING -s 172.16.22.0/24 -j SNAT --to-source `ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'NR==1 { print $1}'`
iptables -A FORWARD -p tcp --syn -s 172.16.22.0/24 -j TCPMSS --set-mss 1356

创建 csfore.sh 设置防火墙开启转发等;注意代码中 eth1 为公网IP网卡

创建安装PPTP一键脚本
vi /root/pptpd6.sh

yum remove pptpd ppp -y
iptables --flush POSTROUTING --table nat
iptables --flush FORWARD
rm -f /etc/pptpd.conf
rm -f /etc/ppp
arch=`uname -m`
yum -y install make libpcap iptables gcc-c++ logrotate tar cpio perl pam tcp_wrappers dkms kernel_ppp_mppe ppp
wget https://www.cnweed.com/usr/uploads/2015/08/pptpd-1.4.0-1.el6.$arch.rpm
rpm -Uvh pptpd-1.4.0-1.el6.$arch.rpm

mknod /dev/ppp c 108 0
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "mknod /dev/ppp c 108 0" >> /etc/rc.local
echo "echo 1 > /proc/sys/net/ipv4/ip_forward" >> /etc/rc.local
echo "localip 172.16.22.254" >> /etc/pptpd.conf
echo "remoteip 172.16.22.1-253" >> /etc/pptpd.conf
echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd
echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd

pass=`openssl rand 6 -base64`
if [ "$1" != "" ]
  then pass=$1
fi

echo "vpn pptpd ${pass} *" >> /etc/ppp/chap-secrets

#iptables -t nat -A POSTROUTING -s 172.16.22.0/24 -j SNAT --to-source `ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'NR==1 { print $1}'`
#iptables -A FORWARD -p tcp --syn -s 172.16.22.0/24 -j TCPMSS --set-mss 1356
#service iptables save
#chkconfig iptables on
chkconfig pptpd on
#service iptables restart
service pptpd start

echo ""
echo "VPN service installed successfully, your VPN username is vpn, VPN password is ${pass}"
echo "Please visit: http://www.cnweed.com"
echo ""

保存。然后 csf -r 重启CSF防火墙,以及sh /root/pptpd6.sh 安装脚本

chmod 755 /root/pptpd6.sh
csf -r
sh /root/pptpd6.sh

注:如果ip_forward没有打开,可以直接修改/etc/sysctl.conf

net.ipv4.ip_forward=1

修改之后运行 sysctrl -p 使其生效

一、安装hdparm

yum install hdparm -y

二、评估读取
SSD 硬盘,请使用hdparm命令进行读取测试。

hdparm -t /dev/sda1 L

SSH执行以上命令,可使用hdparm评估SSD的读取速率。
注意,“/dev/sda1”指的是对应磁盘的驱动号,请执行“fdisk -l”查看。

032A03351-0

转载自:http://linux.it.net.cn/CentOS/server/2014/0226/332.html

In this section, we will analyze real-world examples of programs that
call the gethostbyname*() functions, but we first introduce a small test
program that checks whether a system is vulnerable or not:

[user@...ora-19 ~]$ cat > GHOST.c << EOF
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#define CANARY "in_the_coal_mine"

struct {
  char buffer[1024];
  char canary[sizeof(CANARY)];
} temp = { "buffer", CANARY };

int main(void) {
  struct hostent resbuf;
  struct hostent *result;
  int herrno;
  int retval;

  /*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
  size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
  char name[sizeof(temp.buffer)];
  memset(name, '0', len);
  name[len] = '\0';

  retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);

  if (strcmp(temp.canary, CANARY) != 0) {
    puts("vulnerable");
    exit(EXIT_SUCCESS);
  }
  if (retval == ERANGE) {
    puts("not vulnerable");
    exit(EXIT_SUCCESS);
  }
  puts("should not happen");
  exit(EXIT_FAILURE);
}
EOF

[user@...ora-19 ~]$ gcc GHOST.c -o GHOST

On Fedora 19 (glibc-2.17):

[user@...ora-19 ~]$ ./GHOST
vulnerable

On Fedora 20 (glibc-2.18):

[user@...ora-20 ~]$ ./GHOST
not vulnerable

修复漏洞
升级glibc库

RHEL/CentOS : sudo yum update glibc
Ubuntu : sudo apt-get update ; sudo apt-get install libc6

参考:http://www.openwall.com/lists/oss-security/2015/01/27/9

Server Shield是一款轻量级的系统保护和强化工具

它的功能包括:

Firewall Hardening 防火墙强化
TCP Hardening TCP强化
Data Leakage Protection 防泄保护
ICMP/Ping Flood Protection ICMP/Ping攻击保护
Rootkit Protection Rootkit保护
DoS Protection DDOS保护
Spoof Protection Spoof保护
Bogus TCP Protection Bogus TCP保护
SYN Flood Protection 洪水攻击保护
FTP/SSH 暴力破解保护
等……

依赖软件

yum-security
iptables
net-tools
sed
gawk
git

安装

git clone https://github.com/bluedragonz/server-shield

cd server-shield;chmod +x sshield;mv sshield /etc/init.d

/etc/init.d/sshield start    

项目地址:https://github.com/bluedragonz/server-shield

yum -y install iotop  或
sudo apt-get install iotop

官网:http://guichaz.free.fr/iotop/

io

用法 iotop -参数

–version 查看版本信息的

-h, –help 查看帮助信息的

-o, –only 只显示在划硬盘的程序
-b, –batch 批量处理 用来记录日志的

-n NUM 设定循环几次

-d SEC, –delay=SEC 设定显示时间间隔

其中按 r 是反顺序排列,按 o 为动态切换,按q退出。

1.选择Free行,再点击Create按钮;
1

2.选择“Create Partition”选项中的“Standard Partition”,然后点击Create;
2

3.在挂载点上选择“/boot”,文件系统类型中选择“ext4”,大小填写100(单位为MB),然后在“Additional Size Options”区域选择“Fixed size”选项,最后再勾选“Force to be a primary partition”,最最后点击OK按钮;
3

4.选择剩下来的Free行,点击Create按钮,在弹出的对话框中选择“Create LVM”选项中的“LVM Physical Volume”单选按钮,最后单击Create;
4

5.在弹出的“Add Partition”对话框中,在“Additional Size Options”区域选择“Force to be a primary size”选项,最后再勾选“Force to be a primary partition”,最最后点击OK按钮;
5

6.选中sda2这一行,单击“Create”按钮,(千万不要单击“Edit”,不然的话,会回到Standard Partition模式)
6

7.在弹出的“Create Storage”对话框中,选择“Create LVM”区域中的“LVM Volume Group”选项,最后单击Create按钮;
7

8.在弹出的“Make LVM Volume Group”对话框中,指定“Volume Group Name”的名称(不能包含空格)和“Physical Extent”的大小,默认为4M,最后点击OK按钮;(也可以在这里直接点击Add按钮添加LVM logical Volume)
8

9.单击上图中的Add按钮,在弹出的“Create Storage”中选择“Create LVM”区域中的“LVM Logical Volume”,最后单击Create按钮;
9

10.在弹出的“Make Logical Volume”对话框中指定挂载点、文件系统类型、逻辑卷的名字和卷的大小,最后单击OK按钮;(如果文件系统类型为swap,则没有挂载点)
10

11.接着挂载根(/);
11

12.最后分区图如下:
12

13.挂载所有分区后的截图如下:
13

参考:http://www.newsky.net.cn/help/Show.asp?id=13