CentOS 7 64bit安装lighttpd服务器、配置及使用

作者: 站长 上传时间: 浏览: N/A 下载: N/A 格式: N/A 评分: N/A

国外购买的服务器配置前该先进行以下操作:
1、修改时区,使用NTP对时服务获取准确时间、将对时后的时间写入硬件以免重启后失效,参考以下博客文章
https://xiaohost.com/1806.html
2、安装中文字体包,配置终端以便显示中文(作为普通web服务器或代理服务器等一般不用安装,若作为附件服务器,需要看到文件的中文名称,则需要该步骤),参考以下博客文章
https://xiaohost.com/1241.html
3、修改ssh端口(注意修改后立即防火墙添加端口,以免ssh连不上了!!),参考
https://xiaohost.com/1164.html
针对centos 7,修改端口参考本篇博文“五、CentOS 7中firewall防火墙配置及使用方法,以及切换为iptables防火墙的方法”
firewall-cmd --permanent --add-port=xxxxx/tcp
xxxxx是你打算用的ssh端口
重新加载防火墙配置:
firewall-cmd --reload
重启sshd服务
systemctl restart sshd.service
查看sshd服务状态
systemctl status sshd.service

4、开启BBR
wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && ./bbr.sh
验证是否成功:
查看内核是否已成功升级
uname -r
使用以下命令再次验证
sysctl net.ipv4.tcp_available_congestion_control
返回值应该为net.ipv4.tcp_available_congestion_control = bbr cubic reno

sysctl net.ipv4.tcp_congestion_control
返回值应该为net.ipv4.tcp_congestion_control = bbr

sysctl net.core.default_qdisc
返回值应该为net.core.default_qdisc = fq

lsmod | grep bbr
返回值有 tcp_bbr 模块即说明 bbr 已启动。注意:并不是所有的 VPS 都会有此返回值,若没有也属正常。

5、关闭SELinux
查看SELinux状态
getenforce
Disabled
/usr/sbin/sestatus -v
SELinux status: disabled

临时关闭
##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
setenforce 0

永久关闭
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
或使用命令
sed -e "17a SELINUX=disabled" -i /etc/selinux/config
设置后需要reboot重启才能生效

一、使用包管理器安装
CentOS 7 官方软件仓库中并没有提供Lighttpd软件,所以需要在系统中安装额外的软件源epel仓库:
yum install epel-release
添加软件源后更新一下
yum update

安装lighttpd
yum install lighttpd
安装指定版本lighttpd
yum list | grep lighttpd
yum install lighttpd-xxxxxxx -y
查看安装的是不是指定版本
rpm -qa | grep lighttpd

二、编译安装lighttpd
如果还是不行,那就手动编译安装

我们以最新的版本lighttpd-1.4.48来进行演示

下载
cd /tmp/
wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.48.tar.gz
tar -xf lighttpd-1.4.48.tar.gz

cd lighttpd-1.4.48
安装所需要的包,根据需求可调整
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel zip unzip;yum -y install libtool;yum -y install bzip2-*

编译的配置参数可以通过以下命令查看,根据业务需求自行添加编译参数
./configure --help

./configure

开始编译

make && make install

一键:
cd /tmp/ && wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.46.tar.gz && tar -zxvf lighttpd-1.4.46.tar.gz && cd lighttpd-1.4.46 && ./configure --disable-ipv6 && make && make install
安装完成后
**************对日志的处理****************
使用linux系统自带的Logrotate分割&切割lighttpd日志,参照https://xiaohost.com/1356.html
—————————————————————–
三、lighttpd服务器配置文件
配置文件路径
/etc/lighttpd/lighttpd.conf
模块配置文件路径
/etc/lighttpd/modules.conf
各功能模块配置文件路径
/etc/lighttpd/conf.d/
虚拟主机配置文件位置
/etc/lighttpd/vhosts.d/
—————————————————————–
四、centos 7系统下lighttpd服务器操作命令

启动lighttpd服务:
systemctl start lighttpd
设置lighttpd服务开机启动:
systemctl enable lighttpd
重启lighttpd服务:
systemctl restart lighttpd
查看lighttpd服务当前状态:
systemctl status lighttpd
停止lighttpd服务:
systemctl stop lighttpd

卸载软件
yum remove lighttpd
如果是rpm包:
rpm -e lighttpd
tar包直接删除文件或者
make uninstall lighttpd

CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替
详细介绍可以参考https://linux.cn/article-5926-1.html

原centos 6.5及以下使用的daemon命令 centos 7 开始用的systemctl命令 命令功能说明
service [服务] start systemctl start [unit type] 启动服务
service [服务] stop systemctl stop [unit type] 停止服务
service [服务] restart systemctl restart [unit type] 重启服务

它实际上将 servicechkconfig 这两个命令组合到一起

任务 旧指令 新指令
使某服务自动启动 chkconfig –level 3 httpd on systemctl enable httpd.service
使某服务不自动启动 chkconfig –level 3 httpd off systemctl disable httpd.service
检查服务状态 service httpd status systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active)
显示所有已启动的服务 chkconfig –list systemctl list-units —type=service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service
重启某服务 service httpd restart systemctl restart httpd.service

 

实例:centos 7 NFS服务操作命令
1.启动nfs服务
systemctl start nfs-server.service
2.设置开机自启动
systemctl enable nfs-server.service
3.停止开机自启动
systemctl disable nfs-server.service
4.查看服务当前状态
systemctl status nfs-server.service
5.重新启动某服务
systemctl restart nfs-server.service
6.查看所有已启动的服务
systemctl list -units --type=service
开启防火墙22端口
iptables -I INPUT -p tcp --dport 22 -j accept
如果开启iptables有问题,就可能是SELinux导致的
关闭SElinux:
修改/etc/selinux/config文件中的SELINUX=””为disabled,然后重启。
彻底关闭防火墙:
sudo systemctl status firewalld.service
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service

其他实例:
#启动网络服务
systemctl start network.service
#停止网络服务
systemctl stop network.service
#重启网络服务
systemctl restart network.service
#查看网络服务状态
systemctl status network.serivce
#停止cup电源管理服务
systemctl stop cups.service
#禁止cups服务开机启动
systemctl disable cups.service
#查看cups服务状态
systemctl status cups.service
#重新设置cups服务开机启动
systemctl enable cups.service

systemctl命令 说明
systemctl 列出所有的系统服务
systemctl list-units 列出所有启动unit
systemctl list-unit-files 列出所有启动文件
systemctl list-units –type=service –all 列出所有service类型的unit
systemctl list-units –type=service –all grep cpu 列出 cpu电源管理机制的服务
systemctl list-units –type=target –all 列出所有target

 

systemctl特殊命令 说明
systemctl is-active [unit type] 查看服务是否运行
systemctl is-enable [unit type] 查看服务是否设置为开机启动
systemctl mask [unit type] 注销指定服务
systemctl unmask [unit type] 取消注销指定服务

—————————————————————–
五、CentOS 7中firewall防火墙配置及使用方法,以及切换为iptables防火墙的方法
1、firewall防火墙配置及使用
centos 7 与 centos6.5 防火墙区别比较大,Centos 7.x 中取消了iptables, 用firewall取而代之,官方说明文档https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html#sec-Introduction_to_firewalld1

查看firewall的状态:
firewall-cmd --state
查看防火墙规则:
firewall-cmd --list-all

开启firewall防火墙:
systemctl start firewalld.service
重启firewall防火墙:
systemctl restart firewalld.service
重新加载防火墙配置:
firewall-cmd --reload
关闭firewall防火墙:
systemctl stop firewalld.service
禁止开机启动firewall防火墙(需要先关闭firewall防火墙):
systemctl disable firewalld.service
设置firewall防火墙开机启动
systemctl enable firewalld.service

命令的方式添加端口
实例:
firewall-cmd --permanent --add-port=9527/tcp
说明:
firewall-cmd:是Linux提供的操作firewall的一个工具
–permanent:表示设置为持久
–add-port:标识添加的端口

批量添加端口实例,打开9527-10001端口:
firewall-cmd --permanent --add-port=9527-10001/tcp

实例:添加8010端口
firewall-cmd --zone=public --permanent --add-port=8010/tcp
说明:
–zone=public:指定的zone为public

删除8010端口
firewall-cmd --zone= public --permanent --remove-port=8010/tcp

查看8010端口
firewall-cmd --zone= public --query-port=8010/tcp

直接修改配置文件的方式


Public
For use in public areas.




放通指定ip,指定端口、协议

放通任意ip访问服务器的9527端口

上述配置文件内容说明:
添加需要的规则,开放通源ip为122.10.70.234,端口514,协议tcp
开放通源ip为123.60.255.14,端口10050-10051,协议tcp;/3、开放通源ip为任意,端口9527,协议tcp

—————————————————————–
2、firewall防火墙切换为iptables防火墙的步骤
(1)关闭firewall
systemctl stop firewalld.service
(2)禁止firewall开机启动
systemctl disable firewalld.service
(3)安装iptables防火墙
yum install iptables-services
(4)配置iptables防火墙(命令行或编辑配置文件方式)
命令行方式参考博文
https://xiaohost.com/1138.html
编辑防火墙配置文件方式:
vi /etc/sysconfig/iptables
下面是个配置文件示例:
Firewall configuration written by system-config-firewall

Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT

-A INPUT -j REJECT –reject-with icmp-host-prohibited

-A FORWARD -j REJECT –reject-with icmp-host-prohibited

COMMIT

保存退出
:wq!

启动iptables防火墙
service iptables start

设置防火墙开机启动
systemctl enable iptables.service

六、centos 7系统下为lighttpd安装php服务
这里以php5为例
yum install php php-cgi php-fpm php-mysql php-curl php-gd php-intl php-pecl-imagick php-mcrypt php-memcache php-pear lighttpd-fastcgi

如要让 PHP 与 Lighttpd 协同工作,我们只要根据所使用的发行版执行如下对应的指令即可。

首先要做的便是使用文件编辑器编辑 php 设置文件(例如/etc/php.ini)并取消掉对cgi.fix_pathinfo=1这一行的注释。
nano /etc/php.ini
完成上面的步骤之后,我们需要把 PHP-FPM 进程的所有权从 Apache 转移至 Lighttpd。要完成这些,首先用文件编辑器打开/etc/php-fpm.d/www.conf文件。
nano /etc/php-fpm.d/www.conf
然后在文件中增加下面的语句:
user = lighttpd
group = lighttpd

做完这些,我们保存并退出文本编辑器。然后从/etc/lighttpd/modules.conf设置文件中添加 FastCGI 模块。
nano /etc/lighttpd/modules.conf
然后,去掉下面语句前面的#来取消对它的注释。
include "conf.d/fastcgi.conf"
最后我们还需在文本编辑器设置 FastCGI 的设置文件。
nano /etc/lighttpd/conf.d/fastcgi.conf
在文件尾部添加以下代码:
fastcgi.server += ( ".php" =>
((
"host" => "127.0.0.1",
"port" => "9000",
"broken-scriptfilename" => "enable"
))
)

在编辑完成后保存并退出文本编辑器即可

如需检测 PHP 是否按预期工作,我们需在 Lighttpd 的web根目录下新建一个 php 文件
nano /var/www/info.php
然后只需将下面的语句添加到info.php文件里即可

然后通过浏览器访问这个文件

七、centos7 安装配置vsftp(生成环境已经更换为了pure-ftpd,简单易用,参考https://xiaohost.com/2423.html)

安装vsftp
yum -y install vsftpd

firewall放行FTP:
#添加ftp通行规则
firewall-cmd --add-service=ftp --permanent
#重新加载防火墙策略
firewall-cmd --reload

设置vsftp服务开机启动
systemctl enable vsftpd.service
启动vsftp服务
systemctl start vsftpd.service
查看vsftp服务状态
systemctl status vsftpd.service
重启vsftp服务
systemctl restart vsftpd.service

vsftpd的配置文件有三个
/etc/vsftpd/vsftpd.conf
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list

其中
/etc/vsftpd/vsftpd.conf是主配置文件
/etc/vsftpd/ftpusers配置哪些用户不能访问FTP服务器,应该将root用户加入
/etc/vsftpd/user_list该文件里的用户账户在默认情况下也不能访问FTP服务器,仅当vsftpd .conf配置文件里设置userlist_enable=NO选项时才允许该名单中的用户访问FTP。
通过搭配/etc/vsftpd/ftpusers 和 /etc/vsftpd/user_list可以限制指定用户可以访问。

注意:需要注释掉/etc/pam.d/vsftpd中的auth required pam_shells.so
vi /etc/pam.d/vsftpd

配置参考https://xiaohost.com/1239.html

Leave a Comment