CentOS 7 MySQL 5.7.10 Mongo 3.2.1 Nginx 1.8.0 php 5.5.31 Redis 3.0.6
====================================== CentOS configsystemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall開機啟動yum install -y iptables-servicesvi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 9312 -j ACCEPT:wq! #保存退出systemctl restart iptables.service systemctl enable iptables.service vi /etc/selinux/config #關(guān)閉SELINUX#SELINUX=enforcing #注釋掉#SELINUXTYPE=targeted #注釋掉SELINUX=disabled #增加:wq! #保存退出setenforce 0 #使配置立即生效# 修改時間,如果安裝時改了時區(qū)則略過datetimedatectltimedatectl set-timezone Asia/Shanghaidatehwclock --showhwclock --set --date '2016-01-27 00:24:10' hwclock --hctosysclock -wshutdown -r now# 注意,以下每步wget的安裝包都存放到/usr/local/src;因為部分用到的安裝包需要翻出去下載,不能翻的可在網(wǎng)盤地址【http://pan.baidu.com/s/1boBJxd9】中下載。============================================= cmakeyum install -y aPR* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-develyum -y install imake mysql-develyum -y install net-toolsyum -y install wgetcd /usr/local/srcwget http://www.cmake.org/files/v2.8/cmake-2.8.11.2.tar.gztar -zxvf cmake-2.8.11.2.tar.gzcd cmake-2.8.11.2./configuremakemake install============================================= mysql cd /usr/local/srcwget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.10.tar.gzgroupadd mysql #添加mysql組useradd -g mysql mysql -s /bin/false #創(chuàng)建用戶mysql并加入到mysql組,不允許mysql用戶直接登錄系統(tǒng)mkdir -p /home/mysql/data #創(chuàng)建MySQL數(shù)據(jù)庫存放目錄chown -R mysql:mysql /home/mysql/datamkdir -p /usr/local/mysqltar -zxvf mysql-5.7.10.tar.gzcd mysql-5.7.10# 配置,解決CMake Error,如果已經(jīng)下載boost則執(zhí)行以下操作,否則將以下cmake的-DDOWNLOAD_BOOST=0變?yōu)?mkdir /usr/local/boostcp /usr/local/src/boost_1_59_0.tar.gz /usr/local/boost/boost_1_59_0.tar.gzcd /usr/local/boosttar -zxvf boost_1_59_0.tar.gzcd /usr/local/src/mysql-5.7.10cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=0 -DWITH_BOOST=/usr/local/boostmakemake installcd /usr/local/mysql # 執(zhí)行以下初始化命令前保證 /home/mysql/data 下無任何文件和目錄!bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/home/mysql/datamkdir -p /home/mysql/data/undolog # undo存放空間,必須安裝時設(shè)置innodb_undo_directory、innodb_undo_tablespaces,非必要用途chown -R mysql:mysql /home/mysql/data/undolog# 建立配置文件,如果需要主從復(fù)制或者集群,參見另篇博文的mysql部署cp support-files/my-default.cnf /etc/my.cnfvi /etc/my.cnf[mysqld]character_set_server=utf8init_connect='SET NAMES utf8'net_buffer_length=4Mmax_allowed_packet=300Mexpire_logs_days=15#undo(ibdata) para set oninnodb_undo_log_truncate=ONinnodb_undo_directory=/home/mysql/data/undologinnodb_undo_tablespaces=4innodb_max_undo_log_size=10G[client]#default-character-set=utf8 #此項最好不添加:wq! #保存退出cp support-files/mysql.server /etc/rc.d/init.d/mysqld #復(fù)制啟動腳本到init.d下,而且/etc/init.d與/etc/rc.d/init.d已經(jīng)建立鏈接chmod 755 /etc/init.d/mysqld chkconfig mysqld on vi /etc/rc.d/init.d/mysqldbasedir=/usr/local/mysql #MySQL程序安裝路徑datadir=/home/mysql/data #MySQl數(shù)據(jù)庫存放目錄:wq! #保存退出systemctl start mysqld.service #啟動 service mysqld startvi /etc/profile #把mysql服務(wù)加入系統(tǒng)環(huán)境變量:在最后添加下面這一行export PATH=$PATH:/usr/local/mysql/bin:wq! #保存退出source /etc/profile# 下面這兩行把myslq的庫文件鏈接到系統(tǒng)默認的位置,這樣你在編譯類似PHP等軟件時可以不用指定mysql的庫文件地址。ln -s /usr/local/mysql/lib /usr/lib/mysqlln -s /usr/local/mysql/include/mysql /usr/include/mysqlmkdir /var/lib/mysql #創(chuàng)建目錄ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加軟鏈接mysql_secure_installation #(!坑人,不建議執(zhí)行!)設(shè)置Mysql密碼,根據(jù)提示按Y 回車輸入2次密碼,不要使用默認生成密碼的方式,記不住alter user 'root'@'localhost' identified by 'sa'; #或者按這個改默認密碼GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'sa' WITH GRANT OPTION; #允許root遠程登錄,改密碼為'sa'flush privileges;# 如果安裝后修改data存放,則需——service mysqld stopmkdir /home/mysql/data #mysql用戶的目錄中建立數(shù)據(jù)目錄datacd /data/mysql #原數(shù)據(jù)目錄cp -R * /home/mysql/datachown -R mysql:mysql /home/mysql/datavi /etc/rc.d/init.d/mysqlddatadir=/home/mysql/data:wq!service mysqld start============================================= nginxcd /usr/local/srcwget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gzwget http://www.openssl.org/source/openssl-1.0.1h.tar.gzwget http://zlib.net/zlib-1.2.8.tar.gzwget https://github.com/pagespeed/ngx_pagespeed/archive/v1.8.31.4-beta.tar.gzwget https://dl.google.com/dl/page-speed/psol/1.8.31.4.tar.gzwget http://nginx.org/download/nginx-1.8.0.tar.gztar -zxvf pcre-8.35.tar.gzmkdir /usr/local/pcrecd pcre-8.35./configure --prefix=/usr/local/pcremakemake installtar -zxvf openssl-1.0.1h.tar.gzmkdir /usr/local/opensslcd openssl-1.0.1h./config --prefix=/usr/local/opensslmakemake installvi /etc/profileexport PATH=$PATH:/usr/local/openssl/bin:wq!source /etc/profiletar -zxvf zlib-1.2.8.tar.gzmkdir /usr/local/zlibcd zlib-1.2.8./configure --prefix=/usr/local/zlibmakemake installtar -zxvf v1.8.31.4-beta.tar.gzcp 1.8.31.4.tar.gz ./ngx_pagespeed-1.8.31.4-betacd ngx_pagespeed-1.8.31.4-betatar -xzvf 1.8.31.4.tar.gzgroupadd wwwuseradd -g www www -s /bin/falsetar -zxvf nginx-1.8.0.tar.gzmkdir /usr/local/nginxchown -R www:www /usr/local/nginxcd nginx-1.8.0./configure --prefix=/usr/local/nginx --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.35 --add-module=/usr/local/src/ngx_pagespeed-1.8.31.4-beta#注意:--with-openssl --with-zlib --with-pcre --add-module 指向的是源碼包解壓的路徑,而不是安裝的路徑,否則會報錯makemake install/usr/local/nginx/sbin/nginxvi /etc/rc.d/init.d/nginx ###################### 啟動腳本,添加以下內(nèi)容#!/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: /usr/local/nginx/conf/nginx.conf# pidfile: /usr/local/nginx/logs/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 0nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs() {# make required directoriesuser=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=/([^ ]*/).*//1/g' -`if [ -z "`grep $user /etc/passwd`" ]; thenuseradd -M -s /bin/nologin $userfioptions=`$nginx -V 2>&1 | grep 'configure arguments:'`for opt in $options; doif [ `echo $opt | grep '.*-temp-path'` ]; thenvalue=`echo $opt | cut -d "=" -f 2`if [ ! -d "$value" ]; then# echo "creating" $valuemkdir -p $value && chown -R $user $valuefifidone}start() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6make_dirsecho -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {#configtest || return $?stopsleep 1start}reload() {#configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUPRETVAL=$?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" instart)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 2esac:wq! chmod 755 /etc/rc.d/init.d/nginx chkconfig nginx on #systemctl enable nginx , chkconfig --add nginxvi /usr/local/nginx/conf/nginx.confworker_processes 1 #根據(jù)cpu內(nèi)核數(shù)(more /proc/cpuinfo|grep "model name")調(diào)整worker進程數(shù),1個內(nèi)核對應(yīng)1個worker進程gzip on; #去掉注釋 client_max_body_size 50M; #增加該項解除上傳限制過小的問題fastcgi_ignore_client_abort on; #放http段內(nèi),解決php fsockopen函數(shù)無效問題client_header_buffer_size 16k; #放http段內(nèi),解決php fsockopen函數(shù)無效問題large_client_header_buffers 4 64k; #放http段內(nèi),解決php fsockopen函數(shù)無效問題:wq! /etc/rc.d/init.d/nginx restart========================================== php cd /usr/local/srcwget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gzwget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gzwget ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gzwget https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gzwget https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2wget http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gzwget ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.12.tar.gzwget http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.3.tar.gzwget http://www.ijg.org/files/jpegsrc.v9a.tar.gzwget http://cn2.php.net/distributions/php-5.5.31.tar.gzwget http://pecl.php.net/get/redis-2.2.4.tgzwget http://pecl.php.net/get/mongo-1.6.12.tgzwget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz #memcached服務(wù)依賴wget http://www.memcached.org/files/memcached-1.4.25.tar.gzwget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz #memcached擴展依賴wget http://pecl.php.net/get/memcached-2.2.0.tgztar -zxvf yasm-1.2.0.tar.gzcd yasm-1.2.0./configuremakemake installtar -zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configuremakemake installtar xvf libvpx-v1.3.0.tar.bz2mkdir /usr/local/libvpxcd libvpx-v1.3.0./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9makemake installtar -zxvf tiff-4.0.3.tar.gzmkdir /usr/local/tiffcd tiff-4.0.3./configure --prefix=/usr/local/tiff --enable-sharedmakemake installtar -zxvf libpng-1.6.12.tar.gzmkdir /usr/local/libpngcd libpng-1.6.12./configure --prefix=/usr/local/libpng --enable-sharedmakemake installtar -zxvf freetype-2.5.3.tar.gzmkdir /usr/local/freetypecd freetype-2.5.3./configure --prefix=/usr/local/freetype --enable-sharedmakemake installtar -zxvf jpegsrc.v9a.tar.gzmkdir /usr/local/jpegcd jpeg-9a./configure --prefix=/usr/local/jpeg --enable-sharedmakemake installtar -zxvf libgd-2.1.0.tar.gzmkdir /usr/local/libgdcd libgd-2.1.0./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpxmakemake install tar -zxvf t1lib-5.1.2.tar.gzmkdir /usr/local/t1libcd t1lib-5.1.2./configure --prefix=/usr/local/t1lib --enable-sharedmake without_doc #如果想用make則需先裝latex:yum -y install tetex-latexmake install/cp -frp /usr/lib64/libltdl.so* /usr/lib//cp -frp /usr/lib64/libXpm.so* /usr/lib/tar -zxvf php-5.5.31.tar.gzcd php-5.5.31export LD_LIBRARY_PATH=/usr/local/libgd/lib./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctypemake #如果出undefined reference to libiconv_open ,使用make ZEND_EXTRA_LIBS='-liconv'make install cp php.ini-production /usr/local/php/etc/php.ini #復(fù)制php配置文件到安裝目錄rm -rf /etc/php.ini #刪除系統(tǒng)自帶配置文件ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加軟鏈接到 /etc目錄cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷貝模板文件為php-fpm配置文件ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #添加軟連接到 /etc目錄vi /usr/local/php/etc/php-fpm.confpid = run/php-fpm.pid #取消前面的分號user = www #設(shè)置php-fpm運行賬號為wwwgroup = www #設(shè)置php-fpm運行組為www:wq! #保存退出cp /usr/local/src/php-5.5.31/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷貝php-fpm到啟動目錄chmod +x /etc/rc.d/init.d/php-fpmchkconfig php-fpm onvi /usr/local/php/etc/php.ini#編輯配置文件,列出PHP可以禁用的函數(shù),如果某些程序需要用到這個函數(shù),可以刪除,取消禁用。找到:disable_functions =修改為:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname找到:;date.timezone = 修改為:date.timezone = PRC #設(shè)置時區(qū)找到:expose_php = On 修改為:expose_php = Off #禁止顯示php版本的信息找到:short_open_tag = Off 修改為:short_open_tag = On #支持php短標(biāo)簽找到:opcache.enable=0 修改為:opcache.enable=1 #php支持opcode緩存找到:opcache.enable_cli=1 修改為:opcache.enable_cli=0 #php支持opcode緩存在[opcache]添加:zend_extension=opcache.so #開啟opcode緩存功能:wq! vi /usr/local/nginx/conf/nginx.conf #配置nginx支持php, 做如下修改user www www; #首行user去掉注釋,修改Nginx運行組為www www;必須與/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否則php運行出錯index index.html index.htm index.php; #添加index.php取消FastCGI server部分location的注釋,注意fastcgi_param行的參數(shù),改為$document_root$fastcgi_script_name,或者使用絕對路徑# 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 $document_root$fastcgi_script_name;include fastcgi_params;}:wq! vi /etc/php-fpm.conf # 根據(jù)內(nèi)存(grep MemTotal /proc/meminfo | cut -f2 -d:)調(diào)整并發(fā)請求處理數(shù),每個php-fpm進程占用20m左右物理內(nèi)存;單獨調(diào)高無用,需要對應(yīng)調(diào)整spare_server的配置。pm.max_children = 20pm.start_servers = 8 # start_servers = min_spare_servers + (max_spare_servers - min_spare_servers) / 2pm.min_spare_servers = 4pm.max_spare_servers = 12#******* 安裝擴展php-opensslcd /usr/local/src/php-5.5.31/ext/openssl/mv config0.m4 config.m4/usr/local/php/bin/phpize./configure --with-openssl --with-php-config=/usr/local/php/bin/php-configmakemake installvi /usr/local/php/etc/php.ini加入 extension="openssl.so"#******* 安裝擴展php-redistar -zxvf redis-2.2.4.tgzcd redis-2.2.4/usr/local/php/bin/phpizeConfiguring for:PHP Api Version: 20041225Zend Module Api No: 20060613Zend Extension Api No: 220060519 如果出現(xiàn):Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable is set correctly and then rerun this script.用下面的方法解決:# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz# tar -zvxf m4-1.4.9.tar.gz# cd m4-1.4.9/# ./configure && make && make install# cd ../# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz# tar -zvxf autoconf-2.62.tar.gz# cd autoconf-2.62/# ./configure && make && make install ./configure --with-php-config=/usr/local/php/bin/php-config makemake installvi /usr/local/php/etc/php.ini加入 extension="redis.so"# 所有此般編譯后的so都應(yīng)出現(xiàn)在該路徑/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/#******* 安裝擴展mongodb database drivertar -zxvf mongo-1.6.12.tgzcd mongo-1.6.12/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake installvi /usr/local/php/etc/php.ini加入 extension="mongo.so"#******* 安裝memcache服務(wù)與memcached擴展tar -zxvf libevent-2.0.22-stable.tar.gzcd libevent-2.0.22-stable./configure --prefix=/usr/local/libeventmakemake installtar -zxvf memcached-1.4.25.tar.gzmv memcached-1.4.25 memcached-svr-1.4.25cd memcached-svr-1.4.25./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libeventmakemake installvi /etc/init.d/memcached###################### 啟動腳本,添加以下內(nèi)容#! /bin/bash # # memcached start/stop the memcached daemon # # chkconfig: 35 80 70 # description: memcached is a memory cache server. #prog="memcached" exec=/usr/local/memcached/bin/memcachedlockfile=/var/lock/subsys/memcached # source function library. . /etc/rc.d/init.d/functions start() { if [ $UID -ne 0 ]; then echo "User has insufficient privilege." exit 4 fi [ -x $exec ] || exit 5 echo -n $"starting $prog: " daemon $exec -u root -d -P /var/run/memcached.pid retval=$? echo [ $retval -eq 0 ] && touch $lockfile } stop() { if [ $UID -ne 0 ]; then echo "User has insufficient privilege." exit 4 fi echo -n $"Stopping $prog: " if [ -n "`pidfileofproc $exec`" ]; then killproc $exec else failure $"stopping $prog" fi retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile } restart() { stop start } rh_status() { # run checks to determine if the service is running or use generic 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") rh_status_q || exit 7 $1 ;; "status") rh_status ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 2 ;; esac exit $?:wq!chmod 755 /etc/init.d/memcachedchkconfig memcached ontar -zxvf libmemcached-1.0.18.tar.gzcd libmemcached-1.0.18./configure --prefix=/usr/local/libmemcached --with-memcached=/usr/local/memcached/bin/memcachedmakemake installtar -zxvf memcached-2.2.0.tgzmv memcached-2.2.0 memcached-so-2.2.0cd memcached-so-2.2.0/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-saslmakemake installvi /usr/local/php/etc/php.ini加入 extension="memcached.so"/etc/init.d/nginx restart #重啟nginxservice php-fpm start #啟動php-fpm#******* 測試nginx+phpcd /usr/local/nginx/html/ #進入nginx默認網(wǎng)站根目錄rm -rf /usr/local/nginx/html/* #刪除默認測試頁vi index.php <?phpphpinfo();?>:wq! chown -R www.www /usr/local/nginx/html/chmod 700 /usr/local/nginx/html/ -R# 在瀏覽器中打開服務(wù)器IP地址,會看到php的界面============================================== MongoDBcd /usr/local/srcwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.1.tgztar -zxvf mongodb-linux-x86_64-rhel70-3.2.1.tgzmv /usr/local/src/mongodb-linux-x86_64-rhel70-3.2.1 /usr/local/mongodb #運行目錄groupadd mongodbuseradd -g mongodb mongodb -s /bin/falsemkdir -p /home/mongodb/db #數(shù)據(jù)目錄mkdir -p /home/mongodb/log #日志目錄chown -R mongodb:mongodb /usr/local/mongodbchown -R mongodb:mongodb /home/mongodbvi /usr/local/mongodb/mongodb.confport=27017pidfilepath=/usr/local/mongodb/mongo.pidfork=truedirectoryperdb=truedbpath=/home/mongodb/dblogpath=/home/mongodb/log/mongodb.loglogappend=trueshardsvr=true#auth=true #開啟認證#bind_ip=192.168.1.18 # Listen to local interface only. Comment out to listen on all interfaces.:wq!vi /etc/rc.d/init.d/mongod ############################# 啟動腳本,添加以下內(nèi)容#!/bin/sh# chkconfig: - 64 36# description:mongodb 3.2.1case $1 instart)/usr/local/mongodb/bin/mongod --maxConns 20000 --config /usr/local/mongodb/mongodb.conf;;stop)/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin --eval "db.shutdownServer()";;status)/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin --eval "db.stats()";;esac:wq! chmod 755 /etc/rc.d/init.d/mongod chkconfig mongod onservice mongod startvi /etc/profile #添加環(huán)境變量,在最后一行添加下面的代碼export PATH=$PATH:/usr/local/mongodb/bin:wq! source /etc/profile #使配置立即生效#啟動MongoDB方式 1/usr/local/mongodb/bin/mongod --port 27017 --fork --dbpath=/home/mongodb/db/ --logpath=/home/mongodb/log/mongodb.log --logappendnetstat -lanp | grep "27017" #查看MongoDB是否啟動cd /usr/local/mongodb/bin/./mongo #進入MongoDB數(shù)據(jù)庫控制臺use admin #進入admin數(shù)據(jù)庫db.shutdownServer() #關(guān)閉MongoDB數(shù)據(jù)庫exit #退出#啟動MongoDB方式 2mongo #進入MongoDB控制臺show dbs #查看默認數(shù)據(jù)庫use admin #切換到admin數(shù)據(jù)庫exit #退出MongoDB控制臺#啟動MongoDB方式 3cd /usr/local/mongodb/bin/./mongod --config /usr/local/mongodb/mongodb.conf #啟動MongoDB./mongo 127.0.0.1:27017/admin --eval "db.shutdownServer()" #關(guān)閉MongoDB#建立索引>mongo db.table01.ensureIndex({"myid":1});============================================== sphinxcd /usr/local/srcwget http://sphinxsearch.com/files/sphinx-2.2.8-release.tar.gztar -zxvf sphinx-2.2.8-release.tar.gzmv /usr/local/src/sphinx-2.2.8-release /usr/local/sphinxcd /usr/local/sphinx./configure --prefix=/usr/local/sphinx –-with-mysql# 出現(xiàn)下面的就可以進行下一步:configuration done-------------------You can now run 'make install' to ...make && make install #安裝結(jié)束,到/usr/local 目錄看是否有剛才指定的Sphinx目錄,有安裝成功# 在make時如果出現(xiàn)undefined reference to libiconv的錯誤:/usr/local/sphinx/src/sphinx.cpp:20060:undefined reference to `libiconv_open'/usr/local/sphinx/src/sphinx.cpp:20078: undefined reference to `libiconv'/usr/local/sphinx/src/sphinx.cpp:20084: undefined reference to `libiconv_close'collect2: ld returned 1exit statusmake[2]:***[indexer]Error1make[2]:Leaving directory `/home/sphinx/src'make[1]: *** [all] Error 2make[1]: Leaving directory `/home/sphinx/src'make: *** [all-recursive] Error 1解決辦法:打開configure文件,找到“#define USE_LIBICONV 1”,將注釋去掉,并將1改成0。執(zhí)行:#make clean#make && make install# 創(chuàng)建索引文件和存放目錄mkdir /home/sphinxmkdir /home/sphinx/indexdelta #創(chuàng)建增量索引存放目錄useradd sphxrun #不使用root運行chown sphxrun:sphxrun -R /home/sphinxchown sphxrun:sphxrun -R /usr/local/sphinx/varvi /usr/local/sphinx/etc/sphinx.conf #修改對應(yīng)索引的數(shù)據(jù)存放目錄:wq!vi /etc/rc.d/init.d/sphinx #################### 啟動腳本,添加以下內(nèi)容,【?。?!注意!??!啟動賬戶為新建的用戶“sphxrun”】#!/bin/sh # sphinx: Startup script for Sphinx search # # chkconfig: 345 86 14 # description: This is a daemon for high performance full text / # search of MySQL and PostgreSQL databases. / # See http://www.sphinxsearch.com/ for more info. # # processname: searchd # pidfile: $sphinxlocation/var/log/searchd.pid # Source function library. . /etc/rc.d/init.d/functions processname=searchd servicename=sphinx sphinxlocation=/usr/local/sphinx pidfile=$sphinxlocation/var/log/searchd.pid searchd=$sphinxlocation/bin/searchdindexer=$sphinxlocation/bin/indexercfgfile=$sphinxlocation/etc/sphinx.conf RETVAL=0 PATH=$PATH:$sphinxlocation/bin start() { su - sphxrun -c "$searchd -c $cfgfile > /dev/null 2>&1" ret=$? if [ $ret -eq 0 ]; then action $"Starting Sphinx: " /bin/true else action $"Starting Sphinx: " /bin/false fi return $ret} stop() { echo -n $"Stopping Sphinx daemon: " su - sphxrun -c "$searchd --config $cfgfile --stop" #killproc -p $pidfile $servicename -TERM RETVAL=$? echo if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/$servicename rm -f $pidfile fi }indexer(){ su - sphxrun -c "$indexer --config $cfgfile --all --rotate > /dev/null 2>&1" ret=$? if [ $ret -eq 0 ]; then action $"sphinx making index: " /bin/true else action $"sphinx making index: " /bin/false fi return $ret } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status $processname RETVAL=$? ;; restart) stop sleep 3 start sleep 3 ;; indexer) indexer ;; condrestart) if [ -f /var/lock/subsys/$servicename ]; then stop sleep 3 start sleep 3 fi ;; *) echo $"Usage: $0 {start|stop|status|restart|indexer|condrestart}" ;; esac exit $RETVAL:wq!chmod 755 /etc/rc.d/init.d/sphinx chkconfig sphinx on# 如果sphinx文件太大,刪除對應(yīng)存放目錄文件cd /home/sphinx/rm * -frmkdir indexdelta#如果提示searchd.pid錯誤,則執(zhí)行下兩步vi /usr/local/sphinx/var/log/searchd.pid寫入11770============================================== jvmyum search java #找到合適的版本,然后執(zhí)行installyum install -y java-1.8.0-openjdk-develjava -versionvi /etc/profile export JAVA_HOME=/usr/lib/jvm/java-1.8.0 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH source /etc/profile============================================== redis servercd /usr/local/srcwget http://download.redis.io/releases/redis-3.0.6.tar.gztar -zxvf redis-3.0.6.tar.gzcd redis-3.0.6make MALLOC=libc #如果不加參數(shù),linux下會報錯,沒試過,反正是加上了參數(shù)編譯的make testmake install #將可執(zhí)行文件拷貝到/usr/local/bin目錄mkdir /home/redis #數(shù)據(jù)data和日志log目錄./utils/install_server.sh #問答式的配置如下,執(zhí)行腳本使得Redis隨系統(tǒng)啟動###################################################Selected config:Port : 6379Config file : /etc/redis/6379.confLog file : /home/redis/log/redis_6379.logData dir : /home/redis/6379Executable : /usr/local/bin/redis-serverCli Executable : /usr/local/bin/redis-cli###################################################chkconfig --list #檢查是否開機啟動# 測試redis-cli127.0.0.1:6379> set foo barOK127.0.0.1:6379> get foo"bar"src/redis-server & #啟動redis (后臺開啟服務(wù)器)src/redis-cli shutdown #關(guān)閉redis新聞熱點
疑難解答
圖片精選