環(huán)境介紹
查看服務(wù)器版本:
cat /etc/redhat-release
[root@localhost nginx-1.14.0]# yum install patch make gcc gcc-c++ automake cmake autoconf kernel-devel libtool libtool-libs libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel glibc glibc-devel glibc-headers glibc-static glibc-utils openssl openssl-devel crypto-utils gettext gettext-devel ncurses ncurses-devel gmp-devel aspell aspell-devel perl-IO-Compress-Base perl-HTML-Parser perl-ExtUtils-MakeMaker perl-libwww-perl perl-Pod-Escapes perl-Module-Pluggable perl-libs perl-ExtUtils-FindFunctions perl-Compress-Raw-Zlib perl-IO-Compress-Zlib perl-Test-Harness perl-ExtUtils-ParseXS perl-Newt perl-HTML-Tagset perl-URI perl-Convert-ASN1 perl-ExtUtils-Embed perl-Pod-Simple perl-ExtUtils-DynaGlue perl-Compress-Zlib perl-devel perl-DBI gd gd-devel curl libcurl libcurl-devel readline readline-devel
nginx
1.安裝依賴包
yum -y install zlib-devel pcre-devel openssl-devel
# 下載nginx
[root@localhost /]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
[root@localhost src]# tar -zxvf nginx-1.14.0.tar.gz
2.編譯nginx
cd nginx-1.0.13
./configure --prefix=/usr/local/nginx\ # 指定安裝目錄為/usr/local/nginx
--with-openssl=/usr/include/openssl\ # 啟用ssl
--with-pcre\ # 啟用正規(guī)表達式
--with-http_stub_status_module # 安裝可以查看nginx狀態(tài)的程序
make && make install
3.啟動nginx
/usr/local/nginx/sbin/nginx
4.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
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
}
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
mysql
創(chuàng)建mysql用戶和組
[root@localhost src]# groupadd mysql
[root@localhost src]# useradd -g mysql -s /sbin/nologin mysql
下載mariadb
1,安裝特定的開發(fā)包
[root@localhost src]# yum -y install readline-devel zlib-devel openssl-devel
2.編譯及安裝
[root@localhost src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
[root@localhost src]# tar zxvf mysql-5.6.17.tar.gz
[root@localhost src]# cd mysql-5.6.17
[root@localhost src]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
[root@localhost src]# make && make install
3.修改/usr/local/mysql權(quán)限
[root@localhost local]# chmod +w /usr/local/mysql
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql
在啟動MySQL服務(wù)時观挎,會按照一定次序搜索my.cnf,先在/etc目錄下找,找不到則會搜索”$basedir/my.cnf” 就是安裝目錄下 /usr/local/mysql/my.cnf彩届,這是新版MySQL的配置文件的默認位置! 注意:在CentOS 6.x版操作系統(tǒng)的最小安裝完成后裹刮,在/etc目錄下會存在一個my.cnf奢讨,需要將此文件更名為其他的名字。 如:/etc/my.cnf.bak动雹,否則槽卫,該文件會干擾源碼安裝的MySQL的正確配置,造成無法啟動胰蝠。 由于我們已經(jīng)卸載了最小安裝完成后的mysq庫所以歼培,就沒必要操作了
- mysql初始化
[root@localhost mysql-5.6.17]# cd support-files/
# 執(zhí)行初始化腳本
[root@localhost mysql-5.6.17]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
#拷貝腳本
[root@localhost mysql-5.6.17]# cp support-files/mysql.server /etc/init.d/mysqld
#賦予權(quán)限
[root@localhost mysql-5.6.17]# chmod +x /etc/init.d/mysqld
- 設(shè)置開機啟動
[root@localhost mysql-5.6.17]# chkconfig mysqld on
啟動MySQL
[root@localhost mysql-5.6.17]# service mysqld start
或者
[root@localhost mysql-5.6.17]# /etc/init.d/mysql start
6.設(shè)置mysql PATH
修改/etc/profile文件
[root@localhost mysql-5.6.17]# vi /etc/profile
在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
[root@localhost mysql-5.6.17]# source /etc/profile
設(shè)置密碼
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
- 遠程登錄
# 查看用戶
select user,host from mysql.user;
+------+-----------------------+
| user | host |
+------+-----------------------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+------+-----------------------+
# 刪除不必要的用戶
drop user ""@localhost;
drop user ""@localhost.localdomain;
drop user root@localhost.localdomain;
drop user root@'::1';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '你的密碼' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '你的密碼' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'c65mini.localdomain' IDENTIFIED BY '你的密碼' WITH GRANT OPTION;
php
創(chuàng)建www用戶組和用戶
[root@localhost src]# groupadd www
[root@localhost src]# useradd -g www -s /sbin/nologin www
1.安裝PHP前首先要安裝幾個源碼包依賴:libmcrypt mhash mcrypt
wget https://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2
tar -jxvf libmcrypt-2.5.8.tar.bz2 # 這個包是bz2的 使用-j參數(shù)解壓
cd libmcrypt-2.5.8
./configure
make
make install
####################################################
wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2/download
tar -jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make
make install
# 這兩個包安裝完成后要把動態(tài)鏈接庫做一個軟連接到/usr/lib,以為接下來的mcrypt依賴于這兩個包
ln -s /usr/local/lib/libmcrypt* /usr/lib
ln -s /usr/local/lib/libmhash.* /usr/lib/
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
###########################################################
wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
出現(xiàn)onfigure: error: *** libmcrypt was not found
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH
make
make install
2 下載php
wget http://cn2.php.net/distributions/php-7.2.5.tar.gz
tar -zxvf php-7.2.5.tar.gz
cd php-7.2.5
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# 啟動php-fpm
cp /usr/local/php/sbin/php-fpm /etc/init.d/php-fpm
/etc/init.d/php-fpm retart
到這里lnmp環(huán)境已經(jīng)完成了