centos安装nginx、php-fpm、myssql(为zabbix做准备)

centos6.9自己的linux服务器是买的vps,因此yum都是准备好的
还是检查下:

yum repolist
yum makecache 更新yum配置
yum update
yum -y install pcre* 为了支持rewrite
yum -y install gcc-c++
yum -y install java* #因为这个这个环境是为zabbix_server做的准备,因此需要配置jdk环境,自己使用的centos6.9环境,jdk装上去是1.8环境的,装好jdk之后使用java --version检查

 

个人安装开源软件的习惯是安装在/usr/lcoal这个目录下,所以下面的开源软件都是安装在此目录下
一、nginx源码包下载及安装(个人建议直接在官网下载好,然后上传到自己的服务器上进行编译安装)     

wget http://nginx.org/download/nginx-1.13.4.tar.gz -e http-proxy=95.211.80.227 
tar -zxvf nginx-1.13.4.tar.gz
cd nginx-1.13.4
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/logs/error.log --http-log-path=/usr/local/nginx/logs/access.log --pid-path=/usr/local/nginx/nginx.pid --lock-path=/usr/local/nginx/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-pcre
make
make install
useradd -s /sbin/nologin -M nginx
id nginx
/usr/local/nginx/sbin/nginx

vim /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/local/nginx/sbin/nginx" 
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/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 -QUIT 
retval=$? 
echo 
[ $retval -eq 0 ] && rm -f $lockfile 
return $retval 
killall -9 nginx 
}

restart() { 
configtest || return $? 
stop 
sleep 1 
start 
}

reload() { 
configtest || return $? 
echo -n $"Reloading $prog: " 
killproc $nginx -HUP 
RETVAL=$? 
echo 
}

force_reload() { 
restart 
}

configtest() { 
$nginx -t -c $NGINX_CONF_FILE 
}

rh_status() { 
status $prog 
}

rh_status_q() { 
rh_status >/dev/null 2>&1 
}

case "$1" in 
start) 
rh_status_q && exit 0 
$1 
;; 
stop) 
rh_status_q || exit 0 
$1 
;; 
restart|configtest) 
$1 
;; 
reload) 
rh_status_q || exit 7 
$1 
;; 
force-reload) 
force_reload 
;; 
status) 
rh_status 
;; 
condrestart|try-restart) 
rh_status_q || exit 0 
;; 
*) 
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
exit 2 
esac 
service nginx start
启动nginx
/usr/local/nginx/sbin/nginx 启动nginx
/usr/local/nginx/sbin/nginx -s reload reload nginx
/usr/local/nginx/sbin/nginx -s stop 停止nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

 

二、php下载及安装:

wget http://am1.php.net/distributions/php-5.5.38.tar.gz
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y 
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath --enable-mbstring --enable-sockets
make
make install
配置php
cp php.ini-production /usr/local/php/etc/php.ini

vim /usr/local/php/etc/php.ini (配置zabbix的时候需要修改如下参数)

[PHP]
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Shanghai    
always_populate_raw_post_data = -1 #这行打开
 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #默认是没有配置文件的,要不启动的时候会报错
启动php-fpm
/usr/local/php/sbin/php-fpm

重启php

killall php-fpm 
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini (指定文件路径启动,防止启动的文件不对)

配置nginx测试站点

mkdir /data/logs/nginx/ # 用于存放nginx日志.请看2.3的配置文件
mkdir -p /data/site/test.ttlsa.com/ # 站点根目录
vim /data/site/test.ttlsa.com/info.php
<?php
phpinfo();
?>

mysql的下载及安装:

三、mysql的下载及安装:

wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz 
tar -xzvf cmake-2.8.10.2.tar.gz 
cd cmake-2.8.10.2 
./bootstrap 
make
make install 
cd ~
groupadd mysql
useradd -r -g mysql mysql
mkdir -p /usr/local/mysql
mkdir -p /data/mysqldb
yum -y install ncurses-devel
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz 
tar -zxv -f mysql-5.6.16.tar.gz
cd mysql-5.6.16
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
rm CMakeCache.txt
make
make install
cd /usr/local/mysql 
chown -R mysql:mysql /usr/local/mysql
cd /data/mysqldb
chown -R mysql:mysql /data/mysqldb
cd /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &

如果初始化数据的时候出现下面错误的时候:

解决方式:

yum install 'perl(Data::Dumper)' -y #因为yum的prel包中没有Dumper.pm文件。这时候只要执行以下命令就可以手动下载Dumper.pm文件

然后继续初始化:

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld

vim /etc/profile 

PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
source /etc/profile

netstat -tulnp | grep 3306 
mysql -u root -p 
mysqladmin -u root password 'xxxx'   #修改mysql的密码
/usr/local/mysql/bin/mysql_secure_installation

mysql启动的时候出现错误:
Starting MySQL... ERROR! The server quit without updating PID file (/data/mysqldb/tiantianml.pid).

解决方式:
mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data
在配置文件中添加这一行之后,然后启动mysql正常

下面列出一些启动mysql启动时常见的错误:

service mysqld start
如果在启动mysql的过程中出现错误,可以利用错误日志查看具体的错误是什么。
1、在/etc/my.cnf这目录里面添加log_error = /var/log/mysql/error.log
2、创建/var/log/mysql这个目录
3、然后启动mysql,查看错误日志中报出是什么错误。(本人出现的错误如下)

4、切换到/usr/loca/mysql的这个目录下,然后./scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf
5、再次重启的时候,就可以正常启动。

chkconfig --level 35 mysqld on
netstat -tulnp | grep 3306 
mysql -u root -p 

密码为空,如果能登录上,说明安装成功

个人原创,有错误的地方敬请见谅,可以留言进行沟通

posted @ 2017-11-19 21:27  小王同学-TT  阅读(116)  评论(0)    收藏  举报