標籤:
一、開機自動啟動apache方法
#sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist //開機啟動#sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist //關閉啟動
二、開機自啟動memcached方法
centos下設定開機自啟動某個服務,只需要把啟動服務對於的命令添加到/etc/rc.local檔案中即可,例如開機自動啟動memcached,在檔案中加入如下資訊即可:
/usr/local/memcached/bin/memcached -d -m 64 -l 127.0.0.1 -p 11211 -u root
mac os lion 中似乎沒有這個檔案,如果要做到開機自啟動,則需要通過plist指令碼來完成,關於plist指令碼的更多資訊可以參考:mac os 定期任務配置。
以自啟動memcached為例,首先寫一個啟動memcached的shell指令碼,命名為start-memcached,存放在/usr/bin下,當然檔案名稱、存放路徑可以隨意按自己喜歡方式來命名,shell指令碼的內容為:
#!/bin/bash/usr/bin/memcached -d -m 16 -l 127.0.0.1 -p 11211 -u phpdragon
注意該檔案要有執行許可權,可以使用chmod命令修改,memcached命令根據本機實際路徑來書寫。
在plist指令碼中來執行上述shell指令碼,plist指令碼命名為:com.phpdragon.memcached.plist,存放在/Library/LaunchDaemons下,指令碼內容如下:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>Label</key> <string>com.phpdragon.memcached.plist</string> <key>ProgramArguments</key> <array> <string>/usr/bin/start-memcached</string> </array> <key>KeepAlive</key> <false/> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/tmp/memcached.err</string> <key>StandardOutPath</key> <string>/tmp/memcached.out</string></dict></plist>
通過上述配置,每次開機後都會自動啟動memcached服務了。
三、開機自動啟動mysql方法(dmg方式安裝)
1.添加檔案
代碼如下:
touch /Library/LaunchDaemons/com.sun.mysqld.plist
2.新增內容
代碼如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>com.sun.mysqld</string> <key>ProgramArguments</key> <array> <string>/usr/local/mysql/bin/mysqld_safe</string> <string>--user=root</string> </array> </dict> </plist>
3.添加後重啟
代碼如下:
sudo launchctl load -w /Library/LaunchDaemons/com.sun.mysqld.plist
mac開機啟動apache、memcached與mysql