常用Linux服务(启动,停止,查看状态,开机自启等过程)

+----------------------------------------------------------------------------------------------------------+
注意:
centos 7用systemctl这种格式
centos 6及其以下用service这种格式

+----------------------------------------------------------------------------------------------------------+
nginx服务

编译安装
    启动    /usr/local/nginx/sbin/nginx
    重启    /usr/local/nginx/sbin/nginx -s reload
    检测    /usr/local/nginx/sbin/nginx -t

设置开机自启

步骤

脚本:官网地址:https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/
注意:
自定义编译安装的nginx,需要根据您的安装路径修改下面这两项配置:
nginx=”/usr/sbin/nginx” 修改成nginx执行程序的路径。
NGINX_CONF_FILE=”/etc/nginx/nginx.conf” 修改成配置文件的路径

保存脚本文件后设置文件的执行权限:
chmod a+x /etc/init.d/nginx

然后,就可以通过该脚本对nginx服务进行管理了:
/etc/init.d/nginx start
/etc/init.d/nginx stop

使用chkconfig进行管理,先将nginx服务加入chkconfig管理列表:
chkconfig --add /etc/init.d/nginx

加完这个之后,就可以使用service对nginx进行启动,重启等操作了。
service nginx start
service nginx stop

设置终端模式开机启动:
chkconfig nginx on
+----------------------------------------------------------------------------------------------------------+
apache服务

》apahce安装目录为/usr/local/apache《
1. 启动apahce的命令:
/usr/local/apache/bin/apachectl start apache
2.  停止apache的命令:
/usr/local/apache/bin/apachectl stop  
3.  重启apache的命令:
/usr/local/apache/bin/apachectl restart
要在重启 Apache 服务器时不中断当前的连接,则应运行:
/usr/local/sbin/apachectl graceful

=================================================================
如果当前用户的apache已经安装为linux的服务的话,可以使用以下命令进行以上操作。

1. 启动apache
systemctl start httpd
或者
service httpd start 
2. 停止服务apache
systemctl stop httpd
或者
service httpd stop 
3. 重新启动apache
systemctl restart httpd
或者
service httpd restart
4.开机自启
systemctl enable httpd

+----------------------------------------------------------------------------------------------------------+
php服务

找到安装目录一直找到php-fpm,输入完整路径回车即可
启动:/usr/local/php/sbin/php-fpm
/usr/local/php-5.6.3/sbin/php-fpm -R
如果报错显示不能用root用户启动,则可以考虑使用 -R命令

================================================================
如果当前用户的apache已经安装为linux的服务的话,可以使用以下命令进行以上操作。

service php-fpm start  开启
service php-fpm stop   停止
service php-fpm restart  重启
service php-fpm enable   开机自启(可能不支持)

+----------------------------------------------------------------------------------------------------------+
mysql服务
编译安装:
    启动    /usr/local/mysql57/support-files/mysql.server   start
    停止    /usr/local/mysql57/support-files/mysql.server   stop

设置一下开机启动。
先将/usr/local/mysql57/support-files/ 文件夹下的mysql.server文件复制到 /etc/rc.d/init.d/ 目录下mysqld
命令: cp /usr/local/mysql57/support-files/mysql.server /etc/rc.d/init.d/mysqld
赋予可执行权限:chmod +x /etc/init.d/mysqld
添加为服务: chkconfig --add mysqld
查看服务列表:  chkconfig --list
【看到3、4、5状态为开或者为 on 则表示成功。如果是 关或者 off 则执行一下:chkconfig --level 345 mysqld on】
+----------------------------------------------------------------------------------------------------------+
tomcat服务
    进入tomcat安装文件bin文件中【如果权限不够就执行这个命令:chmod u+x *.sh】
    启动     执行脚本    ./startup.sh 
    停止    执行脚本    ./shutdown.sh
+----------------------------------------------------------------------------------------------------------+
zabbix服务
启动    systemctl  start zabbix-server
停止    systemctl  stop zabbix-server
    监听服务
    启动    systemctl  start zabbix-agent
    停止    systemctl  stop zabbix-agent
+----------------------------------------------------------------------------------------------------------+
nfs服务(依赖rpcbind)
启动        systemctl start nfs        并    systemctl start rpcbind
重启        systemctl restart nfs        并    systemctl restart rpcbind
停止        systemctl stop nfs        并    systemctl stop rpcbind
设置开机自启    systemctl enable nfs        并    systemctl enable rpcbind
查看状态    systemctl status nfs        并    systemctl status rpcbind
+----------------------------------------------------------------------------------------------------------+
ftp
启动ftp命令
service vsftpd start
systemctl start vsftpd
停止ftp命令
service vsftpd stop
systemctl stop vsftpd
重启ftp命令
service vsftpd restart
systemctl restart vsftpd
设置开机自启
service vsftpd enable
systemctl enable vsftpd
+----------------------------------------------------------------------------------------------------------+
keepalived

systemctl start keepalived   //启动keepalived 
systemctl enable keepalived  //加入开机启动
systemctl restart keepalived  //重新启动keepalived
+----------------------------------------------------------------------------------------------------------+

查看端口是否启动
netstat -lntp

查看进程号
ps -ef|grep  服务名称

查看服务状态
systemctl status 服务名称
或者
service 服务名称 status

 

如有问题请联系博主!!!!!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值