原创 服务器

第一:安装前准备


1, 说明:

php 和 nginx 使用源码安装,便于升级。mysql使用yum安装。其它的一些支持组件、库使用yum安装


2, 本文的系统环境

[root@localhost ~]# # uname -a
Linux localhost.localdomain 2.6.32-220.17.1.el6.x86_64 #1 SMP Wed May 16 00:01:37 BST 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# # more /etc/redhat-release
CentOS Linux release 6.2 (Final)


3, 本文所需软件

epel-release-6-7.noarch.rpm yum 源
nginx-1.2.0.tar.gz 最新稳定版 官网可下载
php-5.4.3.tar.gz 最新稳定版 官网可下载


4, 下载yum源并安装

[root@localhost ~]# wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
[root@localhost ~]#
[root@localhost ~]# rpm -ivh epel-release-6-7.noarch.rpm
[root@localhost ~]# yum install gcc make pcre-devel pcre


5, 创建相关目录和用户名

[root@localhost ~]# mkdir -pv /opt/wwwroot/bbs.jedy.com
[root@localhost ~]# useradd nginx


 第二:PHP的安装和配置:


1, 安装php所需的库文件

 

[root@localhost ~]# yum install libjpeg-6b libjpeg-devel libpng libpng-devel zlib zlib-devel freetype freetype-devel libXpm libXpm-devel libxml2 libxml2-devel bzip2 bzip2-devel gd


2, 源码安装php

从php-5.3.2开始,php 已自带了php-fpm 补丁,不需再另装
[root@localhost ~]# tar zxvf php-5.4.3.tar.gz -C /usr/local/src
[root@localhost ~]# cd /usr/local/src/php-5.4.3/
[root@localhost php-5.4.3]# ./configure --prefix=/usr/local/php-5.4.3 --with-mysql --enable-fastcgi --enable-fpm --enable-mbstring --with-bz2 --with-freetype-dir --with-png-dir --with-xpm-dir --enable-gd-native-ttf --with-t1lib --without-gdbm --with-gettext --with-iconv --with-jpeg-dir --with-pcre-regex --with-zlib --enable-exif --enable-ftp --enable-magic-quotes --enable-sockets --with-libxml-dir --enable-xml --with-mhash --without-gd
\\ --enable-fastcgi --enable-fpm 这两个参数一定要加上 要不然 php 不能以 fastcgi方式运行,nginx也就不能连接了
\\ --enable-fastcgi 会报错 不用理
[root@localhost php-5.4.3]# make && make install
[root@localhost php-5.4.3]# ln -sv /usr/local/php-5.4.3 /usr/local/php
[root@localhost php-5.4.3]# cp /usr/local/src/php-5.4.3/php.ini-development /usr/local/php/etc/php.ini
[root@localhost php-5.4.3]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.4.3]# cd /usr/local/php/

 

3, 编辑配置文件

[root@localhost php]# vi etc/php.ini
改 short_open_tag = Off 为
short_open_tag = On \\ 改了这个之后才能支持 <? ?> 这种标签,这个和php-5.3 之前的版本的不同之处,改了这个之后我们才能进行下一步的测试。如果不改的话,会造成访问php网页时不出现任何页面,但也不报错
[root@localhost php]# vim /usr/local/php/etc/php-fpm.conf
将user和group 都改成nginx 让php 以 nginx用户运行
并确保有以下这一行
listen = 127.0.0.1:9000
[root@localhost php]# /usr/local/php/sbin/php-fpm -c /usr/local/php/php.ini
[root@localhost php]# echo “/usr/local/php/sbin/php-fpm -c /usr/local/php/php.iniservice” &gt;&gt;/etc/rc.local

 

第三: NGINX的安装和配置:
1, 源码安装nginx

   [root@localhost ~]# tar zxvf /root/nginx-1.2.0.tar.gz -C /usr/local/src
[root@localhost ~]# cd /usr/local/src/nginx-1.2.0/
[root@localhost nginx-1.2.0]# ./configure --prefix=/usr/local/nginx-1.2.0 --conf-path=/etc/nginx/nginx.conf --with-http_stub_status_module --witho
ut-http_rewrite_module --with-pcre
[root@localhost nginx-1.2.0]# make && make install
[root@localhost nginx-1.2.0]# ln -sv /usr/local/nginx-1.2.0 /usr/local/nginx
[root@localhost nginx-1.2.0]# mv /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
[root@localhost nginx-1.2.0]# cp /usr/local/nginx/* /opt/wwwroot/bbs.jedy.com/
[root@localhost nginx-1.2.0]# cd

 


2, 编辑配置文件

[root@localhost ~]# vim /etc/nginx/nginx.conf 修改以下内容
server { \\禁止ip地址访问
server_name _; #default
return 404;
}
server { \\ 允许域名访问
limit_conn addr 10;
listen 80 ;
server_name bbs.jedy.com ;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /opt/wwwroot/bbs.jedy.com; \\ 主目录
index index.html index.htm index.php;
}
\\ 去掉以下内容前的注释 支持php功能
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/wwwroot/bbs.jedy.com$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost ~]#
 nginx.conf 全文如下:
##################################脚本开始#####################################
user nginx;
worker_processes 10;
worker_rlimit_nofile 100000;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_static on;
gzip_comp_level 5;
gzip_min_length 1024;
keepalive_timeout 65;
limit_conn_zone $binary_remote_addr zone=addr:10m;
# Load config files from the /etc/nginx/conf.d directory
include /etc/nginx/conf.d/*.conf;
server {
server_name _; #default
return 404;
}
server {
limit_conn addr 10;
listen 80 ;
server_name bbs.jedy.com ;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /opt/wwwroot/bbs.jedy.com;
index index.html index.htm index.php;
}
error_page 404 /404.html;
location = /404.html {
root /opt/wwwroot/bbs.jedy.com;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /opt/wwwroot/bbs.jedy.com;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/wwwroot/bbs.jedy.com$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
##################################脚本开始#####################################
 

3, 让nginx开机自启动

[root@localhost ~]# vi /etc/init.d/nginx \\ 新建nginx开机启动文件
/etc/init.d/nginx 全文如下:
##################################脚本开始#####################################
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
#nginx="/usr/sbin/nginx"
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -TERM
retval=$?
if [ $retval -eq 0 ]; then
if [ "$CONSOLETYPE" != "serial" ]; then
echo -en "\\033[16G"
fi
while rh_status_q
do
sleep 1
echo -n $"."
done
rm -f $lockfile
fi
echo
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
sleep 1
RETVAL=$?
echo
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status &gt;/dev/null 2&gt;&1
}
# Upgrade the binary with no downtime.
upgrade() {
local pidfile="/var/run/${prog}.pid"
local oldbin_pidfile="${pidfile}.oldbin"
configtest || return $?
echo -n $"Staring new master $prog: "
killproc $nginx -USR2
sleep 1
retval=$?
echo
if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then
echo -n $"Graceful shutdown of old $prog: "
killproc -p ${oldbin_pidfile} -TERM
sleep 1
retval=$?
echo
return 0
else
echo $"Something bad happened, manual intervention required, maybe restart?"
return 1
fi
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
force-reload|upgrade)
rh_status_q || exit 7
upgrade
;;
reload)
rh_status_q || exit 7
$1
;;
status|status_q)
rh_$1
;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;
*)
echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart}"
exit 2
esac
##################################脚本结束#####################################


[root@localhost ~]# chmod +x /etc/init.d/nginx
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig --level 345 nginx on
[root@localhost ~]# service nginx start
[root@localhost ~]# netstat -tlnp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25540/nginx
[root@localhost ~]#


4, 测试

[root@localhost ~]# vi /opt/wwwroot/bbs.jedy.com/test.php 内容如下
/<?
phpinfo()
?>
[root@localhost ~]#
在浏览器中输入 http://bbs.jedy.com \\ 如果出来了欢迎信息,说明nginx安装成功
在浏览器中输入 http://bbs.jedy.com/test.php \\ 如果出来了php的内容,说明成功php集成成功
[root@localhost ~]#
[root@localhost ~]#


 第四:MYSQL的安装和配置:


1, 安装 mysql mysql-server

[root@localhost ~]# yum install mysql mysql-server nginx php php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator


2, 更改mysql默认的数据目录 为 /opt/data

1) 创建目录
[root@localhost ~]# mkdir /opt/data
2) 把MySQL服务进程停掉
[root@localhost ~]# service mysqld stop
3) 把/var/lib/mysql整个目录移到/home/data
[root@localhost ~]# mv /var/lib/mysql/* /opt/data/
这样就把MySQL的数据文档移动到了/home/data/下。
4) 找到my.cnf配置文档
假如/etc/目录下没有my.cnf配置文档,请到/usr/share/mysql/下找到*.cnf文档,拷贝其中一个到/etc/并改名为my.cnf)中。
命令如下:
[root@localhost ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
5) 编辑MySQL的配置文档/etc/my.cnf
为确保MySQL能够正常工作,需要指明mysql.sock文档的产生位置。修改socket=/var/lib/mysql/mysql.sock一行中等号右边的值为:/home/mysql/mysql.sock 。操作如下: .
[root@localhost ~]# vi my.cnf (用vi工具编辑my.cnf文档,找到下列数据修改之,有的版本上是有的,就不用改了) .
# The MySQL server
[mysqld]
port = 3306
#socket = /var/lib/mysql/mysql.sock(原内容,为了更稳妥用“#”注释此行)
socket = /opt/data/mysql/mysql.sock (加上此行) .
my.cnf 全文如下:
##################################脚本开始#####################################
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
#socket = /opt/data/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
#socket = /opt/data/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_format=mixed
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
##################################脚本结束#####################################
6) 修改MySQL启动脚本/etc/init.d/mysqld
最后,需要修改MySQL启动脚本/etc/init.d/mysqld,把其中datadir=/var/lib/mysql一行中,等号右边的路径改成您现在的实际存放路径:home/data/mysql。
[root@localhost ~]# vi /etc/init.d/mysqld
#datadir=/var/lib/mysql (注释此行) 。
datadir=/opt/data/mysql (加上此行) ..
mysqld 全文如下:
##################################脚本开始#####################################
#!/bin/sh
#
# mysqld This shell script takes care of starting and stopping
# the MySQL subsystem (mysqld).
#
# chkconfig: - 64 36
# description: MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
exec="/usr/bin/mysqld_safe"
prog="mysqld"
# Set timeouts here so they can be overridden from /etc/sysconfig/mysqld
STARTTIMEOUT=120
STOPTIMEOUT=60
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/$prog
# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
if [ -z "$result" ]; then
# not found, use default
result="$3"
fi
}
#get_mysql_option mysqld datadir "/var/lib/mysql"
get_mysql_option mysqld datadir "/opt/data/mysql"
datadir="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
errlogfile="$result"
get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
mypidfile="$result"
start(){
[ -x $exec ] || exit 5
# check to see if it's already running
RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2&gt;&1`
if [ $? = 0 ]; then
# already running, do nothing
action $"Starting $prog: " /bin/true
ret=0
elif echo "$RESPONSE" | grep -q "Access denied for user"
then
# already running, do nothing
action $"Starting $prog: " /bin/true
ret=0
else
# prepare for start
touch "$errlogfile"
chown mysql:mysql "$errlogfile"
chmod 0640 "$errlogfile"
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
if [ ! -d "$datadir/mysql" ] ; then
# First, make sure $datadir is there with correct permissions
if [ ! -e "$datadir" -a ! -h "$datadir" ]
then
mkdir -p "$datadir" || exit 1
fi
chown mysql:mysql "$datadir"
chmod 0755 "$datadir"
[ -x /sbin/restorecon ] && /sbin/restorecon "$datadir"
# Now create the database
action $"Initializing MySQL database: " /usr/bin/mysql_install_db --datadir="$datadir" --user=mysql
ret=$?
chown -R mysql:mysql "$datadir"
if [ $ret -ne 0 ] ; then
return $ret
fi
fi
chown mysql:mysql "$datadir"
chmod 0755 "$datadir"
# Pass all the options determined above, to ensure consistent behavior.
# In many cases mysqld_safe would arrive at the same conclusions anyway
# but we need to be sure. (An exception is that we don't force the
# log-error setting, since this script doesn't really depend on that,
# and some users might prefer to configure logging to syslog.)
# Note: set --basedir to prevent probes that might trigger SELinux
# alarms, per bug #547485
$exec --datadir="$datadir" --socket="$socketfile" \
--pid-file="$mypidfile" \
--basedir=/usr --user=mysql &gt;/dev/null 2&gt;&1 &
safe_pid=$!
# Spin for a maximum of N seconds waiting for the server to come up;
# exit the loop immediately if mysqld_safe process disappears.
# Rather than assuming we know a valid username, accept an "access
# denied" response as meaning the server is functioning.
ret=0
TIMEOUT="$STARTTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2&gt;&1` && break
echo "$RESPONSE" | grep -q "Access denied for user" && break
if ! /bin/kill -0 $safe_pid 2&gt;/dev/null; then
echo "MySQL Daemon failed to start."
ret=1
break
fi
sleep 1
let TIMEOUT=${TIMEOUT}-1
done
if [ $TIMEOUT -eq 0 ]; then
echo "Timeout error occurred trying to start MySQL Daemon."
ret=1
fi
if [ $ret -eq 0 ]; then
action $"Starting $prog: " /bin/true
touch $lockfile
else
action $"Starting $prog: " /bin/false
fi
fi
return $ret
}
stop(){
if [ ! -f "$mypidfile" ]; then
# not running; per LSB standards this is "ok"
action $"Stopping $prog: " /bin/true
return 0
fi
MYSQLPID=`cat "$mypidfile"`
if [ -n "$MYSQLPID" ]; then
/bin/kill "$MYSQLPID" &gt;/dev/null 2&gt;&1
ret=$?
if [ $ret -eq 0 ]; then
TIMEOUT="$STOPTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
/bin/kill -0 "$MYSQLPID" &gt;/dev/null 2&gt;&1 || break
sleep 1
let TIMEOUT=${TIMEOUT}-1
done
if [ $TIMEOUT -eq 0 ]; then
echo "Timeout error occurred trying to stop MySQL Daemon."
ret=1
action $"Stopping $prog: " /bin/false
else
rm -f $lockfile
rm -f "$socketfile"
action $"Stopping $prog: " /bin/true
fi
else
action $"Stopping $prog: " /bin/false
fi
else
# failed to read pidfile, probably insufficient permissions
action $"Stopping $prog: " /bin/false
ret=4
fi
return $ret
}
restart(){
stop
start
}
condrestart(){
[ -e $lockfile ] && restart || :
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p "$mypidfile" $prog
;;
restart)
restart
;;
condrestart|try-restart)
condrestart
;;
reload)
exit 3
;;
force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
##################################脚本结束#####################################
7) 重新启动MySQL服务
[root@localhost ~]# service mysqld start
[root@localhost ~]# netstat -tlnp | grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 20981/mysqld
[root@localhost ~]#

##################################完装结束#####################################