centos中lnmp的安装

写在最前面,在安装之前,最好配置163yum源,或者阿里云的yum源
可以使用163的yum源:wget http://mirrors.163.com/.help/CentOS6-Base-163.repo (将原本的repo文件备份)

yum makecache  #更新yum配置

1、先安装nginx:

cd /usr/local/ && wget http://nginx.org/download/nginx-1.13.4.tar.gz -e http-proxy=95.211.80.227

编译安装过程:
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=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/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=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
make
make install

创建目录及加用户
cd /var/tmp/
mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}
/usr/local/nginx/sbin/nginx
useradd -s /sbin/nologin -M nginx
id nginx

设置启动脚本:

#!/bin/sh
 
# 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

启动、加载、停止nginx

# /usr/local/nginx/sbin/nginx -c 启动nginx,-c后面跟主配置文件使是指定配置文件启动
# /usr/local/nginx/sbin/nginx -s reload reload nginx
# /usr/local/nginx/sbin/nginx -s stop 停止nginx

2、安装php

cd /usr/src && 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  #安装依赖包

编译安装:

tar -zxvf php-5.5.38.tar.gz
cd php-5.5.38
./configure --prefix=/usr/local/php-5.5.38 --with-config-file-path=/usr/local/php-5.5.38/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(这个配置的目的是为后期配置zabbix):

# cp php.ini-production /usr/local/php-5.5.38/etc/php.ini
# vim /usr/local/php-5.5.38/etc/php.ini (修改如下参数)
[PHP]
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Shanghai
#cp /usr/local/php-5.5.38/etc/php-fpm.conf.default /usr/local/php-5.5.38/etc/php-fpm.conf

启动php:

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

到此php已经安装完成

3、安装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

编译安装:

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
scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
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 'tiange1003' (修改mysql的密码)
/usr/local/mysql/bin/mysql_secure_installation

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


image.png

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

你可能感兴趣的:(centos中lnmp的安装)