yum -y install httpd 在线安装httpd
yum -y install php 在线安装PHP
vi /etc/httpd/conf/httpd.conf
AddDefaultCharset GB2312 添加GB2312为默认编码
安全配置
ServerTokens Prod 在出现错误页的时候不显示服务器操作系统的名称
ServerSignature Off 在错误页中不显示Apache的版本
<Directory "/var/www/icons"> 不在浏览器上显示树状目录结构
Options Indexes MultiViews 将Indexes删除
扩展配置
Options Includes ExecCGI FollowSymLinks 允许服务器执行CGI及SSI
AddHandler cgi-script .cgi .pl 允许扩展名为.pl的CGI脚本运行
AllowOverride All 变为此状态,允许.htaccess
php open_basedir 目录限制
方法一:在php.ini里配置
open_basedir = .:/tmp/
方法二:在Apache的VirtualHost里设置
php_admin_value open_basedir .:/tmp/
方法三:在Apache的Directory里设置
php_admin_value open_basedir .:/tmp/
Linux下Apache设置umask
在 /usr/local/apache/bin/envvars 或 /etc/sysconfig/httpd
添加 umask 000
semanage port -a -t http_port_t -p tcp [port] selinux允许apache监听其他端口
chkconfig httpd on 设置HTTP服务自启动
chkconfig --list httpd 检测是否开机启动
/etc/rc.d/init.d/httpd start 或 service httpd start 启动HTTP服务
yum -y install vsftpd 在线安装vsftpd
/etc/vsftpd/vsftpd.conf 配置文件
useradd -d [目录] -g ftp -s /sbin/nologin -M [用户名] 添加不允许ssh登陆的ftp用户
setsebool -P ftp_home_dir 1 配置selinux允许进入ftp_home
pasv_enable=YES
pasv_min_port=[MinPort]
pasv_max_port=[MaxPort]
/etc/ssh/sshd_config SSH配置
Protocol 2
ServerKeyBits 1024
PermitRootLogin no
PermitEmptyPasswords no
cat /etc/issue 查看系统版本
uname -a 查看内核版本
/etc/inittab 启动选项(文本或窗口)
service network restart 重启全部网卡
setup 修改ip 重启网卡生效
/etc/sysconfig/network-scripts/ifcfg-eth0 eth0配置文件
ifdown [设备名如eth0] 关闭eth0
ifup [设备名如eth0] 启动eth0
cp ifcfg-eth0 ifcfg-eth0:x x为0-255 一个网卡设置多个IP
修改ifcfg-eth0:x的DEVICE=eth0为DEVICE=eth0:x与IPADDR即可
ifconfig -a 查看ip
route -n 查看路由
route add -net [目标IP网络号] netmask [子网掩码] gw [网关ip地址] 添加路由
route del -net [目标IP网络号] netmask [子网掩码] gw [网关ip地址] 删除路由
/etc/resolv.conf 修改全局DNS
nameserver 8.8.8.8 #google域名服务器
如果要为网卡单独设置DNS
向网卡配置文件如/etc/sysconfig/network-scripts/ifcfg-eth0添加
PEERDNS=yes
DNS1=8.8.8.8
DNS2=8.8.4.4
/var/log/ 系统日志保存文件夹
/etc/syslog.conf 系统日志配置文件,配置完重启 service syslog restart
/etc/logrotate.conf 日志文件管理工具配置文件
iptables -L -n 查看防火墙规则
只对终端有效,Xwindows无效
who 查询在线用户
w 查询在线用户当前动作
last 查询曾登陆过的用户
who -a 查询终端pid
kill -9 [pid] 踢用户
id 查看该用户的UID、GID及所归属的用户组
id [name] 查看name用户的UID、GID及所归属的用户组
finger 查看当前登陆用户
finger [name] 查看name用户LoginTime、Name、Directory、Shell
groups 显示该用户所属的用户组
groups [GroupName] 查询用户组有哪些用户
pwconv 让/etc/passwd和/etc/shadow同步
grpconv 让/etc/group和/etc/gshadow同步
su 用户切换
newgrp 切换用户组
touch -c -m -t 201101011200 test.txt 修改时间
ls -la 查看隐藏文件
ls -ld 查看当前目录属性
tar -zcvf [文件或文件夹] 压缩
tar -zxvf [文件] 解压
rm -rf [文件或文件夹] 删除文件
cp [源文件] [目的文件] 复制文件
mv [源文件] [目的文件] 移动文件或者文件夹
chmod -R 777 [文件或文件夹] 设置权限包括子目录
diff [file1] [file2] 找出两个文件不同之处
file [file1] 显示文件类型
find / -iname [文件名] 全盘查找文件
find / -iname "*" | xargs grep '内容'
find / -type d -perm 777 快速查找可写目录
ln -s [目标文件夹或文件的绝对地址] [文件] 创建链接
whereis [程序名] 查询程序所在路径
cat /proc/cpuinfo | grep model 查看CPU型号
df 查看磁盘空间总占用
du 查看文件夹占用空间
top 查看CPU情况
free 查看内存使用量
ps 查看终端前台进程
ps -aux 查看终端后台进程
kill -9 [PID] 终止进程
history 查看shell记录
history -c 删除shell记录
cal 显示日期
hwclock --show 查看硬件时间
hwclock --set --date="月/日/年 时:分:秒" 设置硬件时间
hwclock --hctosys 将系统时间与硬件时间同步
date 查看系统时间
netstat -ant 显示TCP端口
netstat -i 查看网卡传送接收数据包
mii-tool -v 查看网卡信息
write [username] 跟在线的用户通讯
wall 广播给所有在线用户
fg 前台运行
& 或 bg 后台运行
jobs 后台运行清单
fdisk -l 打印当前的磁盘分区表
fdisk /dev/sd[x] m n p w
mkfs -t ext3 /dev/sd[x]1
mount /dev/sd[x]1 /mnt
tcpdump 抓取所有流量
tcpdump -i [eth0] 指定网卡设备
tcpdump {src、dst}host [hostname] 指定主机 来源、目标
tcpdump {src、dst}port [port] 指定端口 来源、目标
tcpdump -i [eth0] host [hostname] and port [port] 指定网卡、主机、端口
./configure 配置
make 编译
make install 安装
make clean 删除安装时产生的临时文件
make uninstall 卸载(不一定提供该功能)
rpm -ivh [软件包名] RPM安装软件
--force 忽略软件包及文件的冲突
--nodeps 不检查依赖性关系
--nopgp 不校验PGP签名
rpm -e [软件名] RPM卸载软件
安装前查询
rpm -qpi [绝对路径文件名.rpm] 查询rpm包的相关信息
rpm -qpl [绝对路径文件名.rpm] 查询rpm包包含哪些文件 (显安装路径)
rpm -qpR [绝对路径文件名.rpm] 查询RPM软件包依赖哪些文件
rpm -qpc [绝对路径文件名.rpm] 查看配置信息
安装后查询
rpm -qf [绝对路径如/etc/rc.d/init.d/sshd] 查询属于哪个软件包 (显逻辑包名)
rpm -qa |more 查询全部已安装的软件包
rpm -qa |grep [逻辑包名||不完整] 查询该包是否安装 (显完整包名)
rpm -qi [逻辑包名] 查询rpm包的相关信息
rpm -ql [逻辑包名] 查询rpm包包含哪些文件 (显安装路径)
rpm -qR [逻辑包名] 查询RPM软件包依赖哪些文件
rpm -qd [逻辑包名] 查看document安装在哪里
rpm -qc [逻辑包名] 查看配置信息
yum install [软件名] yum安装
yum remove [软件名] yum卸载
yum check-update [软件名] 查询可更新的软件 (去掉软件名查询所有)
yum update [软件名] 更新指定软件 (去掉软件名更新所有)
yum list [软件名] 列出资源库中可安装或更新及已经安装的rpm包 (去掉软件名列出所有)
yum search [软件名] 搜索匹配特定字符的rpm包
yum info updates 列出资源库中所有可更新的rpm包的信息
yum info installed 列出已经安装的所有的rpm包的信息
yum info extras 列出已经安装的但是不包含在资源库中的rpm包的信息
yum info [软件名] 列出指定软件的rpm包信息
apt-get install [软件名] apt-get在线安装
./[名称.bin] bin二进制安装
dpkg -i [软件包名] deb安装软件
dpkg -e [软件名] deb卸载软件
/etc/rc.d/rc.local 开机启动配置文件 加入启动命令即可 如 /usr/local/apache/bin/apachectl start
/etc/rc.d/init.d 该文件夹下为系统服务 把程序放进去然后编辑程序 如 #chkconfig:345 61 61 #description:Apache httpd
./configure --prefix=/usr/local/apache --enable-so 安装apache
make
make install
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd 开机启动
编辑/etc/rc.d/init.d/httpd
在#!/bin/bash下添加
#chkconfig:345 61 61 //345在哪些运行级别启动,启动序号(S61),关闭序号(K61)
#description:Apache httpd //此行必写,描述服务
chkconfig --add httpd 添加系统服务
编辑/usr/local/apache/conf/httpd.conf 配置apache
#ServerName www.example.com:80 改成 ServerName *:80
删除内<Directory />中Options选项的 Indexes 禁止目录显示
DirectoryIndex index.html index.php
每个虚拟主机独立用户
http://mpm-itk.sesse.net/
mkdir /tmp/apache-itk
cd /tmp/apache-itk
tar -zxvf httpd-xxxxxx.tar.gz
cd httpd-xxxxxx
patch -p1 < ../apache2.2-mpm-itk-xxxxxxx.patch
autoconf
./configure --with-mpm=itk
make ; make install
<VirtualHost *:80>
<IfModule mpm_itk_module>
AssignUserId [name] [group]
</IfModule>
</VirtualHost>
/var/lib/mysql 数据库存储目录
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 设置字符集
在[client]和[mysqld]下添加
default-character-set=utf8
show variables like 'collation_%'; 查看字符集设置
show variables like 'character_set_%';
use mysql 修改root密码
update user set password=password("新密码") where user="root";
delete from user where user="";
flush privileges;
show databases;
use 数据库名;
show tables;
describe 表名;
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/include/mysql --enable-mbstring=all
cp php.ini-development /usr/local/php/lib/php.ini
修改date.timezone=PRC
修改short_open_tag=On
添加zend_extension=/usr/local/apache/modules/ZendGuardLoader.so 路径自行修改,ZendGuardLoader到zend下载
编辑/usr/local/apache/conf/httpd.conf
添加AddType application/x-httpd-php .php
./configure --prefix=/usr/local/php --with-curl --with-gettext --with-bz2 --with-mysql -enable-shmop --enable-calendar --with-openssl --enable-ftp --with-openssl --with-zlib --enable-exif --with-gmp --enable-sysvmsg --enable-sockets --enable-wddx --with-xsl --with-mcrypt=/usr/local/libmcrypt --with-mysqli --with-mime_magic --with-pdo-mysql --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-apxs2=/usr/sbin/apxs --without-sqlite --enable-mbstring --enable-so
make
-------------------
useradd nobody
mkdir /usr/share/empty/
mkdir /var/ftp/
useradd -d /var/ftp ftp
-------------------
make install
cp vsftpd.conf /etc/
cp RedHat/vsftpd.pam /etc/pam.d/ftp
vi /etc/vsftpd.conf
chroot_local_user=YES 限制用户跨目录
userlist_enable=YES 只允许特定的用户登陆ftp
userlist_deny=NO
userlist_file=/etc/vsftpd.userlist
新建/etc/vsftpd.userlist文件 把用户名写入
pasv_enable=YES 设置PASV模式
pasv_min_port=[MinPort]
pasv_max_port=[MaxPort]
listen_port=5555 修改端口
echo "/usr/local/sbin/vsftpd &" >> /etc/rc.local 开机启动vsftpd
/etc/yum.repos.d/CentOS-Base.repo 修改yum镜像站点 centos.ustc.edu.cn
注释所有 mirrorlist=
允许所有 baseurl= 并且把 mirror.centos.org 修改成 centos.ustc.edu.cn
修改所有 gpgkey=http://centos.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-5
××× 端口1723
下载pptpd http://poptop.sourceforge.net/yum/stable/packages/
安装pptpd rpm -ivh pptpd-*.rpm
主要相关配置文件
/etc/pptpd.conf
/etc/ppp/options.pptpd
/etc/ppp/chap-secrets
编辑 /etc/pptpd.conf
localip 88.88.88.88 配置连接IP地址
remoteip 192.168.99.1-255 配置分配IP网段
编辑 /etc/ppp/options.pptpd
ms-dns 配置DNS
编辑 /etc/ppp/chap-secrets
guet pptpd sec * 配置用户 账户guet密码sec
编辑 /etc/sysctl.conf
net.ipv4.ip_forward = 1 打开永久转发功能
sysctl -p 执行立即生效
chkconfig pptpd on 加入开机启动
service pptpd restart 重启pptpd
VNC端口为5900-
编辑 .vnc/xstartup
去掉#注释
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
在twm &上面添加
gnome-session gnome
vncserver 创建vnc桌面
编辑/etc/sysconfig/vncservers 开机自动创建vnc桌面
VNCSERVERS="1:root 2:root"
VNCSERVERARGS[1]="-geometry 1024x768"
VNCSERVERARGS[2]="-geometry 1024x768"
yum install dhcp 安装DHCP服务器
yun install dhcp-devel
cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
编辑/etc/dhcpd.conf
单网段
subnet 客户机获得的IP地址的网段
netmask 客户机获得的IP地址的子网掩码
options domain-name 为客户机指定DNS服务器名称
options domain-name-servers 为客户机指定DNS服务器IP地址
options routers 为客户机指定默认网关的IP地址
options subnet-mask 默认网关IP地址的子网掩码
range 用于说明客户机所得到的IP地址的范围
default-lease-time 指定默认地址租约(秒为单位)
max-lease-time 指定最大地址租约(秒为单位)
host 为特定的DHCP客户机提供IP网络参数
hardware 特定客户机的MAC地址
fixed-address 为特定客户机指定IP地址
多网段
DHCP服务器
把多个subnet{}放到shared-network dhcp{}里
DHCP中继服务器
编辑/etc/sysconfig/dhcrelay
INTERFACES="eth1 eth2" 向接口提供dhcp
DHCPSERVERS="192.168.1.1" dhcp服务器IP
service dhcrelay restart
DNS 端口53
yum install bind*
yum install caching-nameserver
cd /var/named/chroot/etc/
cp -p named.caching-nameserver.conf named.conf
vi named.conf
listen-on port 53 { any; };
allow-query { any; };
match-clients { any; };
match-destinations { any; };
vi named.rfc1912.zones
zone "test.com" IN {
type master;
file "test.com.zone";
allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "192.168.1.zone";
allow-update { none; };
};
cd /var/named/chroot/var/named/
cp -p localdomain.zone test.com.zone
cp -p named.local 192.168.1.zone
vi test.com.zone
添加 www IN A 192.168.1.1
ftp IN A 192.168.1.2
vi 192.168.1.zone
修改 IN NS test.com.
添加 1 IN PTR www.test.com.
2 IN PTR ftp.test.com.
保存为squid.conf 替换/etc/squid/squid.conf
#squid主机名称
visible_hostname squid.guetsec.com
#ip、主机名
cache_peer 192.168.9.2 parent 80 0 no-query originserver name=www
cache_peer 88.88.88.88 parent 80 0 no-query originserver name=web
#主机名对应的域名
cache_peer_domain www www.guetsec.com
cache_peer_domain web web.guetsec.com
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow all
icp_access allow all
#访问权限的控制 主机名
cache_peer_access www allow all
cache_peer_access web allow all
#监听端口 支持虚拟机
http_port 80 vhost
hierarchy_stoplist cgi-bin ?
access_log /var/log/squid/access.log squid
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
iptables开放内网FTP
modprobe ip_nat_ftp 临时加载 iptables重启丢失
编辑/etc/sysconfig/iptables-config 添加 ip_nat_ftp 永久加载
IPTABLES_MODULES="ip_conntrack_netbios_ns ip_conntrack_ftp ip_nat_ftp"
iptables -t nat -A PREROUTING -i eth0 -d 88.88.88.88 -p tcp --dport 21 -j DNAT --to 192.168.9.2
iptables开放内网SSH
iptables -t nat -A PREROUTING -i eth0 -d 88.88.88.88 -p tcp --dport 22 -j DNAT --to 192.168.9.2
允许内网上网 域名解析需要iptables允许tcp53 udp53
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.9.0/24 -j MASQUERADE
/etc/sysconfig/iptables 防火墙规则配置文件 重启起效
getenforce 查看SELinux模式
sestatus 查看SELinux政策
setenforce [0|1] 将SELinux在permissive与Enforcing之间切换 无需重启生效
编辑/etc/selinux/config
SELINUX=[enforcing|disabled|permissive] 设置SELinux模式
id -Z 检查帐号的安全上下文
ps -Z 检查进程的安全上下文
ls -Z 检查文件与目录的安全上下文
chcon -R -u [user] -r [role] -t [type] [文件或目录] 修改文件/目录安全上下文
getsebool -a 查看selinux全部策略值
getsebool 名称 查看selinux指定策略值
setsebool -P 名称=[0|1] 设置selinux指定策略值
Crontab 定时任务管理
crontab -e
01 03 * * * /root/mysql.sh
0~59 表示分
1~23 表示小时
1~31 表示日
1~12 表示月份
0~6 表示星期(其中0表示星期日)
转载于:https://blog.51cto.com/petermis/1194787