zoukankan      html  css  js  c++  java
  • LAMP搭建

    安装步骤
    1.配置前的包准备工作
    2.安装apache
    3.安装myql
    4.安装php
    5.安装redis
    6.安装memcached
    7.安装PHP扩展

    8.验证

    1、配置前的包准备工作
    yum install -y wget gcc openssl gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd-devel pcre-devel pcre bison flex

    2、安装apache:
    mkdir -p /newdisk/software
    cd /newdisk/software
    wget http://mirror.esocc.com/apache//apr/apr-1.5.2.tar.gz
    wget http://mirror.esocc.com/apache//apr/apr-util-1.5.4.tar.gz
    tar -xzvf apr-1.5.2.tar.gz
    tar -xzvf apr-util-1.5.4.tar.gz
    wget http://archive.apache.org/dist/httpd/httpd-2.4.16.tar.gz
    tar -xzvf httpd-2.4.16.tar.gz
    cp -rf apr-1.5.2 /newdisk/software/httpd-2.4.16/srclib/apr/
    cp -rf apr-util-1.5.4 /newdisk/software/httpd-2.4.16/srclib/apr-util

    /usr/sbin/groupadd www
    /usr/sbin/useradd -r -g www www
    cd httpd-2.4.16
    ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support --enable-ssl=shared
    make
    make install

    #验证配置文件正确性
    /usr/local/apache2/bin/apachectl -t
    /usr/local/apache2/bin/apachectl start

    #添加apache服务自启动:
    echo "/usr/local/apache2/bin/apachectl start">>/etc/rc.d/rc.local

    3、安装mysql:
    yum install libaio cmake ncurses-devel -y
    cd /newdisk/software
    wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.13.tar.gz/from/http://cdn.mysql.com/

    tar xzf mysql-5.6.13.tar.gz

    cd mysql-5.6.13

    /usr/sbin/groupadd mysql
    /usr/sbin/useradd -g mysql mysql

    ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib64/libmysqlclient.so.18
    ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/lib/libmysqlclient.so.18
    ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/local/lib64/libmysqlclient.so.18
    ln -s /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /usr/local/lib/libmysqlclient.so.18

    /usr/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=0 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DINSTALL_LAYOUT=STANDALONE -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DWITH_DEBUG=OFF

    make

    make install

    chmod a+w /usr/local/mysql
    chown -R mysql:mysql /usr/local/mysql
    mkdir -p /newdisk/data/mysql/data

    chown -R mysql:mysql /newdisk/data/mysql/
    cp ./support-files/my-default.cnf /newdisk/data/mysql/my.cnf
    echo ''>/newdisk/data/mysql/my.cnf
    chmod a+w /var/run

    vi /newdisk/data/mysql/my.cnf

    [client]
    port = 3306
    socket = /tmp/mysql.sock
    character-set-server = utf8
    [mysqld]
    character-set-server = utf8
    collation-server = utf8_general_ci
    replicate-ignore-db = mysql
    replicate-ignore-db = test
    replicate-ignore-db = information_schema
    user = mysql
    port = 3307
    socket = /tmp/mysql.sock
    basedir = /usr/local/mysql
    datadir = /newdisk/data/mysql/data
    log-error = /newdisk/data/mysql/error.log
    pid-file = /var/run/mysql.pid
    local-infile = 0
    open_files_limit = 10240
    back_log = 1500
    max_connections = 4000
    max_connect_errors = 6000
    skip-external-locking
    max_allowed_packet = 32M
    thread_cache_size = 300
    query_cache_size = 512M
    query_cache_limit = 2M
    query_cache_min_res_unit = 2k
    default-storage-engine = MyISAM
    thread_stack = 256K
    transaction_isolation = READ-COMMITTED
    tmp_table_size = 256M
    max_heap_table_size = 256M
    net_buffer_length = 8K
    key_buffer_size = 200M
    low_priority_updates = 1
    read_buffer_size = 4M
    read_rnd_buffer_size = 16M
    bulk_insert_buffer_size = 64M
    myisam_sort_buffer_size = 128M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
    myisam-recover-options
    interactive_timeout = 120
    wait_timeout = 120
    skip-name-resolve
    expire_logs_days = 30
    innodb_data_file_path = ibdata1:256M:autoextend
    innodb_lock_wait_timeout = 120
    explicit_defaults_for_timestamp=true
    innodb_force_recovery = 1 # files
    innodb_file_per_table
    innodb_log_file_size = 200M
    innodb_log_files_in_group = 3
    innodb_open_files = 4000
    table_open_cache = 8000
    table_open_cache_instances = 8

    #buffers
    innodb_buffer_pool_size = 100M
    innodb_buffer_pool_instances = 24
    innodb_log_buffer_size = 64M
    sort_buffer_size = 6M
    join_buffer_size = 8M

    #tune
    innodb_checksums = 0
    innodb_doublewrite = 0
    innodb_support_xa = 0
    innodb_thread_concurrency = 0
    innodb_flush_log_at_trx_commit = 2
    innodb_flush_method = O_DIRECT
    innodb_max_dirty_pages_pct = 50
    innodb_use_native_aio =1
    innodb_stats_persistent = 1
    innodb_spin_wait_delay = 6

    #performance special
    innodb_adaptive_flushing = 1
    innodb_flush_neighbors = 0
    innodb_read_io_threads = 16
    innodb_write_io_threads = 4
    innodb_io_capacity = 2000
    innodb_purge_threads = 1
    innodb_adaptive_hash_index = 1

    [mysqldump]
    quick
    max_allowed_packet = 32M
    [mysql]
    no-auto-rehash
    [myisamchk]
    key_buffer_size = 20M
    sort_buffer_size = 20M
    read_buffer = 2M
    write_buffer = 2M
    [mysqlhotcopy]
    interactive-timeout

    初始化DB:
    /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/newdisk/data/mysql/data --user=mysql --defaults-file=/newdisk/data/mysql/my.cnf

    启动DB:
    /usr/local/mysql/bin/mysqld_safe --defaults-file=/newdisk/data/mysql/my.cnf &

    更改数据库密码:
    /usr/local/mysql/bin/mysqladmin -uroot password 'aA123456'
    登录测试数据库,输入密码登录数据库,退出输入exit或者q:
    /usr/local/mysql/bin/mysql -uroot -p

    创建数据库启动文件:
    touch /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    vi /etc/init.d/mysqld
    #!/bin/sh
    #chkconfig: 345 90 90
    #description: MySQL version 5.6.13 listens on port 3307

    mysql_port=3307
    mysql_username="root"
    mysql_password="aA123456"
    function_start_mysql() { printf "Starting MySQL... "
    /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/newdisk/data/mysql/my.cnf 2>&1 > /dev/null &
    }
    function_stop_mysql() {
    printf "Stoping MySQL... "
    /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} shutdown
    }
    function_restart_mysql() {
    printf "Restarting MySQL... "
    function_stop_mysql
    sleep 5
    function_start_mysql
    }
    function_kill_mysql() {
    kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
    kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
    }
    if [ "$1" = "start" ]; then
    function_start_mysql
    elif [ "$1" = "stop" ]; then
    function_stop_mysql
    elif [ "$1" = "restart" ]; then
    function_restart_mysql
    elif [ "$1" = "kill" ]; then
    function_kill_mysql
    else
    printf "Usage: /etc/init.d/mysqld-${mysql_port} {start|stop|restart|kill} "
    fi

    开启自启动数据库服务:
    chkconfig --add /etc/init.d/mysqld

    4、安装php:
    yum install libicu php-mcrypt libmcrypt libmcrypt-devel mhash-devel libicu-devel -y
    cd /newdisk/software
    wget http://museum.php.net/php5/php-5.4.33.tar.gz
    tar xzf php-5.4.33.tar.gz
    cd php-5.4.33
    cp -frp /usr/lib64/libjpeg.* /usr/lib/
    cp -frp /usr/lib64/libpng* /usr/lib/
    ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/etc/php --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-zlib --with-curl --with-curlwrappers --enable-intl --with-icu-dir=/usr --with-libxml-dir --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --with-mcrypt --enable-mbregex --with-openssl --enable-soap --enable-gd-native-ttf --enable-ftp --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --with-mhash --enable-calendar --with-bz2 --with-gettext --enable-wddx --enable-mbstring=all
    make
    make test
    make install

    mkdir -p /etc/php
    cp php.ini-development /etc/php/php.ini
    vi /etc/php/php.ini
    #更改不显示错误
    display_errors = Off

    5、安装radis服务器:
    cd /newdisk/software
    wget http://download.redis.io/releases/redis-2.6.17.tar.gz
    tar -xzvf redis-2.6.17.tar.gz
    cp -rf redis-2.6.17 /usr/local/redis
    cd /usr/local/redis
    make
    make test
    make install

    安装过程中如果出现以下错误:

    make1: Entering directory `/usr/local/redis/src'
    You need tcl 8.5 or newer in order to run the Redis test
    make1: * [test] Error 1 make1: Leaving directory `/usr/local/redis/src' make: * [test] Error 2

    解决办法如下:
    cd /newdisk/software
    wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
    tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
    cd /usr/local/tcl8.6.1/unix/
    ./configure
    make
    make install

    解决之后再次进入
    cd /usr/local/redis
    make clean
    make
    make test
    make install

    mkdir -p /usr/local/redis/bin
    mkdir -p /usr/local/redis/etc
    mkdir -p /usr/local/redis/var
    cd src/
    cp redis-server redis-cli redis-benchmark redis-sentinel /usr/local/redis/bin/
    cp ../redis.conf /usr/local/redis/etc/

    启动radis服务:

    /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf &

    添加到开机启动:

    echo "/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf &">>/etc/rc.d/rc.local

    验证radis服务器是否安装,查看6379端口是否开放:
    netstat -antupl|grep '6379'

    6、安装memcached服务器:
    6.1、安装libevent:
    cd /newdisk/software
    wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
    tar -xzvf libevent-1.4.13-stable.tar.gz
    cd libevent-1.4.13-stable
    ./configure --prefix=/usr/local/libevent
    make
    make install

    6.2、安装libmemcached:
    cd /newdisk/software
    wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
    tar -xzvf libmemcached-1.0.18.tar.gz
    cd libmemcached-1.0.18
    ./configure --prefix=/usr/local/libmemcached
    make
    make install

    6.3、安装memcached服务器:
    cd /newdisk/software
    tar -xzvf memcached-1.4.15.tar.gz
    cd memcached-1.4.15
    ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/
    make
    make install

    开启memcached:

    /usr/local/memcached/bin/memcached -d -m 10 -p 12000 -u root -c 256

    添加到开机启动:
    echo "/usr/local/memcached/bin/memcached -d -m 10 -p 12000 -u root -c 256">>/etc/rc.d/rc.local

    验证memcached服务器是否安装成功,查看12000端口是否开放:
    netstat -antupl|grep '12000'

    7、安装PHP扩展:

    7.1、安装memcached扩展:
    cd /newdisk/software
    wget http://pecl.php.net/get/memcached-2.1.0.tgz
    tar xzf memcached-2.1.0.tgz
    cd memcached-2.1.0
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config -with-libmemcached-dir=/usr/local/libmemcached/
    make
    make install

    7.2、安装radis扩展:
    cd /newdisk/software
    wget http://pecl.php.net/get/redis-2.2.3.tgz
    tar xzf redis-2.2.3.tgz
    cd redis-2.2.3
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php//bin/php-config
    make
    make test
    make install

    7.3、安装APC扩展
    cd /newdisk/software
    wget http://pecl.php.net/get/APC-3.1.13.tgz
    tar xzf APC-3.1.13.tgz
    cd APC-3.1.13
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make
    make test
    make install

    7.4、安装memcache扩展
    cd /newdisk/software
    wget http://pecl.php.net/get/memcache-2.2.7.tgz
    tar xzf memcache-2.2.7.tgz
    cd memcache-2.2.7
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make
    make test
    make install

    7.5、安装markdown扩展
    cd /newdisk/software
    wget http://pecl.php.net/get/markdown-1.0.0.tgz
    tar xzf markdown-1.0.0.tgz
    cd markdown-1.0.0
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make
    make install

    7.6、安装sphinx扩展
    cd /newdisk/software
    yum install libtool -y wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
    tar zxvf coreseek-4.1-beta.tar.gz
    cd coreseek-4.1-beta
    cd csft-4.1/api
    cd libsphinxclient/
    sh -x buildconf.sh

    如果出现这样的错误:
    configure.in:20: error: possibly undefined macro: AC_PROG_LD
    If this token and others are legitimate, please use m4_pattern_allow.
    See the Autoconf documentation.
    configure.in:26: error: possibly undefined macro: AM_PROG_LIBTOOL
    rebuilding sphinxclient_config.h.in
    rebuilding Makefile.in files

    解决办法:
    cp -R /usr/share/aclocal/ /usr/share/aclocal-1.11/*

    ./configure
    make
    make install

    cd /newdisk/software
    wget http://pecl.php.net/get/sphinx-1.3.2.tgz
    tar xzvf sphinx-1.3.0.tgz
    cd sphinx-1.3.0
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config
    make
    make test
    make install

    7.8、php主配置文件中加入扩展:

    vi /etc/php/php.ini

    找到这行:

    extension_dir = "./"

    修改为:

    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

    新增以下行:

    extension=redis.so
    extension=memcached.so extension=apc.so
    extension=discount.so
    extension=memcache.so

    8、验证

    编辑Apache配置文件:

    vi /etc/httpd/httpd.conf

    添加下面这行内容:

    Addtype application/x-httpd-php .php .php5 .phtml

    找到此行,加入index.php:

    DirectoryIndex index.php index.html

    重启apache,测试是否php文件能够正确解析:

    /usr/local/apache2/bin/apachectl restart

    在/usr/local/apache2/htdocs文件夹下新增一个php文件。

    echo "<?php echo 'Hello World'?>" > index.php

    输入地址http://IP地址,测试,如果能正确输出Hello World,说明能够正确解析php文件了。

  • 相关阅读:
    博客园
    未释放的已删除文件
    ssh连接缓慢
    剑指 Offer 38. 字符串的排列
    剑指 Offer 37. 序列化二叉树
    剑指 Offer 50. 第一个只出现一次的字符
    剑指 Offer 36. 二叉搜索树与双向链表
    剑指 Offer 35. 复杂链表的复制
    剑指 Offer 34. 二叉树中和为某一值的路径
    剑指 Offer 33. 二叉搜索树的后序遍历序列
  • 原文地址:https://www.cnblogs.com/luckyjinping/p/4763307.html
Copyright © 2011-2022 走看看