热门标签 | 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;如需转载请自行联系原作者






推荐阅读
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • 如何配置Unturned服务器及其消息设置
    本文详细介绍了Unturned服务器的配置方法和消息设置技巧,帮助用户了解并优化服务器管理。同时,提供了关于云服务资源操作记录、远程登录设置以及文件传输的相关补充信息。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • CentOS7源码编译安装MySQL5.6
    2019独角兽企业重金招聘Python工程师标准一、先在cmake官网下个最新的cmake源码包cmake官网:https:www.cmake.org如此时最新 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 优化联通光猫DNS服务器设置
    本文详细介绍了如何为联通光猫配置DNS服务器地址,以提高网络解析效率和访问体验。通过智能线路解析功能,域名解析可以根据访问者的IP来源和类型进行差异化处理,从而实现更优的网络性能。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本周信息安全小组主要进行了CTF竞赛相关技能的学习,包括HTML和CSS的基础知识、逆向工程的初步探索以及整数溢出漏洞的学习。此外,还掌握了Linux命令行操作及互联网工作原理的基本概念。 ... [详细]
  • 本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ... [详细]
  • 本文深入探讨了Linux系统中网卡绑定(bonding)的七种工作模式。网卡绑定技术通过将多个物理网卡组合成一个逻辑网卡,实现网络冗余、带宽聚合和负载均衡,在生产环境中广泛应用。文章详细介绍了每种模式的特点、适用场景及配置方法。 ... [详细]
  • 本文详细分析了Hive在启动过程中遇到的权限拒绝错误,并提供了多种解决方案,包括调整文件权限、用户组设置以及环境变量配置等。 ... [详细]
  • 本文详细介绍如何使用Samba软件配置CIFS文件共享服务,涵盖安装、配置、权限管理及多用户挂载等关键步骤。通过具体示例和命令行操作,帮助读者快速搭建并优化Samba服务器。 ... [详细]
  • 本文详细介绍如何使用arm-eabi-gdb调试Android平台上的C/C++程序。通过具体步骤和实用技巧,帮助开发者更高效地进行调试工作。 ... [详细]
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社区 版权所有