我是靠谱客的博主 活泼柚子,这篇文章主要介绍创建非yum安装的nginx、mongodbt开机自启配置文件,现在分享给大家,希望可以做个参考。

       在CentOS7用源码包安装服务,不同yum源安装那么方便,安装完后不能直接用systemctl命令去实现服务开启、关闭和开启自启动。但是,yum安装时的不好地方是里面的rpm包是别人已经封装好的了,安装的文件路径和配置参数是别人设置好的,要修改也有点麻烦。很多人觉得源码安装的服务较yum源安装稳定,自定义性强,故要创建源码安装的服务,开机自启配置文件!

一、设置相关服务开机自启的daemon

++华丽的分隔线++++++++++++++++++++++++++++++++++++++++++++++++++

文件路径:/usr/lib/systemd/system

(在/usr/lib/systemd/system里创建的nginx.service会在/lib/systemd/system里生成一份一样的)

++1、nginx.service配置文件+++++++++++++++++++++++++++++++++++++

vi  /usr/lib/systemd/system/nginx.service

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit] Description=nginx  After=network.target     [Service]  Type=forking  ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx reload ExecStop=/usr/local/nginx/sbin/nginx quit PrivateTmp=true     [Install]  WantedBy=multi-user.target

++2、mongodb.service配置文件+++++++++++++++++++++++++++++++++++++

vi  /usr/lib/systemd/system/mongodb.service

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking RuntimeDirectory=mongodb PIDFile=/usr/local/mongodb/data/db/mongod.lock ExecStart=/usr/local/mongodb/bin/mongod --smallfiles --config /usr/local/mongodb/etc/mongodb.conf ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/etc/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target

 

二、最后步骤:(每个服务)给执行权限,起服务,设置服务开机自启动
[root@localhost ~]# chmod a+x /usr/lib/systemd/system/nginx.service 
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to  /usr/lib/systemd/system/nginx.service.
[root@localhost ~]# systemctl is-enabled nginx
enabled

(注:整套过程无报错即可,如果照上面复制还有报错的话,就是字体问题,请手打吧....)

最后

以上就是活泼柚子最近收集整理的关于创建非yum安装的nginx、mongodbt开机自启配置文件的全部内容,更多相关创建非yum安装内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部