生产环境中添加以非root用户进行nginx、tomcat、nodejs等开机自启动

一、添加开机自启服务
在centos7中添加开机自启服务非常方便,只需要两条命令(以nginx为例):
# systemctl enable nginx.service #设置nginx服务为自启动服务
# sysstemctl start  nginx.service #启动nginx服务
 
二、添加开机自启脚本
在centos7中增加脚本有两种常用的方法,以脚本autostart.sh为例:
# cat autostart.sh
 
#!/bin/bash
# description: 开机自启脚本
/opt/tomcat/bin/startup.sh  #启动tomcat
 
方式一:
1、赋予脚本可执行权限(/opt/script/autostart.sh是你的脚本路径)
# chmod a+x /opt/script/autostart.sh
 
2、打开/etc/rc.d/rc.local文件,在末尾增加如下内容
/opt/script/autostart.sh
 
3、在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
# chmod a+x /etc/rc.d/rc.local
 
方式二:
1、将脚本移动到/etc/rc.d/init.d目录下
# cp  /opt/script/autostart.sh /etc/rc.d/init.d
 
2、增加脚本的可执行权限
# chmod a+x  /etc/rc.d/init.d/autostart.sh
 
3、添加脚本到开机自动启动项目中
# cd /etc/rc.d/init.d
# chkconfig --add autostart.sh
# chkconfig autostart.sh on
 
 
 
直接使用# sudo -u app sh /opt/tomcat/bin/startup.sh   无法正常启动tomcat,因为未正常读取到java的环境变量,即便是在app用户家目录下.bash_profile定义java环境变量仍然是无法正常启动。
解决办法:
在startup.sh中增加java环境变量,则可解决问题。
 
如果不使用 sudo -u app bash /opt/tomcat/bin/startup.sh,使用 su - app -c "bash /opt/tomcat/bin/startup.sh" 可正常启动。
 
坑:
centos7系统的/etc/rc.d/rc.local默认没有执行权限,所以如果将开机自启动的命令写在该处,这需增加执行权限
# chmod a+x /etc/rc.d/rc.local
 
 
 
 
 
 

转载于:https://www.cnblogs.com/wplvqj/p/10537026.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,关于Vue项目在生产环境如何使用Nginx、Apache、Tomcat等应用服务器进行部署,我可以给您提供一些参考信息。 1. Nginx部署Vue项目 Nginx是一个高性能的Web服务器,可以用于部署Vue项目。下面是部署Vue项目的简单步骤: 1)安装Nginx; 2)将Vue项目打包,得到dist文件夹; 3)将dist文件夹拷贝到Nginx的html目录下; 4)修改Nginx的配置文件,将请求转发至Vue项目的index.html文件; 5)启动Nginx。 以下是一个简单的Nginx配置文件示例: ``` server { listen 80; server_name yourdomain.com; root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ /index.html; } } ``` 2. Apache部署Vue项目 Apache是另一个常用的Web服务器,也可以用于部署Vue项目。下面是部署Vue项目的简单步骤: 1)安装Apache; 2)将Vue项目打包,得到dist文件夹; 3)将dist文件夹拷贝到Apache的htdocs目录下; 4)修改Apache的配置文件,将请求转发至Vue项目的index.html文件; 5)启动Apache。 以下是一个简单的Apache配置文件示例: ``` <VirtualHost *:80> ServerName yourdomain.com DocumentRoot /var/www/html <Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </Directory> </VirtualHost> ``` 3. Tomcat部署Vue项目 Tomcat是一个Java应用服务器,也可以用于部署Vue项目。下面是部署Vue项目的简单步骤: 1)安装Tomcat; 2)将Vue项目打包,得到dist文件夹; 3)将dist文件夹拷贝到Tomcat的webapps目录下; 4)修改Tomcat的配置文件,将请求转发至Vue项目的index.html文件; 5)启动Tomcat。 以下是一个简单的Tomcat配置文件示例: ``` <Context path="/" docBase="/path/to/dist"> <Resources> <PreResources className="org.apache.catalina.webresources.DirResourceSet" base="/path/to/dist" webAppMount="/"> </PreResources> </Resources> </Context> ``` 希望以上信息可以对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值