安装centos
1、插入光盘,启动,可以选择第一项进行安装2、根据实际需求,一般会选择skip3、选择语言“简体中文”4、选择第一项5、设置主机名字,使用默认6、选择时区7、设置超级用户密码,这一步一定要小心,记住你设定的密码8、初次安装,选择第一项
9、安装一个桌面,方便操作10、创建一个普通用户,要设置密码11、设置时间
1、插入光盘,启动,可以选择第一项进行安装2、根据实际需求,一般会选择skip3、选择语言“简体中文”4、选择第一项5、设置主机名字,使用默认6、选择时区7、设置超级用户密码,这一步一定要小心,记住你设定的密码8、初次安装,选择第一项
9、安装一个桌面,方便操作10、创建一个普通用户,要设置密码11、设置时间
解决方案 »
- vs2017 WSL调试Ubuntu14.04 发生错误
- 腾讯云centos的问题,每次网页请求数据库,linux都会建立一个新连接
- 分享一款个人开发的万年历。支持libc.so 2.5+ 32/64系统
- 使用DD恢复IMG文件遇到错误
- 关于git的问题请教
- linux关于开机跳过密码和ftp的问题,百度了很多都没解决,不知道咋办了,求助
- centos7桌面版更新glibc-2.18导致启动黑屏,求救。
- 请教下各位老铁
- 为啥我反向解析错误,
- Makefile的文件编译顺序问题
- Vmware虚拟机卸载Ubuntu如何重新安装
- 在虚拟机上安装好了Linux系统,但是用它自带的火狐浏览器上不了网啊,咋办啊,还望各位大神不吝赐教
virtualbox里新安装的Centos 7 的分辨率默认的应该是800*600。 如果是‘最小化安装’的Centos7 进入的就是命令模式 。如果安装的是带有GUI的Centos7 可在桌面模式下 Ctrl+Alt+F1/F2/F3/F4 组合件来切换命令模式和桌面模式。进入命令模式 开始修改操作: 输入下面命令:
[root@localhost ~]# gedit /boot/grub/grub.conf
1、修改grub.cfg文件: 在标注地方末尾加上“vga = ask“,然后保存grub.cfg文件。
vga = ask意味着每次开始的时候都会询问分辨率。如果确定了,也可以将ask改成具体的分辨率指(下文图示)。
2、重启reboot,会看到下面界面:
根据自己的屏幕选择合适的分辨率了,输入分辨率代码,Enter键确认。 例如我的电脑选择最后一项,输入代码“34c”
开机等待时间
可以通过修改文件“/boot/grub/menu.lst”,来配置开机等待时间,其中timeout就是开机等待时间,建议保持在2s以上
[root@localhost ~]# gedit /boot/grub.menu.lst
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.i686)
默认启动方式
1、可以通过配置文件“/etc/inittab”来修改默认的启动方式,打开配置文件可以看到如下的内容
[root@localhost ~]# gedit /etc/inittab
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
最后一行的就是默认的启动方式,我们可以将5改成1,这样就不会启动图形界面了。2、关于id后面的序号,说明如下
0
关机
1
单用户模式
2
多用户命令模式,无网络
3
多用户命令模式,有网络
4
保留
5
图形界面的多用户模式
6
重启
ps:在安装了图形界面的系统中,默认启动图形界面。
开启启动数字键盘
1、修改配置文件“/etc/rc.local”,改为如下
[root@localhost ~]# gedit /etc/rc.local
touch /var/lock/subsys/local
INITTY=/dev/tty[1-8]
for tty in $INITTY; do
setleds -D +num < $tty
done
2、保存退出即可
登录前后信息
Centos登录前默认只能显示操作系统和内核版本,登录后不显示任何信息。用户可以自由的添加一些信息,在登录前或者登录之后显示
1、登录前
修改配置文件“/etc/issue“,在最后加一句welcome to centos,保存之后退出,
[root@localhost ~]#vim /etc/issue
CentOS release 6.5 (Final) // issue文件
Kernel \r on an \m
welcome centos
重新登录账户,可以看到如下结果
CentOS release 6.5
Kernel 2.6.32
welcome to centos //登录前显示的信息
localhost login
2、登录后
修改文件“/etc/motd”,输入你的内容,例如“already login”
[root@localhost ~]# vim /etc/motd
already login
保存,重新登录,看到如下
Localhost login : root
Pass
Last login: Fri Aug
already login
自动纠错路径
在命令行输入路径的时候,难免会出错。centos提供了一个小技巧:可以纠正错误的路径,但是出错的内容不能太多。
1、修改配置文件“/etc/bashrc”,在最后追加一句话
[root@localhost ~]# gedit /etc/bashrc
shopt -s cdspell
2、保存之后重新登录,测试一下
[root@localhost ~]# cd /medai
/media
ps:这种当时只适用于出错少的情况
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ 密码:n7bk
本地yum可以实现各种包的快速安装,避免漫长的下载过程
1、找一个centos的安装包,将其挂载的系统中
[root@localhost ~]# mount –t iso9660 –loop centos-i386.iso /mnt2、拷贝所有的内容到某个指定的文件夹,例如“/wj/centos-img/”
[root@localhost ~]# mkdir /wj/centos-img
[root@localhost ~]# cp /mnt /wj/centos-img3、跳转的yum的配置目录“/etc/yum.repos.d”
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Media.repo
CentOS-Debuginfo.repo CentOS-Vault.repo4、将配置目录下的所有配置文件做备份
[root@localhost yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# mv CentOS-Media.repo CentOS-Media.repo.bak
[root@localhost yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak
[root@localhost yum.repos.d]# mv CentOS-Vault.repo CentOS-Vault.repo.bak5、编辑其中一个配置文件,这里用的是CentOS-Base.repo
[root@localhost yum.repos.d]# vi CentOS-Base.repo
[base]
name=CentOS-Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os 这句话前面加#,相当于注释掉
baseurl=file:///wj/centos-img/ 这里是centos包的路径,上面已经拷贝到/wj/centos-img
gpgcheck=1
gpgkey=file:///wj/centos-img/RPM-GPG-KEY-CentOS-6 注意这里的路径也有改变
enable=1 这里是1,代表使能当前的配置6、清除yum的缓存
[root@localhost ~]# yum clean metadata
[root@localhost ~]# yum clean all7、测试,查看当前yum配置是否成功
[root@localhost ~]# yum list
seahorse-plugins.i686 2.28.1-2.el6 base
seekwatcher.noarch 0.12-5.el6 base
selinux-policy-doc.noarch 3.7.19-231.el6 base
selinux-policy-minimum.noarch 3.7.19-231.el6 base
1、通过命令“getenforce”获取selinux状态,
[root@localhost ~]# getenforce
Enforcing //enforceing代表开启, [root@localhost ~]# getenforce
Permissive // permissive代表警告 [root@localhost ~]# getenforce
Disabled //disabled代表关闭
[root@localhost ~]#2、在终端输入命令即可关闭selinux,此种做法只是暂时关闭,重启之后没有效果
[root@localhost ~]# setenforce 0 //关闭
[root@localhost ~]# getenforce
Permissive [root@localhost ~]# setenforce 1 //开启
[root@localhost ~]# getenforce
Enforcing 3、通过配置文件“/etc/sysconfig/selinux”来修改selinux状态,此种做法需要重启机器
[root@localhost ~]# gedit /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled4、通过修改“/boot/grub/menu.lst”来关闭selinux,这样每次开机都不会启动selinux
[root@localhost ~]# gedit /boot/grub/menu.lst
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.i686)
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.i686 ro root=/dev/mapper/VolGroup-lv_root nomodeset rd_NO_LUKS rd_NO_MD rd_LVM_LV=VolGroup/lv_swap crashkernel=auto vga=ask LANG=zh_CN.UTF-8 rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet selinux=0
initrd /initramfs-2.6.32-431.el6.i686.img
用户可以设置某项服务开机启动或者关闭,有图形界面和命令两种方式1、图形界面
1)在终端输入命令setup,在弹出的界面选择“系统服务”
2)也可以直接在终端输入命令“ntsysv”,得到如下界面
3)通过空格来修改开启或者关闭,上下左右键移动,tab键回到“确定”或者“取消”,回车确认。2、命令方式
1)通过命令“chkconfig”来设置服务的默认启动或者关闭状态,该命令的用法如下
chkconfig --list
查看所有服务的启动状态
chkconfig –list 服务名
查看指定服务的启动状态
chkconfig –add 服务名
增加指定的服务
chkconfig –del 服务名
删除指定的服务
chkconfig –level num(0~6) 服务名 on/off
设置指定服务在某个level的启动状态
2)查看所有服务的启动状态
[root@localhost ~]# chkconfig --list
NetworkManager 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
abrt-ccpp 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭
abrtd 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭
acpid 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
atd 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭
auditd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
autofs 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭
3)以nfs服务为例,查看该服务在每个level的启动状态
[root@localhost ~]# chkconfig --list nfs
nfs 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
4)设置nfs服务在level5开机启动,并查看结果
[root@localhost ~]# chkconfig --level 5 nfs on
[root@localhost ~]# chkconfig --list nfs
nfs 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:启用 6:关闭
5)每个level的意义
0,关机
1,单用户模式
2,多用户命令模式,无网络
3,多用户命令模式,有网络
4,保留
5,图形界面的多用户模式
6,重启
你那个word的密码是多少
1、禁用ipv6很简单,只需要在配置文件“/etc/modprobe.d/disable-ipv6.conf”中写入“install ipv6 /bin/true”,之后重启系统
[root@localhost ~]# echo "install ipv6 /bin/true">/etc/modprobe.d/disable-ipv6.conf
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:14:33:57
inet addr:192.168.0.108 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:30 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3891 (3.7 KiB) TX bytes:2134 (2.0 KiB)
2、如果要启用ipv6,那么只要删除配置文件即可。
ps:上面提到的配置文件,其本身是不存在的,我们自己起一个名字,系统重启的时候回加载“/etc/modprobe.d”目录下的配置文件禁止ping
有些时候为了保护主机,会禁止其他机器对主机进行ping操作。Ping命令用的是ICMP协议,只要禁用ICMP协议,那么ping方法就无法检测这台主机。关于ICMP协议的配置文件是“/proc/sys/net/ipv4/icmp_echo_ignore_all”,向此文件写入1,就可以禁止ICMP,写入0开启ICMP。 此操作不需要重启网络服务
1、查看ICMP,从下面的结果可以看到,当前默认是允许ping
[root@localhost ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all
02、禁止ICMP
[root@localhost ~]# echo "1">/proc/sys/net/ipv4/icmp_echo_ignore_all
[root@localhost ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all
13、开启ICMP
[root@localhost ~]# echo "0">/proc/sys/net/ipv4/icmp_echo_ignore_all
[root@localhost ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all
0
配置ip
1、启动网卡
1)网络配置文件 /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# gedit /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 网卡名字
HWADDR=08:00:27:14:33:57 mac地址
TYPE=Ethernet 设备类型
UUID=b8b1216e-1570-4e0e-bb96-7666ddf0b707 唯一ID
ONBOOT=no 是否开机启动
NM_CONTROLLED=yes
BOOTPROTO=dhcp 启动的时候使用dhcp
2)修改网卡开机启动
ONBOOT=yes 开机启动
3)重启网络服务,修改完网卡配置文件之后,只有重启才能生效
[root@localhost ~]# service network restart
Centos默认的是使用dhcp服务,自动分配ip地址2、配置的固定ip地址
1)添加ipaddr
IPADDR=192.168.0.250
2)添加NETMASK
NETMASK=255.255.255.0
3)添加GATEWAY
GATEWAY=192.168.0.1
4)添加DNS
DNS1=119.29.29.29
5)重启网络服务
[root@localhost ~]# service network restart
ps:上述配置中,严格区分大小写。Dns配置好之后,可以在/etc/resolv.conf文件中看到,如下:
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 119.29.29.293、图形界面配置ip
用户可以通过图形界面来修改ip,这样避免了复杂的命令,更加容易配置。
1)在终端输入“setup”命令,弹出如下窗口,选择“网络配置”2)选择DNS配置3)eth0就是第一块网卡,选择它就可以配置其ip4)取消dhcp,这样就可以配置ip以及dns5)选择dhcp,这样ip就不能配置了6)不管选择哪种方式,记得保存
这个程序读取diff的输出,并显示每个文件的插入、删除和修改的直方图。Diffstat是一个用于检查大型复杂修补程序文件的程序。它从包含diff输出的一个或多个输入文件中读取,生成针对引用的每个文件更改的总行的直方图。如果输入文件名以.bz 2、.gz、.lzma、.z或.z结尾,Diffstat将通过管道从相应的程序读取未压缩数据。它还可以根据标准输入的管道文件推断压缩类型。
Diffstat识别来自diff的最流行的输出类型:
unified,修补程序首选。
context,最好的可读性,但不太紧凑。
default,不是很好,但很容易产生。 Diffstat检测由diff输出的行,以判断比较了哪些文件,然后在第一列中计数表示更改类型(插入、删除或修改)的标记。这些在直方图中显示为“、”-“和”!“字符。如果命令行上没有指定文件名,Diffstat将读取标准输入中的差异。
此命令的适用范围:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。1、语法
diffstat [options] [file-specifications]2、选项列表
-b
忽略diff中的“二进制文件XXX和YYY不同”匹配的行
-c
在每一行输出前加上“#”,使其成为shell脚本的注释行。
-D destination
指定一个目录,其中包含可作为应用差异的结果而引用的文件。Diffstat将计算相应文件中的行数(在通过-p选项调整名称之后),以获得每个文件中的总行数。
-e file
将标准错误重定向到文件
-f format
指定直方图的格式:
0,为了简洁,它只显示值和一个直方图代码insert (+),delete (-)或modify (!)。
1,正常格式。
2,用点填充直方图。
4,使用直方图打印每个值。
任何非零值都会给出直方图。点和个别值可以结合在一起,例如-f6给出两者。
-h
显示帮助信息并且退出
-k
禁止合并报表中的文件名
-l
只列出文件名。不生成直方图。
-m
从修补程序文件的每个“块”中合并插入/删除计数,以接近修改行的计数
-n number
指定用于文件名的最小宽度。如果不指定这一点,Diffstat在去掉常见前缀后使用最长文件名的长度。
-N number
指定用于文件名的最大宽度。超过此限制的名称在左侧被截断。如果您没有指定此选项,下面将检查-n选项。
-o file
将标准输出重定向到文件
-p number
重写删除公共路径名的逻辑,模拟修补程序“-p”选项。
-q
抑制空差异的“0文件更改”消息
-r code
提供直方图中显示的数据的可选舍入,而不是通过错误调整截断数据:
0,是默认的。不执行舍入操作,但累积错误将添加到下列中。
1,舍入数据。
2,对数据进行舍入并调整直方图,以确保在有任何差异的情况下显示某些内容,即使这些差异通常被四舍五入为零。
-S source
这类似于-D选项,但指定了一个可以找到原始文件(在应用差异之前)的位置。
-t
重写直方图,生成逗号分隔值的输出。
-u
禁止对报表中的文件名进行排序。
-v
显示进度,例如,如果输出重定向到文件,则将进度消息写入标准错误
-V
显示版本号,并且退出
-w number
指定直方图的最大宽度。直方图将永远不会小于10列,以防文件名过大。3、环境变量
Diffstat运行在可移植的UNIX环境中。您可以通过设置与输入文件名称相对应的环境变量来覆盖用于解压缩输入文件的程序的编译路径。然而,Diffstat假设生成的程序使用相同的命令行选项,例如“-c”来解压缩到标准输出。
DIFFSTAT_BZCAT_PATH
DIFFSTAT_BZIP2_PATH
DIFFSTAT_COMPRESS_PATH
DIFFSTAT_GZIP_PATH
DIFFSTAT_LZCAT_PATH
DIFFSTAT_PCAT_PATH
DIFFSTAT_UNCOMPRESS_PATH
DIFFSTAT_ZCAT_PATH
4、实例
统计差异信息
[root@localhost wj]# diff 1.c 2.c
1c1
< asd
---
> add
3,4c3,4
< dfg
< ass
---
> dsgf
> sss
[root@localhost wj]# diff 1.c 2.c |diffstat -f 2
unknown | 6 +++---..........................................................
1 file changed, 3 insertions(+), 3 deletions(-)
[root@localhost wj]# diff 1.c 2.c |diffstat -f 1
unknown | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
You have new mail in /var/spool/mail/root
[root@localhost wj]# diff 1.c 2.c |diffstat -f 0
unknown | 6 3 + 3 - 0 !
1 file changed, 3 insertions(+), 3 deletions(-)
[root@localhost wj]#
1、安装Apache,使用命令“yum install httpd -y”
[root@localhost ~]# yum install httpd -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
base | 4.0 kB 00:00 ...
Setting up Install Process2、启动apache
[root@localhost ~]# service httpd start
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[确定]
[root@localhost ~]#3、设置apache开机自启
[root@localhost ~]# chkconfig --level 5 httpd on
[root@localhost ~]# chkconfig --list httpd
httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:启用 6:关闭
[root@localhost ~]# 4、修改防火墙
想要其他机器访问到该主机的apache,要么关闭防火墙,要么就修改防火墙的配置
1)关闭防火墙,
在终端输入setup命令
[root@localhost ~]# setup
弹出窗口,选择防火墙
弹出窗口,用空格关闭防火墙,保存退出(有*是启动)
2)修改防火墙配置,
在终端输入命令“setup”,在弹出的框中选择“防火墙”,接着选择“定制”
使用空格键选中“http“、”https“,接着选择“转发”
选择“添加“
添加端口80,协议tcp,然后确定
回到最初的界面,“确定”
重启防火墙
[root@localhost ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
[root@localhost ~]#
重启apache
[root@localhost ~]# service httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[确定]
[root@localhost ~]#
5、测试,在其他局域网电脑输入本机的ip地址,看到如下界面代表apache安装成功
Apache的配置文件默认路径是“/etc/httpd/conf/httpd.conf”,编辑该文件就可以修改Apache的配置 1、设置网页主目录,参数DocumentRoot就是网页存放的主目录。打开配置文件httpd.conf,查找DocumentRoot(大约292行)
[root@localhost ~]# gedit /etc/httpd/conf/httpd.conf
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot "/var/www/html" //当前默认是在"/var/www/html"目录下,所有的网页必须放在这里2、设置连接端口,通过参数listen来设置连接的端口,默认80.(大约136行)
[root@localhost ~]# gedit /etc/httpd/conf/httpd.conf
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 803、设置连接超时,参数timeout,当连接超过一定的空闲时间,就会自动断开。(大约68行)
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 604、设置字符集,参数AddDefaultCharset,建议最好设置utf-8,这是通用的。(大约753行)
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default. To use the
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
AddDefaultCharset UTF-85、设置服务器名称,参数ServerName。这是服务器的域名,必须有dns解析才可以访问。如果你没有合法的域名,那么只能通过ip地址来访问
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
#ServerName www.example.com:806、设置keepalive,提高网络效率,默认是关闭的。(大约76行)
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive Off7、设置keepaliverequest,设置为0 的时候没有限制,不过最好还是用默认值,或者自己根据情况来改变。(大约83行)
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend ou leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
php是最好用的服务器语言了,Apache对php有很强大的支持 1、检测是否安装php,如果什么信息也没有,那么你就要自己安装php了
[root@localhost ~]# rpm -qa | grep php2、安装php,在终端输入命令“yum install –y php”
[root@localhost ~]# yum install -y php
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Dependency Installed:
php-cli.i686 0:5.3.3-26.el6 php-common.i686 0:5.3.3-26.el6
Complete!
[root@localhost ~]# 3、再次检测,看是否安装。看到如下信息就证明安装成功了。
[root@localhost ~]# rpm -qa | grep php
php-cli-5.3.3-26.el6.i686
php-5.3.3-26.el6.i686
php-common-5.3.3-26.el6.i686
[root@localhost ~]# 4、重新启动Apache服务
[root@localhost ~]# service httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[确定]
[root@localhost ~]# 5、测试php。在“/var/www/html/”目录下创建一个test.php文件。然后在浏览器输入“127.0.0.1/test.php”
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# touch test.php
[root@localhost html]# gedit test.php
<?php
echo "hello php";
?>
可以在浏览器看到以下结果
6、安装gd库,支持php图形验证码。在终端输入命令“yum install -y php-gd”
[root@localhost ~]# yum install -y php-gd
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
============================================================================
Package Arch Version Repository Size
============================================================================
Installing:
php-gd i686 5.3.3-26.el6 base 105 k
Installing for dependencies:
libXpm i686 3.5.10-2.el6 base 50 k
Dependency Installed:
libXpm.i686 0:3.5.10-2.el6
Complete!
[root@localhost ~]# rpm -qa | grep php-gd
php-gd-5.3.3-26.el6.i686
[root@localhost ~]#
1、打开Apache配置文件httpd.conf,搜索“cgi”,找到下面的一段,去掉“addhandler”前面的“#“,这样就开启了Apache的cgi功能
[root@localhost ~]# gedit /etc/httpd/conf/httpd.conf
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi
2、cgi的目录在“/var/www/cgi-bin/”,在这里创建一个测试文件“test.cgi”输入内容如下
[root@localhost ~]# touch /var/www/cgi-bin/test.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "hello cgi";
3、将“cgi-bin”的权利改为777
[root@localhost ~]# chmod –R 777 /var/www/cgi-bin
4、在浏览器输入“127.0.0.1/cgi-bin/test.cgi”可以看到下面的结果
做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ 密码:n7bk
1、检测是否安装ssl模块,如果没有就安装
[root@localhost cgi-bin]# rpm -qa | grep mod_ssl //查看是否安装ssl模块
[root@localhost cgi-bin]# yum install -y mod_ssl //安装ssl
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Complete!
[root@localhost cgi-bin]#
2、修改ssl的配置文件“/etc/httpd/conf.d/ssl.conf”如下,开启ssl,设置监听端口
[root@localhost ~]# gedit /etc/httpd/conf.d/ssl.conf
# Do NOT simply read the instructions in here without understanding
# what they do. They're here only as hints or reminders. If you are unsure
# consult the online docs. You have been warned.
LoadModule ssl_module modules/mod_ssl.so //开启ssl功能
# When we also provide SSL we have to listen to the
# the HTTPS port in addition.
Listen 443 //监听的端口
3、修改防火墙配置,开启对上面端口443的支持
1)在终端输入命令“setup”,在弹出的框中选择“防火墙”,接着选择“定制” 2)使用空格键选中”https“,接着选择“转发” 3)选择“添加“ 4)添加端口443,协议tcp,然后确定 5)回到最初的界面,“确定” 6)重启防火墙
[root@localhost ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
[root@localhost ~]#
7)重启apache
[root@localhost ~]# service httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[确定]
[root@localhost ~]#
4、测试
1)在浏览器输入https://127.0.0.1,注意必须是“https“ ,看到如下结果 2)选择“我已充分了解”,弹出如下对话框,选择“确认安全例外”就可以正常访问
为了服务器的安全,通常用户在请求访问某个文件夹的时候,Apache可以要求用户输入有效的用户名和登录密码1、创建一个测试目录
[root@localhost cgi-bin]# mkdir /var/www/html/wj2、开启认证功能,修改配置文件httpd.conf如下,(将html目录的配置中none改为all)
[root@localhost ~]# gedit /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All //默认是none,这里改为all
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>3、给需要认证的目录添加配置,修改httpd.conf文件,添加如下内容
<Directory "/var/www/html/wj"> //wj就是我们要认证的目录
AllowOverride AuthConfig //这里必须使用AuthConfig
Order allow,deny
Allow from all
</Directory>4、 给测试目录设置用户名和密码
[root@localhost wj]# htpasswd -c /var/www/html/wj/.htpasswd david //david就是创建的用户名
New password: //这里需要输入密码,下面的是确认密码
Re-type new password:
Adding password for user david //创建成功
[root@localhost wj]# 5、创建htaccess文件,并且增加内容
[root@localhost wj]# vim .htaccess
AuthUserFile /var/www/html/wj/.htpasswd
AuthName "david"
AuthType Basic
require valid-user6、重启Apache服务
[root@localhost wj]# service httpd restart7、测试,在浏览器输入“127.0.0.1/wj”,可以看到需要输入密码
jdk是运行或者开发java的必须工具,很多软件都会依赖jdk,因此必须学会安装jdk1、查看当前系统的jdk情况
[root@localhost wj]# rpm -qa | grep java
tzdata-java-2013g-1.el6.noarch
java-1.6.0-openjdk-1.6.0.0-1.66.1.13.0.el6.i686 //可以看到当前系统已经安装了jdk,但是版本太旧了
java-1.7.0-openjdk-1.7.0.45-2.4.3.3.el6.i6862、删除系统jdk包
[root@localhost wj]# yum remove -y java-1.6.0
[root@localhost wj]# yum remove -y java-1.7.0
[root@localhost wj]# rpm -qa | grep java //查看是否删除了
tzdata-java-2013g-1.el6.noarch3、到官网下载最新的jdk包,http://www.oracle.com/technetwork/java/javase/downloads/index.html , 下载的时候注意64位或者32位
4、将下载的压缩包复制到“/usr/local/src/”,解压
[root@localhost src]# cp /media/sf_data/jdk-10.0.2_linux-x64_bin.tar /usr/local/src/jdk.tar
[root@localhost src]# tar -xvf jdk.tar5、配置jdk环境变量,打开“/etc/profile”,在最后面追加如下
[root@localhost src]# gedit /etc/profile
#java environment
export JAVAHOME=/usr/local/src/jdk-10.0.2 //这个路径就是jdk解压的路径
export CLASSPATH=.:${JAVAHOME}/jre/lib/rt.jar:${JAVAHOME}/lib/dt.jar:${JAVAHOME}/lib/tools.jar
export PATH=$PATH:${JAVAHOME}/bin6、刷新profile
[root@localhost src]# source /etc/profile7、测试jdk,在终端输入命令“Java -version”
[root@localhost src]# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) Client VM (build 25.181-b13, mixed mode)
[root@localhost src]#
Tomcat作为web服务器实现了对servlet和jsp的支持,centos目前不支持yum方式安装。在使用Tomcat之前,确保你已经安装并配置好了jdk,而且jdk的版本要和tomcat匹配1、从Tomcat官网下载安装包(http://tomcat.apache.org/download-70.cgi),直接解压就可以使用
[root@localhost wj]# tar -xvf tomcat.tar //直接解压
[root@localhost wj]# ls
1.c 1.c~ apache-tomcat-9.0.10 tomcat.tar
[root@localhost wj]# 2、进入Apache的bin目录,执行startup.sh就可以启动Apache
[root@localhost apache-tomcat-9.0.10]# cd /wj/apache-tomcat-9.0.10//bin/
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE: /wj/apache-tomcat-9.0.10
Using CATALINA_HOME: /wj/apache-tomcat-9.0.10
Using CATALINA_TMPDIR: /wj/apache-tomcat-9.0.10/temp
Using JRE_HOME: /usr
Using CLASSPATH: /wj/apache-tomcat-9.0.10/bin/bootstrap.jar:/wj/apache-tomcat-9.0.10/bin/tomcat-juli.jar
Tomcat started.3、修改防火墙配置,Tomcat默认使用8080端口,需要修改防火墙,开启对8080端口的支持
1)在终端输入命令“setup”,在弹出的框中选择“防火墙”,接着选择“定制”
2)使用空格键选中”https“、“http”,接着选择“转发”
3)选择“添加“
4)添加端口8080,协议tcp,然后确定
5)回到最初的界面,“确定”
6)重启防火墙
[root@localhost ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
[root@localhost ~]#
7)重启apache
[root@localhost ~]# service httpd restart
停止 httpd: [确定]
正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[确定]
[root@localhost ~]# 4、测试。在浏览器输入https://127.0.0.1:8080,看到如下结果
1、检测是否已安装mysql
[root@localhost bin]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.i686
[root@localhost bin]2、安装mysql和mysql-server
[root@localhost bin]# yum install -y mysql
[root@localhost bin]# yum install -y mysql-server3、启动mysql,注意这里的服务名字是“mysqld”
[root@localhost bin]# service mysqld start
shell-init: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
chdir: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK [确定]
正在启动 mysqld: [确定]
[root@localhost bin]# 4、配置MySQL开机启动
[root@localhost bin]# chkconfig mysqld on
[root@localhost bin]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@localhost bin]# 5、设置root用户密码 ,设置密码的命令是“mysqladmin -u 用户名password 密码”
[root@localhost bin]# mysqladmin -u root password 543092 //密码是5430926、修改密码,命令是“mysqladmin -u 用户名 -p password 新密码”
[root@localhost bin]# mysqladmin -u root -p password 123456 //新密码123456
Enter password: //这里要求输入旧密码
[root@localhost bin]# 7、mysql配置文件“/etc/my.cnf”
[root@localhost bin]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql //数据库文件目录
socket=/var/lib/mysql/mysql.sock //socket文件
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0 [mysqld_safe]
log-error=/var/log/mysqld.log //日志文件
pid-file=/var/run/mysqld/mysqld.pid //进程pid文件
8、修改端口
1)mysql默认的端口是3306,可以使用netstat来查看
[root@localhost bin]# netstat -tunlp | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4339/mysqld
2)端口在配置文件中修改,打开配置文件,在后面追加一句话”port=xxx”
[root@localhost bin]# gedit /etc/my.cnf
port=3307
3)重启myslqd服务,查看端口
[root@localhost bin]# service mysqld restart
shell-init: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
chdir: error retrieving current directory: getcwd: cannot access parent directories: 没有那个文件或目录
^[[A停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@localhost bin]# netstat -tunlp | grep mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 4604/mysqld
1、登录,可以用密码登录,也可以不用密码登录。命令格式“mysql –u 用户名 –p 密码”
[root@localhost src]# mysql -u root –p //有密码登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
[root@localhost src]# mysql -u root //无密码登录2、退出,命令“quit”
[root@localhost bin]# quit3、创建数据库,命令“create database 数据库名称;”,注意这个命令后面有分号
mysql> create database test1;
Query OK, 1 row affected (0.00 sec)4、查看数据库,命令“show databases;”
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
| test1 |
+--------------------+
4 rows in set (0.00 sec)5、删除数据库,命令“drop database 数据库名称;”
mysql> drop database test1;
Query OK, 0 rows affected (0.01 sec)6、设置权限
mysql允许给某个特定的用户赋予指定的权利,而且可以指定在某台机器上使用。Mysql的权限如下
权限 数据库 Table Column 说明
all privileges √ 所有权利
alter √ √ 增减、删除、修改列
create √ √ 创建数据库、表
delete √ √ 删除行
drop √ √ 删除表、数据库
file √ 操作文件
index √ √ 索引
insert √ √ √ 插入
process √ 查看线程、连接
reference √ 创建外键
reload √ 重新加载,拥有此权限可以刷新表
select √ √ √ 选择
shutdown √ 关闭
update √ √ √ 更新
usage √ 无权限,只能连接 1)授权用户权限,命令格式“grant 权限 on 数据库文件 to 用户名@ip identified by ‘密码’;”。在使用grant的时候,如果用户不存在,那么久创建用户。
//给david在本机授权插入功能,密码123456,只能对test01操作
mysql> grant insert on test01.* to david@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql>
//给david所有权限,在所有的主机都可以操作,而且可以操作任意数据库
mysql> grant all privileges on *.* to david@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> 2)查看当前数据库所有授权情况,命令“select host,user from mysql.user”
mysql> select host,user from mysql.user;
+-----------------------+-------+
| host | user |
+-----------------------+-------+
| % | david |
| 127.0.0.1 | root |
| localhost | |
| localhost | david |
| localhost | root |
| localhost.localdomain | |
| localhost.localdomain | root |
+-----------------------+-------+
7 rows in set (0.00 sec)
mysql> 3)查看当前登录用户的权利,命令“show grants”
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*1256939B1977AFF6C3D114C5594EE354EF363A8B' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> 4)查看某个用户在某台机器的权限,命令“show grants for user@ip”
mysql> show grants for david@localhost;
+--------------------------------------------------------------------------------------------------------------+
| Grants for david@localhost |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'david'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT INSERT ON `test01`.* TO 'david'@'localhost' |
+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> 5)删除用户的权限,命令“revoke 权限 on 数据库文件 from user@ip”
mysql> revoke all privileges on *.* from david@'%';
Query OK, 0 rows affected (0.00 sec) mysql> show grants for david@localhost; //删除之后查看一下
+--------------------------------------------------------------------------------------------------------------+
| Grants for david@localhost |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'david'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql>
6)删除用户,命令“delete from user where user=‘username’”
mysql> use mysql; //首先要调用这个命令
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed mysql> delete from user where user='david'; //删除用户
Query OK, 2 rows affected (0.00 sec) mysql> select host,user from mysql.user; //查看用户
+-----------------------+------+
| host | user |
+-----------------------+------+
| 127.0.0.1 | root |
| localhost | |
| localhost | root |
| localhost.localdomain | |
| localhost.localdomain | root |
+-----------------------+------+
5 rows in set (0.00 sec)
mysql>
做了一个Linux学习的平台,目前出来一个雏形,各位可以参考使用
链接:https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ 密码:n7bk
如果不小心忘记了root密码,那么mysql就不能再登录了,这时就要重置root密码才行。通过下面的步骤,我们可以重新设置root密码。
1、退出mysql
[root@localhost src]# service mysqld stop
停止 mysqld: [确定]
[root@localhost src]# 2、进入sql安全模式,命令“/usr/bin/mysqld_safe --skip-grant-table &”
[root@localhost src]# /usr/bin/mysqld_safe --skip-grant-table &
[1] 6332
[root@localhost src]# 180814 10:10:00 mysqld_safe Logging to '/var/log/mysqld.log'.
180814 10:10:00 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql3、无密码方式登录,命令“mysql –u root”
[root@localhost src]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.71 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trade of Oracle Corporation and/or its
affiliates. Other names may be trades of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 4、使用mysql,命令“use mysql;”
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> 5、重设root密码,命令“update user set password=password (“密码”) where user=’root’”
mysql> update user set password=password('123456') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> 6、刷新
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)7、退出,重新登录
[root@localhost src]# mysql -u root -p
Enter password: //这里输入新密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Sever version: 5.1.71 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trade of Oracle Corporation and/or its
affiliates. Other names may be trades of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
1、检测是否已安装php、php-mysql、apache等工具
[root@localhost src]# rpm -qa |grep php
php-cli-5.3.3-26.el6.i686
php-gd-5.3.3-26.el6.i686
php-mysql-5.3.3-26.el6.i686
php-pdo-5.3.3-26.el6.i686
php-5.3.3-26.el6.i686
php-xml-5.3.3-26.el6.i686
php-common-5.3.3-26.el6.i686
[root@localhost src]# 2、到phpMyAdmin官网下载“phpMyAdmin”,https://www.phpmyadmin.net/3、将下载的软件拷贝到“/var/www/html/”目录下,重命名“phpMyAdmin”
[root@localhost down]# tar –zxvf phpMyAdmin-4.8.2.tar.gz
[root@localhost down]# cp –r phpMyAdmin-4.8.2 /var/www/html/phpMyAdmin4、修改配置文件“config.sample.inc.php”,将第29行的“cookie”改为“http”
[root@localhost src]# cd /var/www/html/phpMyAdmin/
[root@localhost phpMyAdmin]# gedit config.sample.inc.php
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';5、启动Apache 和 mysql
[root@localhost phpMyAdmin]# service httpd start
正在启动 httpd:
[root@localhost phpMyAdmin]# service mysqld start
正在启动 mysqld: [确定]
[root@localhost phpMyAdmin]# 6、在浏览器输入“127.0.0.1/phpMyAdmin”,就可以登录到phpMyAdmin
大多数Linux系统都使用vsftpd,因此这里我们也安装vsftpd
1、安装vsftpd
[root@localhost phpMyAdmin]# yum install -y vsftpd
Loaded plugins: fastestmirror, refresh-packagekit, security
Installed:
vsftpd.i686 0:2.2.2-11.el6_4.1
Complete!
[root@localhost phpMyAdmin]# 2、设置防火墙,vsftpd默认使用21端口,因此必须在防火墙中设置允许访问21端口
1)在终端输入命令“setup”,在弹出的框中选择“防火墙”,接着选择“定制”
2)使用空格键选中”ftp”,接着选择“转发”
3)选择“添加“
4)添加端口21,协议tcp,然后确定
5)回到最初的界面,“确定”
6)重启防火墙
[root@localhost phpMyAdmin]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
iptables:载入额外模块:nf_conntrack_ftp [确定]
[root@localhost phpMyAdmin]# 3、启动vsftpd
[root@localhost bin]# service vsftpd start
为 vsftpd 启动 vsftpd: [确定]4、测试
1)安装lftp
[root@localhost phpMyAdmin]# yum install -y lftp
Installed:
lftp.i686 0:0.17-54.el6
Complete!
2)连接ftp
[root@localhost bin]# lftp 192.168.0.113
lftp 192.168.0.113:~> ls
drwxr-xr-x 2 0 0 4096 Mar 01 2013 pub
lftp 192.168.0.113:/> cd pub
lftp 192.168.0.113:/pub> ls
lftp 192.168.0.113:/pub> 5、修改端口。ftp默认端口是21,但是很多时候都会改变端口,这是就需要修改配置文件“/etc/vsftpd/vsftpd.conf”,在结尾追加一句”listen_port=8765”。
[root@localhost pub]# gedit /etc/vsftpd/vsftpd.conf
listen_port=87656、重启服务测试。请先按照第二步修改防火墙配置
[root@localhost ~]# service vsftpd restart
关闭 vsftpd: [确定]
为 vsftpd 启动 vsftpd: [确定] [root@localhost ~]# lftp 192.168.0.113 //按照默认的端口来连接
lftp 192.168.0.113:~> ls //使用ls命令,发现根本没有连接上
中断
lftp 192.168.0.113:~> [root@localhost ~]# lftp 192.168.0.113:8765 //连接的时候指定端口号
lftp 192.168.0.113:~> ls //使用ls命令可以查看内容,说明连接成功
drwxr-xr-x 2 0 0 4096 Aug 14 03:38 pub
ftp服务器可以设置每个用户的带宽,这样根据实际需求来分配,更加充分的利用系统资源。带宽通过参数“anon_max_rate“和”local_max_rate“来设置,这两个参数在配置文件中如果找不到,那么用户可以在末尾追加。1、设置匿名用户带宽,通过参数“anon_max_rate”,之后重启服务
1)未修改之前的速度
[root@localhost wj]# lftp 192.168.0.113:8765 //匿名登录
lftp 192.168.0.113:~> cd pub/
lftp 192.168.0.113:/pub> get 1.zip //下载文件
[0] get 1.zip &
`1.zip' at 322830336 (13%) 65.74M/s eta:30s [正接收数据] //速度65M2)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”anon_max_rate=30000“
[root@localhost ~]# gedit /etc/vsftpd/vsftpd.conf
anon_max_rate=30000 //匿名用户的带宽是30kb
3)重启服务,测试匿名用户带宽
[root@localhost wj]# service vsftpd restart //重启服务
关闭 vsftpd: [失败]
为 vsftpd 启动 vsftpd: [确定] [root@localhost wj]# lftp 192.168.0.113:8765 //匿名登录,注意端口号之前已经修改了
lftp 192.168.0.113:~> cd pub/
lftp 192.168.0.113:/pub> get 1.zip
[0] get 1.zip &
`1.zip' at 1179648 (0%) 28.0K/s eta:22h [正接收数据] //可以看到这里的下载速度很慢,只有28k
2、设置本机用户的带宽,通过参数“local_max_rate“ 实现 。这里会限制本地所有的用户速度
1)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”anon_max_rate=30000“
[root@localhost wj]# lftp david:[email protected]:8765 //用户david登录,密码是543092
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 06:54 1.zip
lftp [email protected]:~> get 1.zip //下载文件
[0] get 1.zip &
`1.zip' at 322830336 (13%) 65.74M/s eta:30s [正接收数据] //速度65M
2)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”local_max_rate=30000“
[root@localhost ~]# gedit /etc/vsftpd/vsftpd.conf
local_max_rate=30000 //本地用户的带宽是30kb
3)重启服务,测试本地用户带宽
[root@localhost wj]# service vsftpd restart //重启服务
关闭 vsftpd: [失败]
为 vsftpd 启动 vsftpd: [确定] [root@localhost wj]# lftp david:[email protected]:8765 //用户david登录,密码是543092
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 06:54 1.zip
lftp [email protected]:~> get 1.zip //下载文件
[0] get 1.zip &
`1.zip' at 322830336 (13%) 35.0K/s eta:30s [正接收数据] //速度30k [root@localhost wj]# lftp weijie:[email protected]:8765 //用户david登录,密码是123456
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 06:54 1.zip
lftp [email protected]:~> get 1.zip //下载文件
[0] get 1.zip &
`1.zip' at 322830336 (13%) 29.0K/s eta:30s [正接收数据] //速度29k
3、设置指定用户的带宽
1)设置带宽配置目录,参数“user_config_dir“可以指定一个目录来存放管理带宽的文件
[root@localhost ~]# gedit /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/rate_limit //管理用户带宽的目录,这个目录需要用户自己创建
2)设置用户“weijie“的带宽,在”rate_limit“目录下创建文件”weijie“,在文件中添加参数local_max_rate
[root@localhost wj]# mkdir /etc/vsftpd/rate_limit
[root@localhost wj]# cd /etc/vsftpd/rate_limit/
[root@localhost rate_limit]# touch weijie
[root@localhost rate_limit]# gedit weijie
local_max_rate=30000
3)重启vsftpd服务,测试用户“weijie“用户”david“的下载速度
[root@localhost wj]# service vsftpd restart //重启服务
关闭 vsftpd: [确定]
为 vsftpd 启动 vsftpd: [确定] [root@localhost wj]# lftp david:[email protected]:8765 //用户david登录
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 06:54 1.zip
lftp [email protected]:~> get 1.zip
[0] get 1.zip &
`1.zip' at 276234240 (11%) 54.24M/s eta:37s [正接收数据] //速度52M [root@localhost wj]# lftp weijie:[email protected]:8765 //用户weijie登录
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 07:13 1.zip
lftp [email protected]:~> get 1.zip
[0] get 1.zip &
`1.zip' at 196608 (0%) 21.4K/s eta:30h [正接收数据] //速度21k
lftp [email protected]:~>
1、通过vsftpd的配置文件以及“hosts.deny”和“hosts.allow”文件设置允许某个ip地址访问
1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的参数“tcp_wrapper”,确保这个参数是yes
[root@localhost wj]# gedit /etc/vsftpd/vsftpd.conf //匿名登录
tcp_wrapper=YES
2)打开配置文件“/etc/hosts.deny“,在末尾追加一句话”vsftpd:all:Deny“
[root@localhost wj]# gedit /etc/hosts.deny
# hosts.deny This file contains access rules which are used to
# deny connections to network services that either use
# the tcp_wrappers library or that have been
# started through a tcp_wrappers-enabled xinetd.
vsftpd:all:Deny //所有的ip都不可以访问
3)打开配置文件“/etc/hosts.allow“,在末尾追加一句话”vsftpd:192.168.0.123:Allow“。当前的配置就是只允许“192.168.0.123”访问
[root@localhost wj]# gedit /etc/hosts.allow
# hosts.allow This file contains access rules which are used to
# allow or deny connections to network services that
# either use the tcp_wrappers library or that have been
# started through a tcp_wrappers-enabled xinetd.
#
vsftpd:192.168.0.123:Allow
4)测试是否可以访问,当前主机的ip并不是“192.168.0.123”,因此访问不会成功的
[root@localhost wj]# service vsftpd restart //重启服务
关闭 vsftpd: [确定]
为 vsftpd 启动 vsftpd: [确定] [root@localhost wj]# lftp weijie:[email protected]:8765 //本地用户登录
lftp [email protected]:~> ls
中断 //ls失败,并没有连接成功
lftp [email protected]:~> bye [root@localhost wj]# lftp 192.168.0.113:8765 //匿名登录
lftp 192.168.0.113:~> ls
中断 //ls失败,并没有连接成功
lftp 192.168.0.113:~>
2、当一个ip地址对主机的连接太多时,就会降低服务器的效率。因此有必要设置一个IP的连接数,当连接超过一定的数量就不能再连了,这样就可以提高服务器的效率。Vsftpd默认没有连接设置,可以通过参数“max_clients“来设置。由于同一个局域网的ip是一样的,因此这个最大连接数要合理设置。
1)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”max_clients=2“
[root@localhost pub]# gedit /etc/vsftpd/vsftpd.conf
max_clients=2
2)重启服务,测试。一次打开三个连接,发现第三个连接不能访问
[root@localhost wj]# service vsftpd restart //重启服务
关闭 vsftpd: [确定]
为 vsftpd 启动 vsftpd: [确定] [root@localhost wj]# lftp weijie:[email protected]:8765 //登录weijie
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 07:13 1.zip
lftp [email protected]:~> [root@localhost wj]# lftp 192.168.0.113:8765 //匿名登录
lftp 192.168.0.113:~> ls
drwxr-xr-x 2 0 0 4096 Aug 14 06:38 pub
lftp 192.168.0.113:/> [root@localhost pub]# lftp 192.168.0.113 //匿名登录
lftp 192.168.0.113:~> ls
[0] ls &
`ls' at 0 [重新连接前延时: 22] //不能再访问,ls失效
lftp 192.168.0.113:~>
一个Linux主机中会多个用户,而我们希望有些用户不能去访问ftp。ftp服务器可以通过配置文件“/etc/vsftpd/user_list”来设置一个用户列表,这个列表可以是黑名单,也可以是白名单,具体要根据配置文件的参数“userlist_deny”来确定1、黑名单
1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的参数“userlist_enable”,确保这个参数是yes
[root@localhost wj]# gedit /etc/vsftpd/vsftpd.conf //匿名登录
userlist_enable=YES
2)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”userlist_deny=yes“。这个参数是yes,表示要设置一个黑名单
[root@localhost wj]# lftp david:[email protected]:8765 //用户david登录,密码是543092
userlist_deny=YES
3)编辑文件“/etc/vsftpd/user_list“,在末尾追加一句话要设置的用户名即可
[root@localhost ~]# gedit /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
nobody
david
4)重启服务,测试黑名单内的用户是否可以访问,上面列出的都是不可以访问的用户
[root@localhost wj]# service vsftpd restart //重启服务
关闭 vsftpd: [失败]
为 vsftpd 启动 vsftpd: [确定] [root@localhost wj]# lftp weijie:[email protected]:8765 //用户weijie登录,可以访问
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 07:13 1.zip
lftp [email protected]:~> bye [root@localhost wj]# lftp 192.168.0.113:8765 //匿名用户也可以
lftp 192.168.0.113:~> ls
drwxr-xr-x 2 0 0 4096 Aug 14 06:38 pub
lftp 192.168.0.113:/> [root@localhost wj]# lftp david:[email protected]:8765 //用户david在黑名单中,因此无法访问,ls命令会失败
lftp [email protected]:~> ls
[0] ls &
`ls' at 0 [重新连接前延时: 28]
lftp [email protected]:~>
2、白名单
1)修改配置文件“/etc/vsftpd/vsftpd.conf”中的参数“userlist_enable”,确保这个参数是yes
[root@localhost wj]# gedit /etc/vsftpd/vsftpd.conf //匿名登录
userlist_enable=YES
2)打开配置文件“/etc/vsftpd/vsftpd.conf“,在末尾追加一句话”userlist_deny=NO“。这个参数是NO,表示要设置一个白名单
[root@localhost wj]# lftp david:[email protected]:8765 //用户david登录,密码是543092
userlist_deny=NO
3)编辑文件“/etc/vsftpd/user_list“,在末尾追加一句话要设置的用户名即可
[root@localhost ~]# gedit /etc/vsftpd/user_list
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
nobody
david
4)重启服务,测试黑名单内的用户是否可以访问,上面列出的都是不可以访问的用户
[root@localhost wj]# service vsftpd restart //重启服务
关闭 vsftpd: [失败]
为 vsftpd 启动 vsftpd: [确定] [root@localhost wj]# lftp david:[email protected]:8765 //用户david登录,可以访问
lftp [email protected]:~> ls
-rwxrwxrwx 1 0 0 2375494044 Aug 14 07:13 1.zip
lftp [email protected]:~> bye [root@localhost wj]# lftp weijie:[email protected]:8765 //用户weijie不在白名单中,因此无法访问,ls命令会失败
lftp [email protected]:~> ls
[0] ls &
`ls' at 0 [重新连接前延时: 28]
lftp [email protected]:~> bye [root@localhost wj]# lftp 192.168.0.113:8765 //匿名用户也不行
lftp 192.168.0.113:~> ls
[0] ls &
`ls' at 0 [重新连接前延时: 28]
lftp 192.168.0.113:~>
在配置文件中,还有一些关于vsftpd的其他设置,这里列出来
# Example config file /etc/vsftpd/vsftpd.conf
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES //是否允许匿名登录
#
# Uncomment this to allow local users to log in.
local_enable=YES //是否允许本地用户登录
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES //是否允许写操作
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022 //本地用农户权限掩码
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES //是否允许匿名用户上传
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES //是否允匿名用户创建目录
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES //是否允许获取目录信息
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES //是否允许其他用户拥有匿名用户上传的文件
#chown_username=whoever
# You may change the default value for timing out an idle session.
#idle_session_timeout=600 //连接空闲超时
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120 //数据请求超时
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES //是否允许ls命令使用-R参数,递归
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES //是否允许用户切换目录
#chroot_list_enable=YES //是否允许指定的用户切换目录,用户名单在/etc/vsftpd/chroot_list文件中
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list //这个文件中的用户不能切换目录
1、安装bind软件,需要安装3 个bind、bind-chroot、bind-util
[root@localhost pub]# yum install -y bind bind-chroot bind-utils
Installed:
bind.i686 32:9.8.2-0.17.rc1.el6_4.6
Complete! 2、修改配置文件“/etc/named.conf”,追加“forward”
[root@localhost pub]# gedit /etc/named.conf
options {
listen-on port 53 { 127.0.0.1; };
# listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { localhost; };
recursion yes; dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto; /* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic";
forward only;
forwarders{
8.8.8.8;
}
};3、设置防火墙,这里需要用到53端口。需要开启tcp和udp的53端口,记得重启防火墙
[root@localhost pub]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT [root@localhost phpMyAdmin]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
iptables:载入额外模块:nf_conntrack_ftp [确定]
[root@localhost phpMyAdmin]# 4、启动服务
[root@localhost pub]# service named start
启动 named: [确定]
[root@localhost pub]# 5、测试,命令格式“dig 网站 @ip”,这里用回环地址来测试,看是否能请求成功
[root@localhost pub]# dig www.baidu.com @127.0.0.1
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> www.baidu.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51491
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.baidu.com. IN A
;; ANSWER SECTION:
www.baidu.com. 1191 IN CNAME www.a.shifen.com.
www.a.shifen.com. 299 IN A 14.215.177.38 //这个就是请求到的结果
www.a.shifen.com. 299 IN A 14.215.177.39
;; Query time: 3053 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Aug 14 19:02:59 2018
;; MSG SIZE rcvd: 90
6、更改配置文件named.conf,让所有机器都可以使用该服务。
1)将配置文件中的回环地址改为any,意味着允许任何人使用
[root@localhost pub]# gedit /etc/named.conf
options {
listen-on port 53 {any; };
# listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
recursion yes; dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto; /* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic";
forward only;
forwarders{
8.8.8.8;
}
};
2)找一个其他ip地址来测试
[root@localhost pub]# service named restart //重启服务
停止 named: [确定]
启动 named: [确定] [root@localhost pub]# dig www.baidu.com @192.168.0.113
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> www.baidu.com @192.168.0.113
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37134
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION:
;www.baidu.com. IN A ;; ANSWER SECTION:
www.baidu.com. 871 IN CNAME www.a.shifen.com.
www.a.shifen.com. 299 IN A 14.215.177.39
www.a.shifen.com. 299 IN A 14.215.177.38 ;; Query time: 474 msec
;; SERVER: 192.168.0.113#53(192.168.0.113)
;; WHEN: Tue Aug 14 19:06:19 2018
;; MSG SIZE rcvd: 90
1、确定已经安装bind软件,需要安装3 个bind、bind-chroot、bind-util
[root@localhost wj]# yum install –y bind bind-chroot bind-util 2、修改配置文件“/etc/named.conf”
[root@localhost pub]# gedit /etc/named.conf
options {
# listen-on port 53 { 127.0.0.1; };
# listen-on-v6 port 53 { ::1; };
directory "/var/named";
};
。
zone "david.cn" IN{ //正向解析配置
type master;
file "david.cn"; //注意名字,后面要用到这个名字
allow-update {none;};
};
zone "0.168.192.in-addr.arpa" IN{ //反向解析配置
type master;
file "192.168.0"; //注意名字,后面要用到这个名字
allow-update {none;};
};3、编辑正向配置文件“/var/named/david.cn”,这个文件不存在,用户需要自己创建
[root@localhost pub]# gedit /var/named/david.cn
$TTL 86400
@ IN SOA bind.david.cn. root.david.cn. (
2011071001
3600
1800
604800
86400
)
IN NS bind.david.cn.
IN A 192.168.0.113 //这个是本机ip
IN MX 10 mailsrv.david.cn.
bind IN A 192.168.0.113
mailsrv IN A 192.168.0.250
www IN CNAME bind.david.cn.4、编辑反向配置文件“/var/named/192.168.0”,这个文件不存在,用户需要自己创建
[root@localhost pub]# gedit /var/named/192.168.0
$TTL 86400
@ IN SOA bind.david.cn. root.david.cn. (
2011071001
3600
1800
604800
86400
)
IN NS bind.david.cn.
IN PTR david.cn.
IN A 255.255.255.0
113 IN PTR bind.david.cn.
250 IN PTR mailsrv.david.cn5、重启服务(确保防火墙的53端口已经打开)
[root@localhost wj]# service named restart
停止 named: [确定]
启动 named: [确定]
[root@localhost wj]# 6、测试
[root@localhost wj]# nslookup
> server 192.168.0.113 //切换dns服务器为上面配置好的
Default server: 192.168.0.113
Address: 192.168.0.113#53 > bind.david.cn //正向解析A类型
Server: 192.168.0.113
Address: 192.168.0.113#53
Name: bind.david.cn
Address: 192.168.0.113 > mailsrv.david.cn //正向解析A类型
Server: 192.168.0.113
Address: 192.168.0.113#53
Name: mailsrv.david.cn
Address: 192.168.0.250 > set q=mx //正向解析MX类型
> david.cn
Server: 192.168.0.113
Address: 192.168.0.113#53
david.cn mail exchanger = 10 mailsrv.david.cn. > www.david.cn //正向解析CNAME类型
Server: 192.168.0.113
Address: 192.168.0.113#53
www.david.cn canonical name = bind.david.cn. > 192.168.0.113 //反向解析
Server: 192.168.0.113
Address: 192.168.0.113#53
113.0.168.192.in-addr.arpa name = bind.david.cn. > 192.168.0.250 //反向解析
Server: 192.168.0.113
Address: 192.168.0.113#53
250.0.168.192.in-addr.arpa name = mailsrv.david.cn.0.168.192.in-addr.arpa.
>
1、检测samba是否安装,如果没有,那么可以使用yum来安装。至少需要安装3个软件:samba, samba-client、samba-common
[root@localhost pub]# rpm -qa | grep samba
samba-winbind-clients-3.6.9-164.el6.i686
samba-client-3.6.9-164.el6.i686
samba-common-3.6.9-164.el6.i686
samba4-libs-4.0.0-58.el6.rc4.i686
samba-winbind-3.6.9-164.el6.i686
[root@localhost pub]# yum install –y samba samba-client samba-common //如果没有,那么可以用此命令安装2、创建共享目录
[root@localhost /]# mkdir /wj //创建目录
[root@localhost /]# chmod 777 /wj //设置权限3、修改配置文件“/etc/samba/smb.cnf”
[root@localhost /]# gedit /etc/samba/smb.conf
# ----------------------- Standalone Server Options ------------------------
# Scurity can be set to user, share(deprecated) or server(deprecated)
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration
security = share //这里默认是user,改为share,这样不用输入密码就可访问
passdb backend = tdbsam [wj] //创建共享目录配置
comment=wj //名字
path=/wj //路径
read only=no //是否只读,这里为no,这样用户就可以创建文件夹
guest ok=yes //是否允许guest用户登录
browseable=yes //是否可以浏览目录4、修改防火墙,打开tcp的端口137、138、139、445
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 138 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT [root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
iptables:载入额外模块:nf_conntrack_ftp [确定]5、启动smb服务
[root@localhost wj]# service smb start
启动 SMB 服务: [确定]6、测试,在终端输入命令“testparm”,可以看到共享目录的信息
[root@localhost wj]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[wj]"
WARNING: The security=share option is deprecated
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
workgroup = MYGROUP
server string = Samba Server Version %v
security = SHARE
log file = /var/log/samba/log.%m
max log size = 50
idmap config * : backend = tdb
cups options = raw [homes]
comment = Home Directories
read only = No
browseable = No [printers]
comment = All Printers
path = /var/spool/samba
printable = Yes
print ok = Yes
browseable = No [wj]
comment = wj //名字
path = /wj //路径
read only = No //是否只读
guest ok = Yes //是否允许guest访问7、从windows测试,按下快捷键“window+r”,在弹出的窗口输入命令“smb:\\192.168.0.113”,可以看到本机的共享目录
1、当samba配置文件中的secure设置为user的时候,需要正确的用户名和密码才能登录。
root@localhost /]# gedit /etc/samba/smb.conf
# ----------------------- Standalone Server Options ------------------------
# Scurity can be set to user, share(deprecated) or server(deprecated)
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration
security = user //这是默认值,需要用户名密码
passdb backend = tdbsam2、管理账户和密码
samba默认使用tdbsam数据库管理机制来统一管理用户名和密码,使用的命令是pdbedit,命令如下
pdbedit -L
列出samba用户列表
pdbedit -Lv
列出samba用户详细信息
pdbedit -Lw
列出smbpasswd格式的用户
pdbedit –a wj
增加用户wj
pdbedit –x wj
删除用户wj
pdbedit –c “[D]” –u wj
暂停用户wj
pdbedit –c “[]” –u wj
恢复用户wj3、添加用户,必须确保这个用户存在于你的Linux系统中
[root@localhost wj]# pdbedit -a david //添加用户david
new password:
retype new password:
Unix username: david
NT username:
Account Flags: [U ]
User SID: S-1-5-21-1098217942-694112815-2930643030-1000
Primary Group SID: S-1-5-21-1098217942-694112815-2930643030-513
Full Name: david
Home Directory: \\localhost\david
HomeDir Drive:
Logon Script:
Profile Path: \\localhost\david\profile
Domain: LOCALHOST
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: never
Kickoff time: never
Password last set: 三, 15 8月 2018 10:15:21 CST
Password can change: 三, 15 8月 2018 10:15:21 CST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF [root@localhost wj]# pdbedit -L //查看是否添加成功
david:500:david4、重启smb服务
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 138 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT [root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
iptables:载入额外模块:nf_conntrack_ftp [确定]5、启动smb服务
[root@localhost wj]# service smb restart
关闭 SMB 服务: [确定]
启动 SMB 服务: [确定]
[root@localhost wj]# 6、从windows测试,按下快捷键“window+r”,在弹出的窗口输入命令“smb:\\192.168.0.113”,要求输入用户名和密码,匿名用户也无法登陆。
用户登录后,只能查看自己的家目录,不能选择其他目录
swat是一个图形化的samba管理软件,可以帮助不熟悉的人去灵活的配置samba服务,
1、安装swat
[root@localhost wj]# yum install -y samba-swat
Dependency Updated:
libsmbclient.i686 0:3.6.23-51.el6 samba.i686 0:3.6.23-51.el6
samba-client.i686 0:3.6.23-51.el6 samba-common.i686 0:3.6.23-51.el6
samba-winbind.i686 0:3.6.23-51.el6 samba-winbind-clients.i686 0:3.6.23-51.el6
Complete!
[root@localhost wj]#2、修改swat配置文件“/etc/xinetd.d/swat”
[root@localhost wj]# gedit /etc/xinetd.d/swat
service swat
{
port = 901 //端口号
socket_type = stream
wait = no
only_from = 127.0.0.1 //是否只允许本机登录,如果想在其他电脑登录,那么用#注释掉这句话。
user = root
server = /usr/sbin/swat
log_on_failure += USERID
disable = no //这里一定要是no,默认yes
} 3、修改防火墙,添加tcp的901端口
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 901 -j ACCEPT [root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
iptables:载入额外模块:nf_conntrack_ftp [确定]4、启动swat服务
[root@localhost wj]# service xinetd start
正在启动 xinetd: 5、在浏览器输入“ip:901”,可以看到一个图形化的管理界面
DansGuardian可以限制客户端的访问,通过这个软件,我们可以限制哪些网站不可以访问、哪些内容不能下载。
1、下载DansGuardian,提供一个网址http://www.rpmfind.net/linux/RPM/dag/redhat/el5/i386/dansguardian-2.8.0.6-1.2.el5.rf.i386.html
2、安装
[root@localhost wj]# rpm -ivh dansguardian-2.8.0.6-1.2.el5.rf.i386.rpm
warning: dansguardian-2.8.0.6-1.2.el5.rf.i386.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing... ########################################### [100%]
1:dansguardian ########################################### [100%]
3、修改配置文件“/etc/dansguardian/dansguardian.conf”,搜索“filterport”将端口改为8088。默认是8080,和tomcat冲突。关于proxyport端口,使用的是proxy服务器端口,默认3128,如果你修改了proxy的端口,那么这里也要改成对应的端口。
[root@localhost wj]# gedit /etc/dansguardian/dansguardian.conf
# the port that DansGuardian listens to.
filterport = 8088
4、配置防火墙,打开tcp的8088端口
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8088 -j ACCEPT [root@localhost wj]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
iptables:载入额外模块:nf_conntrack_ftp [确定]
5、启动服务
[root@localhost wj]# service dansguardian start
正在关闭 Web Content Filter (dansguardian): [确定]
启动 Web Content Filter (dansguardian): [确定]
6、修改客户端的代理设置,将代理端口改成dansguardian的端口8088,然后去百度一些内容,不良的网站就被屏蔽了。注意,这里端口必须修改,不可以使用3128.
7、增加过滤网址。
1)修改配置文件“/etc/dansguardian/bannedsitelist”,在后面追加要过滤的网址。重启服务
[root@localhost wj]# gedit /etc/dansguardian/bannedsitelist
# You will need to edit to add and remove categories you want
news.baidu.com
[root@localhost wj]# service dansguardian restart
正在关闭 Web Content Filter (dansguardian): [确定]
启动 Web Content Filter (dansguardian): [确定]
2)客户端访问百度新闻
8、过滤关键字
1)修改配置文件“/etc/dansguardian/bannedphraselist”,在后面追加要过滤的网址。重启服务
[root@localhost wj]# gedit /etc/dansguardian/bannedphraselist
# To block any page with words that contain the string "sex". (ie. sexual)
<sex> [root@localhost wj]# service dansguardian restart
正在关闭 Web Content Filter (dansguardian): [确定]
启动 Web Content Filter (dansguardian): [确定]
2)使用客户端浏览器搜索sex,发现网页打不开
9、过滤下载内容
1)修改配置文件“/etc/dansguardian/bannedextentsionlist”,里面默认已经有很多被禁止下载的格式了,如果要去掉某个限制,在前面加#
[root@localhost wj]# gedit /etc/dansguardian/bannedextentsionlist
#Banned extension list
.ade # Microsoft Access project extension
.adp # Microsoft Access project
.asx # Windows Media Audio / Video
.bas # Microsoft Visual Basic class module
.bat # Batch file
.cab # Windows setup file
.chm # Compiled HTML Help file
.cmd # Microsoft Windows NT Command script [root@localhost wj]# service dansguardian restart
正在关闭 Web Content Filter (dansguardian): [确定]
启动 Web Content Filter (dansguardian): [确定]
2)使用客户端浏览器下载一个文件
10、查看日志。可以通过日志文件“/var/log/dansguardian/access.log”来分析当前哪些内容被拦截了。
[root@localhost wj]# gedit /var/log/dansguardian/access.log
Sella&utm_term=wkjxxx0913 *DENIED* 禁止的文件扩展名: .exe GET 0
2018.8.15 16:29:07 - 192.168.0.112 http://xiazai.mindmanager.cc/favicon.ico GET 345
2018.8.15 16:30:28 192.168.0.112 http://trackercdn.kugou.com/i/v2/?
cmd=26&pid=4&authType=1&hash=1319C71BC5CBF32EF1495CECDA23AF24&
key=b1e358948cb6ce56a6c37cc88f408419&behavior=play&module=&appid=1155&
mid=bc7ba9731b77d3e10d329f751e774f1c&userid=0&token=&version=2.6.4&
vipType=0&album_id=517209 GET 318
proxy就是软件代理或者代理服务器,而squid就是一种常用的proxy服务
1、安装squid
[root@localhost wj]# rpm -qa | grep squid
[root@localhost wj]# yum install -y squid
Installed:
squid.i686 7:3.1.10-19.el6_4
Complete!
[root@localhost wj]# 2、设置防火墙,squid默认使用3128端口,用户可以自行修改一些不冲突的端口,之后要在防火墙中添加端口
[root@localhost wj]# gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3128 -j ACCEPT [root@localhost phpMyAdmin]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter nat [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
iptables:载入额外模块:nf_conntrack_ftp [确定]
[root@localhost phpMyAdmin]# 3、启动squid服务
[root@localhost wj]# service squid start
正在启动 squid:. [确定]
[root@localhost wj]# 4、测试,在浏览器中设置http代理为Linux的ip,端口号3128
随便打开一个网站,可以看到还是能正常访问,说明配置成功
代理服务器会在本地硬盘设置缓存,这样可以提高网络效率
1、修改squid配置文件“/etc/squid/squid.conf”,参数“cache_dir_ufs”就是设置缓存目录的
[root@localhost wj]# gedit /etc/squid/squid.conf
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256 //缓存目录var/spool/squid,大小100M2、重启squid服务
[root@localhost wj]# service squid start
正在启动 squid:. [确定]
[root@localhost wj]# gedit /etc/squid/squid.conf
[root@localhost wj]# service squid restart
停止 squid:2018/08/15 11:17:31| WARNING cache_mem is larger than total disk cache space!
................ [确定]
init_cache_dir /var/spool/squid... 正在启动 squid:. [确定]
[root@localhost wj]# 3、查看squid缓存目录,其中swap.state会随着访问网页的增多二逐渐增大
[root@localhost wj]# ls -al /var/spool/squid/
总用量 76
drwxr-x--- 18 squid squid 4096 8月 15 11:18 .
drwxr-xr-x. 15 root root 4096 8月 15 10:50 ..
drwxr-x--- 258 squid squid 4096 8月 15 11:18 00
drwxr-x--- 258 squid squid 4096 8月 15 11:18 01
drwxr-x--- 258 squid squid 4096 8月 15 11:18 02
drwxr-x--- 258 squid squid 4096 8月 15 11:18 03
drwxr-x--- 258 squid squid 4096 8月 15 11:18 04
drwxr-x--- 258 squid squid 4096 8月 15 11:18 05
drwxr-x--- 258 squid squid 4096 8月 15 11:18 06
drwxr-x--- 258 squid squid 4096 8月 15 11:18 07
drwxr-x--- 258 squid squid 4096 8月 15 11:18 08
drwxr-x--- 258 squid squid 4096 8月 15 11:18 09
drwxr-x--- 258 squid squid 4096 8月 15 11:18 0A
drwxr-x--- 258 squid squid 4096 8月 15 11:18 0B
drwxr-x--- 258 squid squid 4096 8月 15 11:18 0C
drwxr-x--- 258 squid squid 4096 8月 15 11:18 0D
drwxr-x--- 258 squid squid 4096 8月 15 11:18 0E
drwxr-x--- 258 squid squid 4096 8月 15 11:18 0F
-rw-r----- 1 squid squid 52 8月 15 11:18 swap.state
[root@localhost wj]#4、定期清理缓存
在squid的缓存目录下,swap.state慢慢的变大,用户需要定时清除这个文件,或者可以做一个计划任务来清除。 做了一个Linux学习的平台,目前出来一个个形,各位可以参考使用
链接:https ://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ密码:n7bk
Squid可以有效的限制连接,指定哪些用户可以连接,指定哪些网站可以访问,这样就可以有效的利用服务器带宽。
1、限制指定网段不能连接。编辑配置文件”/etc/squid/squid.conf”,利用acl语言添加受限制的ip地址
[root@localhost wj]# gedit /etc/squid/squid.conf
acl clientdeny src 192.168.0.1-192.168.0.200
http_access deny clientdeny [root@localhost wj]# service squid restart
停止 squid:................ [确定]
正在启动 squid:. [确定]
重启squid之后,使用这个代理的浏览器将不能访问任何网页
2、限制某个ip不能使用呢,和上面的一样使用acl语法
[root@localhost wj]# gedit /etc/squid/squid.conf
acl clientdeny src 192.168.0.113
http_access deny clientdeny [root@localhost wj]# service squid restart
停止 squid:................ [确定]
正在启动 squid:. [确定]
重启squid之后,IP地址为“192.168.0.113”的电脑如果用了这个代理,那么它将不能访问网站
3、限制某些网站不能访问
[root@localhost wj]# gedit /etc/squid/squid.conf
acl domaindeny dstdomain .baidu.com
http_access deny domaindeny [root@localhost wj]# service squid restart
停止 squid:................ [确定]
正在启动 squid:. [确定]
重启squid之后,使用这个代理的浏览器将不能访问百度
4、网站黑名单,可以通过一个网站列表文件形成网站黑名单,这些网站将不能被访问。
1)在/etc/squid目录下创建爱你一个文件denyurl,在此文件内输入要拦截的网站
[root@localhost wj]# gedit /etc/squid/denyurl
.baidu.com
.hao123.com [root@localhost wj]# service squid restart
停止 squid:................ [确定]
正在启动 squid:. [确定]
2)修改配置文件“/etc/squid/squid.conf”
[root@localhost wj]# gedit /etc/squid/squid.conf
acl denyurl url_regex "/etc/squid/denyurl" //注意这个路径就是上面定义的文件路径
http_access deny denyurl [root@localhost wj]# service squid restart
停止 squid:................ [确定]
正在启动 squid:. [确定]
3)访问百度和hao123
5、限制某个时间段内不能连接
[root@localhost wj]# gedit /etc/squid/squid.conf
acl timedeny time M 10:00-17:00 //M周一 T周二 W周三 H周四 F周五 A周六 S周日
http_access deny clientdeny [root@localhost wj]# service squid restart
停止 squid:................ [确定]
正在启动 squid:. [确定]
重启squid之后,使用这个电脑的代理将无法再星期一的10~17点上网