场景:普通用户编译的apache,要在该用户下启动1024端口以下的apache端口

1、假设普通用户为sims20,用该用户编译 安装了一个apache,安装路径为/opt/aspire/product/sims20/apache

./configure --prefix=/opt/aspire/product/sims20/apache   --enable-so --enable-modules=all   --enable-mods-shared=all   --enable-mods-shared='proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http proxy_rewrite'

make
  make install

2、编译完成后,设置http.conf的监听端口为80

3、直接用普通用户sims20启动

[sims20@bcd-app01 bin]$ ./apachectl  start
(13)Permission denied: make_sock: could not bind
to address [::]:80
(13)Permission
denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting
down
Unable to open
logs

出错原因:在linux下,普通用户只能用1024以上的端口,而1024以内的端口只能由root用户才可以使用

4、利用setuid来解决问题,这样使用httpd能以root权限运行

root用户登录,进入/opt/aspire/product/sims20/apache/bin,分别用chown
root  httpd、chmod u+s httpd 设置httpd的属主为root及特殊权限

[root@bcd-app01 bin]# ls  -l 
httpd
-rwxr-xr-x 1 sims20 aspire
3517470  3月 15 17:12 httpd
[root@bcd-app01 bin]# chown
root  httpd
[root@bcd-app01 bin]# ls  -l 
httpd
-rwxr-xr-x 1 root aspire
3517470  3月 15 17:12 httpd
[root@bcd-app01 bin]# chmod u+s
httpd
[root@bcd-app01
bin]#
ls  -l  httpd
-rwsr-xr-x 1 root aspire 3517470  3月 15 17:12
httpd

5、重新进入普通用户sims20,启动apache

[sims20@bcd-app01 bin]$ ./apachectl  start

可以正常启动,没报错

6、试着访问一下

[sims20@bcd-app01 bin]$ curl 
http://10.24.12.159:80
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML
2.0//EN">
<html><head>
<title>403
Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access
/
on this
server.</p>
</body></html>

报403
Forbidden错误

7、看一下进程

[sims20@bcd-app01 bin]$ ps  -ef |grep
httpd
root      7841     1  0 17:24
?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
daemon    7844  7841  0
17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
daemon    7845  7841  0
17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
daemon    7846  7841  0
17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
daemon    7847  7841  0
17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
daemon    7848  7841  0
17:24 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
sims20    8006  3026  0
17:29 pts/4    00:00:00 grep httpd

怎么跑出daemon 用户了,  原来httpd主进程仍然以root用户的权限运行,而它的子进程将以一个较低权限的用户运行
,而这个较低权限用户daemon 在http.conf中配置

7、在http.conf中配置一下,将用户改成root
   User daemon
   Group
daemon

改成
    User root
    Group root

8、再次用普通用户启动apache

[sims20@bcd-app01 bin]$ ./apachectl  restart
Syntax
error on line 76 of
/opt/aspire/product/sims20/apache/conf/httpd.conf:
Error:\tApache has not
been designed to serve pages while\n\trunning as root.  There are known race
conditions that\n\twill allow any local user to read any file on the
system.\n\tIf you still desire to serve pages as root then\n\tadd
-DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the
server.\n\tIt is strongly suggested that you instead modify the
User\n\tdirective in your httpd.conf file to list a
non-root\n\tuser.\n

不行的,要重新加参数编译

9、再次修改在http.conf中配置一下,将用户改成普通用户吧

改成
    User sims20
    Group aspire

10、再次用普通用户sims20启动apache

[sims20@bcd-app01 bin]$ ./apachectl 
start
[sims20@bcd-app01 bin]$ ps  -ef  |grep  httpd
root      9720     1 
0 18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
sims20    9721  9720  0 18:09 ?        00:00:00
/opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9722  9720  0
18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
sims20    9723  9720  0 18:09 ?        00:00:00
/opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9724  9720  0
18:09 ?        00:00:00 /opt/aspire/product/sims20/apache/bin/httpd -k
start
sims20    9725  9720  0 18:09 ?        00:00:00
/opt/aspire/product/sims20/apache/bin/httpd -k start
sims20    9739  3026  0
18:09 pts/4    00:00:00 grep httpd

6、试着访问一下

[sims20@bcd-app01 bin]$ curl  http://10.248.12.159:80
<html><body><h1>It
works!</h1></body></html>

成功了

zzw原创_非root用户启动apache的问题解决(非root用户启动apache的1024以下端口)的更多相关文章

  1. zzw原创_非root安装fastDFS

    zzw原创_非root安装fastDFS fastDFS 想要非root安装,没找到资料,分析了一下安装脚本,原来作者是留了安装路径的,但没有放出来. 1.解包 [bdc@svr001 setup]$ ...

  2. zzw原创_非root用户下安装nginx

    想自己安装nginx,又不相用到root用户. 非root用户下(本文为用户bdctool)来ngnix安装,要依赖pcre库.zlib库等, 1. 下载依赖包:下载地址 pcre(www.pcre. ...

  3. zzw原创_解决Could not chdir to home directory /test/bdctool: Permission denied一例

    1.用命令新建一用户 adduser -d /test/bdctool  -m bdctool 2.用新用户登录,报错:Could not chdir to home directory /test/ ...

  4. zzw原创_根据某一文件复制出大量固定位数后缀名的递增的文件

    1.trre.sh   :根据某一文件复制出大量固定位数后后缀递增的文件.   如将 SPINFO_190516_20170109.001 复制成SPINFO_190516_20170109.002  ...

  5. Linux普通用户安装配置mysql(非root权限)

    Linux普通用户安装配置mysql(非root权限) 说明:在实际工作中,公司内网的机器我们一般没有root权限,也没有连网,最近参考网上的资料使用一般的账户成功安装mysql,记录如下 Linux ...

  6. linux开机启动及运行级别、root密码丢失、单用户模式只读的处理方法

    linux系统启动大致步骤如下:  加电自检-->根据BIOS中的设置从指定的设备启动-->找到设备MBR中的bootloader引导启动系统-->启动kernel-->启动i ...

  7. Linux开机启动chkconfig命令详解(让MySQL、Apache开机启动)

    chkconfig chkconfig在命令行操作时会经常用到.它可以方便地设置和查询不同运行级上的系统服务.这个可要好好掌握,用熟练之后,就可以轻轻松松的管理好你的启动服务了. 注:谨记chkcon ...

  8. 写给大忙人的centos下ftp服务器搭建(以及启动失败/XFTP客户端一直提示“用户身份验证失败”解决方法)

    注:个人对偏向于底层基本上拿来就用的应用,倾向于使用安装包,直接yum或者rpm安装:而对于应用层面控制较多或者需要大范围维护的,倾向于直接使用tar.gz版本. 对于linux下的ftp服务器,实际 ...

  9. 修改php执行用户,并使其拥有root权限

    useradd apachephp vi /etc/httpd/conf/httpd.conf 将组和用户修改成apachephp,重启apache,然后用lsof -i:80查看apache的执行用 ...

随机推荐

  1. “流式”前端构建工具——gulp.js 简介

    Grunt 一直是前端领域构建工具(任务运行器或许更准确一些,因为前端构建只是此类工具的一部分用途)的王者,然而它也不是毫无缺陷的,近期风头正劲的 gulp.js 隐隐有取而代之的态势.那么,究竟是什 ...

  2. [Android] 转-RxJava+MVP+Retrofit+Dagger2+Okhttp大杂烩

    原文url: http://blog.iliyun.net/2016/11/20/%E6%A1%86%E6%9E%B6%E5%B0%81%E8%A3%85/ 这几年来android的网络请求技术层出不 ...

  3. PHP插入数据库代码,编辑,删除

    插入代码 $action=$_GET['action']; switch($action){ //添加记录 case"add"; $mail = trim(htmlspecialc ...

  4. Spring Boot 全局异常捕获

    import javax.servlet.http.HttpServletRequest; import org.springframework.web.bind.annotation.Control ...

  5. PriorityBlockingQueue 原理分析

    PriorityBlockingQueue是一个支持优先级的无界阻塞队列,直到系统资源耗尽.默认情况下元素采用自然顺序升序排列.也可以自定义类实现compareTo()方法来指定元素排序规则,或者初始 ...

  6. u-boot2010.06移植阶段三--norflash驱动

    2011-03-20 23:06:24 学习笔记: 效果图: 参考步骤: 一,把smdk2410 # 改成apple2440 #  1,在board/samsung/apple2440/apple24 ...

  7. oracle数据库调整字段顺序

    oracle数据库调整字段顺序 https://blog.csdn.net/xiaobaixie/article/details/77892034

  8. vue组件传值

    组件的传值(组件之间的通讯) 1.父子通信 1)父传子 传递:当子组件在父组件中当做标签使用的时候,通过给子组件绑定一个自定义属性,值为需要传递的数据 接收:在子组件内部通过props进行接收 接收的 ...

  9. Vue基础进阶 之 自定义指令

    自定义指令-----钩子函数 自定义指令 除了内置指令,Vue也允许用户自定义指令: 注册指令:通过全局API Vue.directive可以注册自定义指令: 自定义指令的钩子函数: bind: in ...

  10. java面试题汇总(有的题无视即可,没什么实际用途)

    相关概念 面向对象的三个特征 封装,继承,多态,这个应该是人人皆知,有时候也会加上抽象. 多态的好处 允许不同类对象对同一消息做出响应,即同一消息可以根据发送对象的不同而采用多种不同的行为方式(发送消 ...