热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

rhel5.5搭建网关+LAMP+postfix+dhcp的步骤和配置方法

本文介绍了在rhel5.5操作系统下搭建网关+LAMP+postfix+dhcp的步骤和配置方法。通过配置dhcp自动分配ip、实现外网访问公司网站、内网收发邮件、内网上网以及SNAT转换等功能。详细介绍了安装dhcp和配置相关文件的步骤,并提供了相关的命令和配置示例。

环境介绍
公司使用的是pppoe的adsl连接,没有固定ip。 现在要求做一台linux网关服务器。实现以下几点要求:
1.dhcp自动分配ip
2.外网可以访问公司网站
3.内网可以和外网互相收发邮件
4.内网可以上网,做SNAT转换
我选择的是rhel5.5的操作系统完成
安装dhcp
[root@xieping ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:28:04:C2
ONBOOT=yes
IPADDR=192.168.1.254
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
vim /etc/yum.repos.d/rhel-debuginfo.repo 
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///media/Server
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
yum clean all
[root@xieping ~]# yum clean all
[root@xieping ~]# yum install -y dhcp
[root@xieping ~]# cp -p /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf 
[root@xieping ~]# vim /etc/dhcpd.conf

ddns-update-style none;
subnet 192.168.1.0 netmask 255.255.255.0 {
        range           192.168.1.100   192.168.1.200;
        option routers                  192.168.1.254;
        option subnet-mask              255.255.255.0;
        option domain-name              "quantanetwork.com";
        option domain-name-servers      202.106.0.20,121.12.174.212;
        default-lease-time 21600;
        max-lease-time 43200;
}
[root@xieping ~]# /etc/init.d/dhcpd restart
[root@xieping ~]# chkconfig dhcpd on
[root@xieping httpd-2.2.9]# tar zxf httpd-2.2.9.tar.gz -C /usr/src/
[root@xieping httpd-2.2.9]# cd /usr/src/
[root@xieping httpd-2.2.9]# ./configure --prefix=/usr/local/apache2 
--enable-so --enable-rewrite
报错信息:
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
configure failed for srclib/apr
解决办法:
[root@xieping ~]# yum install -y  gcc

[root@xieping ~]# make && make install
[root@xieping apache2]# /usr/local/apache2/bin/apachectl start
[root@xieping apache2]# echo /usr/local/apache2/bin/apachectl restart >> /etc/rc.d/rc.local

mysql
[root@quantanetwork mysql-5.0.56]# tar zxf mysql-5.0.56.tar.gz -C /usr/src/ 
[root@quantanetwork mysql-5.0.56]# cd /usr/src/mysql-5.0.56/
[root@quantanetwork mysql-5.0.56]# useradd -M  -s /sbin/nologin  mysql
[root@quantanetwork mysql-5.0.56]# ./configure --prefix=/usr/local/mysql

报错信息
checking for termcap functions library... configure: error: No curses/termcap library found
解决办法:
[root@quantanetwork mysql-5.0.56]# yum install -y ncurses-devel
[root@quantanetwork mysql-5.0.56]# yum install -y gcc*
[root@quantanetwork mysql-5.0.56]# ./configure --prefix=/usr/local/mysql
[root@quantanetwork mysql-5.0.56]#make && make install
[root@quantanetwork mysql-5.0.56]# cp support-files/my-medium.cnf /etc/my.cnf
[root@quantanetwork mysql-5.0.56]# chown  -R  mysql       /usr/local/mysql/var  
[root@quantanetwork mysql-5.0.56]# chown  -R  root:mysql  /usr/local/mysql  
[root@quantanetwork mysql-5.0.56]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@quantanetwork mysql-5.0.56]# /usr/local/mysql/bin/mysqld_safe  --user=mysql &
[root@quantanetwork mysql-5.0.56]# netstat  -nutlp | grep :3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      21660/mysqld
[root@quantanetwork mysql-5.0.56]# echo "/usr/local/mysql/bin/mysqld_safe  --user=mysql &" >> /etc/rc.d/rc.local
[root@quantanetwork ~]# export PATH=$PATH:/usr/local/mysql/bin/
[root@quantanetwork ~]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
[root@quantanetwork ~]# mysqladmin -u root password "system"
PHP的安装
[root@quantanetwork php-5.2.6]# tar xjf php-5.2.6.tar.bz2 -C /usr/src/
[root@quantanetwork php-5.2.6]# cd /usr/src/php-5.2.6/ 
[root@quantanetwork php-5.2.6]# ./configure  --prefix=/usr/local/php5  --enable-mbstring  --with-apxs2=/usr/local/apache2/bin/apxs  --with-mysql=/usr/local/mysql  --with-config-file-path=/usr/local/php5
报错信息:
configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法:
[root@quantanetwork php-5.2.6]#yum install libxml2-devel -y
[root@quantanetwork php-5.2.6]# ./configure  --prefix=/usr/local/php5  --enable-mbstring  --with-apxs2=/usr/local/apache2/bin/apxs  --with-mysql=/usr/local/mysql  --with-config-file-path=/usr/local/php5
[root@quantanetwork php-5.2.6]#make && make install
[root@quantanetwork php-5.2.6]# cp php.ini-dist /usr/local/php5/php.ini
[root@quantanetwork php-5.2.6]# vim /usr/local/apache2/conf/httpd.conf
在LoadModule  php5_module   modules/libphp5.so下面新加入一条
Addtype application/x-httpd-php .php
  在默认首页直接加入index.php
    DirectoryIndex index.php index.html

[root@quantanetwork php-5.2.6]# /usr/local/apache2/bin/apachectl restart
网站数据和数据库数据的导入导出
[root@quantanetwork php-5.2.6]# rsync -avz root@192.168.1.5:/opt/lampp/htdocs/* /usr/local/apache2/htdocs/
[root@quantanetwork htdocs]# /usr/local/apache2/bin/apachectl stop
[root@quantanetwork htdocs]# /usr/local/apache2/bin/apachectl start
数据库的导出:进入192.168.1.5 执行
root@kunte:~#mysqldump -u root -p --all-databases > /root/mysql_2012_7_20.sql
回到192,168.1.254
[root@quantanetwork htdocs]# 
rsync -avz root@192.168.1.5:/root/mysql_2012_7_20.sql /root/
[root@quantanetwork htdocs]# mysql  -u root -p postfix的搭建(外网收发)
[root@quantanetwork postfix]# /etc/init.d/sendmail stop
[root@quantanetwork postfix]# chkconfig sendmail off
[root@quantanetwork postfix]# tar zxf postfix-2.4.6.tar.gz -C /usr/src/
[root@quantanetwork postfix]# cp postfix-2.4.6-vda-ng.patch.gz /usr/src/
[root@quantanetwork postfix]# cd /usr/src/
[root@quantanetwork src]# gunzip postfix-2.4.6-vda-ng.patch.gz 
[root@quantanetwork src]# cd /usr/src/postfix-2.4.6
[root&#64;quantanetwork postfix-2.4.6]# patch -p1 <../postfix-2.4.6-vda-ng.patch
[root&#64;quantanetwork postfix-2.4.6]# groupadd  -g  1200  postdrop
[root&#64;quantanetwork postfix-2.4.6]# groupadd  -g  1000  postfix
[root&#64;quantanetwork postfix-2.4.6]# useradd   -u  1000  -g  postfix  -G  postdrop  postfix
[root&#64;quantanetwork postfix-2.4.6]# make makefiles &#39;CCARGS&#61;-DHAS_MYSQL -I/usr/local/mysql/include/mysql  -DUSE_SASL_AUTH  -DUSE_CYRUS_SASL -I/usr/include/sasl&#39; &#39;AUXLIBS&#61;-L/usr/local/mysql/lib/mysql -lmysqlclient  -lz  -lm  -L/usr/lib/sasl2  -lsasl2&#39;
报错信息
make -f Makefile.in MAKELEVEL&#61; Makefiles
(echo "# Do not edit -- this file documents how Postfix was built for your machine."; /bin/sh makedefs) >makedefs.tmp
No include file found.
Install the appropriate db*-devel package first.
See the RELEASE_NOTES file for more information.
make: *** [Makefiles] 错误 1
make: *** [makefiles] 错误 2
解决办法&#xff1a;
[root&#64;quantanetwork postfix-2.4.6]# yum install -y db*-devel
[root&#64;quantanetwork postfix-2.4.6]# make makefiles &#39;CCARGS&#61;-DHAS_MYSQL -I/usr/local/mysql/include/mysql  -DUSE_SASL_AUTH  -DUSE_CYRUS_SASL -I/usr/include/sasl&#39; &#39;AUXLIBS&#61;-L/usr/local/mysql/lib/mysql -lmysqlclient  -lz  -lm  -L/usr/lib/sasl2  -lsasl2&#39;
[root&#64;quantanetwork postfix-2.4.6]#make && make install 
报错信息&#xff1a;
xsasl_cyrus_server.c:597: 错误&#xff1a;‘XSASL_CYRUS_SERVER’ 没有名为 ‘username’ 的成员
xsasl_cyrus_server.c:598: 错误&#xff1a;‘XSASL_CYRUS_SERVER’ 没有名为 ‘username’ 的成员
make: *** [xsasl_cyrus_server.o] 错误 1
make: *** [update] 错误 1
解决办法:
[root&#64;quantanetwork postfix-2.4.6]# yum install -y cyrus-sasl-devel
[root&#64;quantanetwork postfix]# yum install -y cyrus-sasl-md5
[root&#64;quantanetwork postfix]# make && make install
报错信息&#xff1a;
error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory
解决办法&#xff1a;
[root&#64;quantanetwork postfix-2.4.6]# echo "/usr/local/mysql/lib/mysql/">> /etc/ld.so.conf
[root&#64;quantanetwork postfix-2.4.6]#ldconfig /etc/ld.so.conf
[root&#64;quantanetwork postfix-2.4.6]#make && make install
install_root: [/] 回车
tempdir: [/usr/src/postfix-2.4.6] 回车
config_directory: [] /etc/postfix
daemon_directory: [] /usr/libexec/postfix
command_directory: [] /usr/sbin
queue_directory: [] /var/spool/postfix
sendmail_path: [] /usr/sbin/sendmail
newaliases_path: [] /usr/bin/newaliases
mailq_path: [] /usr/bin/mailq
mail_owner: [] postfix
setgid_group: [] postdrop
html_directory: [] no
manpage_directory: [] /usr/local/man
readme_directory: [] no
[root&#64;quantanetwork postfix]# postconf -n >> main.cf

[root&#64;quantanetwork postfix]# cd /etc/postfix/
[root&#64;quantanetwork postfix]# vim main.cf
最后面加入&#xff1a;
inet_interfaces &#61; all
myhostname &#61; mail.quantanetwork.com
mydomain &#61; quantanetwork.com
myorigin &#61; $mydomain
mydestination &#61; $mydomain, $myhostname
home_mailbox &#61; Maildir/
[root&#64;quantanetwork postfix]# postfix start
[root&#64;quantanetwork postfix]# echo "/usr/sbin/postfix start" >> /etc/rc.d/rc.local
[root&#64;quantanetwork postfix]# tar zxf dovecot-1.1.4.tar.gz -C /usr/src/
[root&#64;quantanetwork postfix]# useradd -M -s /sbin/nologin dovecot
[root&#64;quantanetwork postfix]# cd /usr/src/dovecot-1.1.4/
[root&#64;quantanetwork dovecot-1.1.4]# yum install -y pam-devel
[root&#64;quantanetwork dovecot-1.1.4]# ./configure --sysconfdir&#61;/etc --with-mysql
[root&#64;quantanetwork dovecot-1.1.4]#make && make install
[root&#64;quantanetwork dovecot-1.1.4]# cp /etc/dovecot-example.conf /etc/dovecot.conf
[root&#64;quantanetwork dovecot-1.1.4]# vim /etc/dovecot.conf 
vim  /etc/dovecot.conf
  23  protocols &#61; pop3 imap
  47  disable_plaintext_auth &#61; no
  87  ssl_disable &#61; yes
  208 mail_location &#61; maildir:~/Maildir

[root&#64;quantanetwork dovecot-1.1.4]#vim /etc/pam.d/dovecot
auth     required pam_nologin.so
auth    include system-auth
account include system-auth
session include system-auth
[root&#64;quantanetwork dovecot-1.1.4]# /usr/local/sbin/dovecot -c /etc/dovecot.conf
[root&#64;quantanetwork dovecot-1.1.4]# echo "/usr/local/sbin/dovecot -c /etc/dovecot.conf" >> /etc/rc.d/rc.local
[root&#64;quantanetwork dovecot-1.1.4]# netstat -anpt | grep dovecot
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      12642/dovecot       
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      12642/dovecot 
[root&#64;quantanetwork dovecot-1.1.4]#cp /usr/lib/sasl2/Sendmail.conf  /usr/lib/sasl2/smtpd.conf
[root&#64;quantanetwork dovecot-1.1.4]#/etc/init.d/saslauthd restart
[root&#64;quantanetwork dovecot-1.1.4]#chkconfig saslauthd on
[root&#64;quantanetwork dovecot-1.1.4]#vim  /etc/postfix/main.cf
mailbox_size_limit &#61; 524288000 //限制用户邮箱大小500M
message_size_limit &#61; 50889600  //限制可发送邮件大小50M 
smtpd_sasl_auth_enable &#61; yes 
smtpd_sasl_security_options &#61; noanonymous  
smtpd_recipient_restrictions&#61;permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination 
[root&#64;quantanetwork dovecot-1.1.4]#postfix reload
PPPOE搭建
[root&#64;quantanetwork dovecot-1.1.4]#yum install rp-pppoe -y
[root&#64;quantanetwork dovecot-1.1.4]#adsl-setup ← 建立ADSL连接
Welcome to the ADSL client setup. First, I will run some checks on
 your system to make sure the PPPoE client is installed properly...

LOGIN NAME

Enter your Login Name (default root): ← 填入ADSL连接的用户名

INTERFACE

Enter the Ethernet interface connected to the ADSL modem
 For Solaris, this is likely to be something like /dev/hme0.
 For Linux, it will be ethX, where &#39;X&#39; is a number.
 (default eth0): ← 指定网络接入设备&#xff0c;一块网卡的情况下&#xff0c;一般为默认eth0

Do you want the link to come up on demand, or stay up continuously?
 If you want it to come up on demand, enter the idle time in seconds
 after which the link should be dropped. If you want the link to
 stay up permanently, enter &#39;no&#39; (two letters, lower-case.)
 NOTE: Demand-activated links do not interact well with dynamic IP
 addresses. You may have some problems with demand-activated links.
 Enter the demand value (default no): ← 直接按回车&#xff0c;接受默认设置

DNS

Please enter the IP address of your ISP&#39;s primary DNS server.
 If your ISP claims that &#39;the server will provide dynamic DNS addresses&#39;,
 enter &#39;server&#39; (all lower-case) here.
 If you just press enter, I will assume you know what you are
 doing and not modify your DNS setup.
 Enter the DNS information here: ← 如果知道DNS服务器的信息在此填入。不知道的情况按回车跳过

PASSWORD

Please enter your Password: ← 输入ADSL的连接密码
 Please re-enter your Password: ← 再次确认输入ADSL的连接密码

USERCTRL

Please enter &#39;yes&#39; (two letters, lower-case.) if you want to allow
 normal user to start or stop DSL connection (default yes): no ← 填入no&#xff0c;不允许一般用户控制PPPoE的连接

FIREWALLING

Please choose the firewall rules to use. Note that these rules are
 very basic. You are strongly encouraged to use a more sophisticated
 firewall setup; however, these will provide basic security. If you
 are running any servers on your machine, you must choose &#39;NONE&#39; and
 set up firewalling yourself. Otherwise, the firewall rules will deny
 access to all standard servers like Web, e-mail, ftp, etc. If you
 are using SSH, the rules will block outgoing SSH connections which
 allocate a privileged source port.

The firewall choices are:
 0 - NONE: This script will not set any firewall rules. You are responsible
 for ensuring the security of your machine. You are STRONGLY
 recommended to use some kind of firewall rules.
 1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
 2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
 for a LAN
 Choose a type of firewall (0-2): 0 ← 输入0&#xff0c;不在这里使用防火墙

Start this connection at boot time

Do you want to start this connection at boot time?
 Please enter no or yes (default no): yes ← 填入yes&#xff0c;在系统启动时自动连接ADSL

** Summary of what you entered **

Ethernet Interface: eth0
 User name: caun870293&#64;ca.dti.ne.jp
 Activate-on-demand: No
 DNS: Do not adjust
 Firewalling: NONE
 User Control: no
 Accept these settings and adjust configuration files (y/n)? y ← 配置信息确认无误后&#xff0c;键入y同意设置
 Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
 Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
 (But first backing it up to /etc/ppp/chap-secrets.bak)
 (But first backing it up to /etc/ppp/pap-secrets.bak)

?

Congratulations, it should be all set up!

Type &#39;/sbin/ifup ppp0&#39; to bring up your xDSL link and &#39;/sbin/ifdown ppp0&#39;
 to bring it down.
 Type &#39;/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0&#39;
 to see the link status.

 

    2.4) 启动PPPOE客户端软件
 # adsl-start ← 启动ADSL连接 
# ← 稍等片刻后若启动成功后出现提示符&#xff08;无任何提示或Connected意味着连接成功&#xff09;

如果不成功&#xff0c;请检查网线、ADSL MODEM等物理设备&#xff0c;并查看 /var/log/messages中的信息 
 /usr/sbin/adsl-stop 关闭和ISP的连接 
 /usr/sbin/adsl-status 查看当前连接的状态 
 
如果想在Linux系统启动时自动启动ADSL连接&#xff0c;输入以下命令 
 #chkconfig --add adsl 
 将在当前的运行级下加入ADSL的自启动脚本


2.5) 测试 
当连接成功后.使用命令 ifconfig -a 在输出中应该含有关于 ppp0 的一堆信息

SNAT
[root&#64;quantanetwork dovecot-1.1.4]#iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE
[root&#64;quantanetwork dovecot-1.1.4]#/etc/init.d/iptables save













本文转自谢无赖51CTO博客&#xff0c;原文链接&#xff1a;http://blog.51cto.com/xieping/936216 &#xff0c;如需转载请自行联系原作者






推荐阅读
  • CentOS 7.6环境下Prometheus与Grafana的集成部署指南
    本文旨在提供一套详细的步骤,指导读者如何在CentOS 7.6操作系统上成功安装和配置Prometheus 2.17.1及Grafana 6.7.2-1,实现高效的数据监控与可视化。 ... [详细]
  • 在Fedora 31上部署PostgreSQL 12
    本文详细介绍如何在Fedora 31操作系统上安装和配置PostgreSQL 12数据库。包括环境准备、安装步骤、配置优化以及安全设置,确保数据库能够稳定运行并提供高效的性能。 ... [详细]
  • 本章详细介绍SP框架中的数据操作方法,包括数据查找、记录查询、新增、删除、更新、计数及字段增减等核心功能。通过具体示例和详细解析,帮助开发者更好地理解和使用这些方法。 ... [详细]
  • 本文将详细介绍如何在没有显示器的情况下,使用Raspberry Pi Imager为树莓派4B安装操作系统,并进行基本配置,包括设置SSH、WiFi连接以及更新软件源。 ... [详细]
  • Django 使用slug field时遇到的问题 ... [详细]
  • Django Token 认证详解与 HTTP 401、403 状态码的区别
    本文详细介绍了如何在 Django 中配置和使用 Token 认证,并解释了 HTTP 401 和 HTTP 403 状态码的区别。通过具体的代码示例,帮助开发者理解认证机制及权限控制。 ... [详细]
  • 本文详细介绍了 Kubernetes 集群管理工具 kubectl 的基本使用方法,涵盖了一系列常用的命令及其应用场景,旨在帮助初学者快速掌握 kubectl 的基本操作。 ... [详细]
  • 本文探讨了如何在Node.js环境中,通过Tor网络使用的SOCKS5代理执行HTTP请求。文中不仅提供了基础的实现方法,还介绍了几种常用的库和工具,帮助开发者解决遇到的问题。 ... [详细]
  • iTOP4412开发板QtE5.7源码编译指南
    本文详细介绍了如何在iTOP4412开发板上编译QtE5.7源码,包括所需文件的位置、编译器设置、触摸库编译以及QtE5.7的完整编译流程。 ... [详细]
  • ElasticSearch 集群监控与优化
    本文详细介绍了如何有效地监控 ElasticSearch 集群,涵盖了关键性能指标、集群健康状况、统计信息以及内存和垃圾回收的监控方法。 ... [详细]
  • 本文探讨了如何在Classic ASP中实现与PHP的hash_hmac('SHA256', $message, pack('H*', $secret))函数等效的哈希生成方法。通过分析不同实现方式及其产生的差异,提供了一种使用Microsoft .NET Framework的解决方案。 ... [详细]
  • 优化SQL Server批量数据插入存储过程的实现
    本文介绍了一种改进的SQL Server存储过程,用于生成批量插入语句。该方法不仅提高了性能,还支持单行和多行模式,适用于SQL Server 2005及以上版本。 ... [详细]
  • 本文介绍了在MacOS上通过Homebrew安装Anaconda3,并配置环境变量以实现不同Python版本之间的快速切换。同时,提供了详细的步骤来创建和管理多个Python环境。 ... [详细]
  • NFS(Network File System)即网络文件系统,是一种分布式文件系统协议,主要用于Unix和类Unix系统之间的文件共享。本文详细介绍NFS的配置文件/etc/exports和相关服务配置,帮助读者理解如何在Linux环境中配置NFS客户端。 ... [详细]
  • 在Linux系统上构建Web服务器的详细步骤
    本文详细介绍了如何在Linux系统上搭建Web服务器的过程,包括安装Apache、PHP和MySQL等关键组件,以及遇到的一些常见问题及其解决方案。 ... [详细]
author-avatar
陈宥治政和瑋男
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有