一、准备编译环境
关闭SELINUX
修改配置文件,重启服务后永久生效
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
命令行设置立即生效
setenforce 0
二、安装nginx1.10
1.安装编译工具和依赖包
yum -y install gcc gcc-c++ autoconf automake make cmake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel perl perl-devel perl-maExtUtils-Embed
2.新建nginx用户和用户组
sudo groupadd -r nginx
sudo useradd -s /sbin/nologin -g nginx -r nginx
3.编译安装
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar -zxvf nginx-1.10.2.tar.gz
编译参数
./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_perl_module \
--with-mail \
--with-mail_ssl_module
安装
make
make install
添加SysV启动脚本。
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/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 -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
赋予脚本执行权限
chmod +x /etc/init.d/nginx
添加至服务管理列表,设置开机自启。
chkconfig --add nginx
chkconfig nginx on
启动服务
service nginx start
三、安装mysql5.7
注:cmake安装mysql5.7,机器要好一点,一开始我的机器是1核1G内存,跑得卡死,后来换成2核4G内存没问题 注:在CentOS 7.0版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
安装编译工具和依赖包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
添加mysql用户和用户组
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
id mysql
下载mysql
cd /root/src
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget http://dev.mysql.com/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
tar zxvf boost_1_59_0.tar.gz
tar zxvf mysql-5.7.11.tar.gz
cd mysql-5.7.11
cmake 参数
cmake 参数 | 含义 |
---|---|
-DCMAKE_INSTALL_PREFIX=dir_name | 设置mysql安装目录 |
-DMYSQL_UNIX_ADDR=file_name | 设置监听套接字路径,这必须是一个绝对路径名。默认为/tmp/mysql.sock |
-DDEFAULT_CHARSET=charset_name | 设置服务器的字符集。 |
-DDEFAULT_COLLATION=collation_name | 设置服务器的排序规则。 |
-DWITH_INNOBASE_STORAGE_ENGINE = 1 | 存储引擎选项:MyISAM,MERGE,MEMORY,和CSV引擎是默认编译到服务器中,并不需要明确地安装。静态编译一个存储引擎到服务器,使用-DWITH_engine_STORAGE_ENGINE= 1 可用的存储引擎值有:ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE (InnoDB), PARTITION (partitioning support), 和PERFSCHEMA (Performance Schema) |
-DMYSQL_DATADIR=dir_name | 设置mysql数据库文件目录 |
-DMYSQL_TCP_PORT=port_num | 设置mysql服务器监听端口,默认为3306 |
-DENABLE_DOWNLOADS=bool | 是否要下载可选的文件。例如,启用此选项(设置为1),cmake将下载谷歌所使用的测试套件运行单元测试。 |
-DWITH_BOOST | BOOST包的位置 |
cmake执行
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=/tmp/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 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/root/src/boost_1_59_0
安装
make
make install
修改安装目录的属组为mysql
chown -R mysql:mysql /usr/local/mysql/
拷贝配置文件和启动脚本
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
设置开机自动启动
chkconfig mysqld on
chkconfig --add mysqld
修改配置文件中的安装路径及数据目录存放路径
echo -e "basedir = /usr/local/mysql\ndatadir = /usr/local/mysql/data\n" >> /etc/my.cnf
设置PATH环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
初始化数据
注:mysql7里mysql_install_db 已经不再推荐使用了,建议改成 mysqld –initialize 完成实例初始化。需要先确保 datadir 目标目录下是空的,避免误操作破坏已有数据
mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize --initialize-insecure
启动服务
service mysqld start
设置mysql密码
mysql -uroot -p
use mysql
set password = password('1234abcd');
四、安装php7.0
1、安装依赖包,我用的centos,偷下懒,直接yum安装
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libmcrypt libmcrypt-devel mhash mhash-devel
2、下载php7包
wget http://cn2.php.net/distributions/php-7.0.17.tar.gz
3、解压,进入PHP目录
tar zxvf php-7.0.17.tar.gz
cd php-7.0.17
4、配置
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-config-file-scan-dir=/usr/local/php/etc/conf.d \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--with-gd \
--with-iconv \
--with-zlib \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-fpm \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-opcache \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-mcrypt \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir
5、安装
make
make install
6、添加php和php-fpm配置文件
进入源码安装包
cp /root/src/php-7.0.17/php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php/var/run/php-fpm.pid@' php-fpm.conf
7、设置PATH环境变量
echo "export PATH=$PATH:/usr/local/php/bin" > /etc/profile.d/php.sh
source /etc/profile.d/php.sh
8、添加php-fpm启动脚本
cp /root/src/php-7.0.17/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
9、添加php-fpm至服务列表并设置开机自启
chkconfig --add php-fpm
chkconfig --list php-fpm
chkconfig php-fpm on
10、启动服务
service php-fpm start
本帖已被设为精华帖!