设为首页 收藏本站
查看: 919|回复: 0

生产环境编译安装LAMP环境

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-12-30 14:00:07 | 显示全部楼层 |阅读模式
#!/bin/bash
#
#LAMP自动化部署脚本(我的生产环境一般都将所有需要用的软件放在/data/source_package目录,同步到服务器,这样更快速和安全。)

#################安装前准备##################
#1、清除系统默认安装的http、mysql、php

rpm -q mysql-server &> /dev/null && rpm -e --nodeps mysql-server
rpm -q mysql &> /dev/null && rpm -e --nodeps mysql
rpm -q httpd &> /dev/null && rpm -e --nodeps httpd
rpm -q php &> /dev/null && rpm -e --nodeps php
rpm -q php-fpm &> /dev/null && rpm -e --nodeps php-fpm

#2、安装gcc、gcc-c++ make wget编译包
yum -y install gcc gcc-c++ make

#################安装http##################


#1、安装httpd编译需的依赖包
yum -y install pcre pcre-devel openssl openssl-devel

#2、安装apr支持包
cd /data/source_package/lamp/http/
tar zxvf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/data/soft/apr  
make && make install
cd ../

#3、安装apr-util支持包
tar zxvf apr-util-1.5.2.tar.gz
cd apr-util-1.5.2
./configure --prefix=/data/soft/apr-util --with-apr=/data/soft/apr
make && make install
cd ../

#4、安装apr-iconv支持包
tar zvxf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure --prefix=/data/soft/apr-iconv --with-apr=/data/soft/apr
make && make install
cd ../

#5、安装httpd
tar zxvf httpd-2.4.4.tar.gz
cd httpd-2.4.4
./configure --prefix=/data/soft/apache --sysconfdir=/etc/httpd --with-apr=/data/soft/apr --with-apr-iconv=/data/soft/apr-iconv --with-apr-util=/data/soft/apr-util --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre  --enable-modules=most --enable-mpms-shared=all --with-mpm=event
make && make install

#8、备份httpd运行文件
cp /etc/httpd/httpd.conf /etc/httpd/httpd.conf.bak

#9、配置httpd文件
sed -i '192a ServerName localhost:80' /etc/httpd/httpd.conf      
sed -i '194a Pidfile "/var/run/httpd.pid"' /etc/httpd/httpd.conf  

#10、设置httpd服务自启动
cp /data/soft/apache/bin/apachectl /etc/rc.d/init.d/httpd
sed -i '2a #chkconfig: 345 85 15' /etc/rc.d/init.d/httpd
chmod 775 /etc/rc.d/init.d/httpd
chkconfig --add httpd
chkconfig httpd on

#11、启动httpd服务
service httpd start

#################安装mysql##################
#1、安装mysql编译需的依赖包

yum -y install bison cmake openssl openssl-devel ncurses ncurses-devel

#2、创建mysql 用户组
groupadd mysql
useradd -g mysql mysql

#3、创建mysql安装目录
mkdir /data/soft/mysql

#4、mysql安装目录、授权
chown -R mysql:mysql /data/soft/mysql
chmod 775 /data/soft/mysql

#5、创建mysql数据目录
mkdir /data/soft/mysql/data

#6、mysql 数据目录 授权
chown -R mysql:mysql /data/soft/mysql/data
chmod 775 /data/soft/mysql/data

#7、创建mysql日志目录
mkdir /data/soft/mysql/logs

#8、mysql日志目录授权
chown -R mysql:mysql /data/soft/mysql/logs
chmod 775 /data/soft/mysql/logs

#9、mysql pid文件目录授权
chown -R mysql:mysql /tmp
chmod 775 /tmp

#10、解压mysql
cd /data/source_package/lamp/mysql
tar zxvf mysql-5.5.17.tar.gz
cd mysql-5.5.17

#11、编译、安装mysql
cmake -DCMAKE_INSTALL_PREFIX=/data/soft/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306

make && make install

#12、设置MYSQL运行配置/etc/my.cnf文件
cat > /etc/my.cnf << EOF
# Example MySQL config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MySQL.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password        = your_password
port                = 3306
socket                = /tmp/mysql.sock
default-character-set=utf8

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
character_set_server=utf8        #设置服务端编码
max_connections=2000                #根据服务器性能调节
basedir=/data/soft/mysql        #设置安装目录,这样在系统启动时才能正确运行到/etc/rc.d/init.d/mysql start

port                = 3306
socket                = /tmp/mysql.sock
skip-external-locking
skip-name-resolve
key_buffer_size = 256M
max_allowed_packet = 20M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id        = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/bin/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/bin/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

datadir=/data/soft/mysql/data
pid-file=/data/soft/mysql/data/mysql.pid
tmpdir=/tmp

expire_logs_day=7
log_error=/data/soft/mysql/logs/error.log

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
EOF

#13、初始化MYSQL系统数据库
/data/soft/mysql/scripts/mysql_install_db --user=mysql --basedir=/data/soft/mysql --datadir=/data/soft/mysql/data

#14、设置MYSQL服务自启动
cp /data/soft/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 775 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

#15、启动MYSQL服务
service mysqld start

#16、把MYSQL路径添加到环境变量
echo 'export PATH=$PATH:/data/soft/mysql/bin:/data/soft/mysql/lib' >> /etc/profile
source /etc/profile

#17、link MYSQL依赖库到系统库中
ln -s /data/soft/mysql/lib/* /usr/lib64/

#18、设置MYSQL管理员密码
mysqladmin -uroot password "passwd"

#################安装php##################
#1、安装php编译需的依赖包
yum -y install libmng libxml2 libxml2-devel libevent libevent-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel bzip2 bzip2-devel gmp gmp-devel gd gd-devel

#2、安装libmcrypt支持
cd /data/source_package/lamp/php
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
cd ../

#3、安装mhash支持包
tar jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install
cd ../

#4、创建lib库软连接
ln -sv /usr/local/lib/* /usr/lib64/

#5、安装mcrypt支持包
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure   
make && make install
cd ../

#6、安装php
tar jxvf php-5.4.17.tar.bz2
cd php-5.4.17
./configure --prefix=/data/soft/php --with-config-file-path=/etc  --with-mysql=/data/soft/mysql/ --with-mysqli=/data/soft/mysql/bin/mysql_config  --with-pdo-mysql=/data/soft/mysql/ --with-iconv-dir=/data/soft/  --with-apxs2=/data/soft/apache/bin/apxs --disable-phar --with-pcre-regex  --with-zlib --with-bz2 --with-curl --with-gmp --enable-dba --with-libxml-dir  --with-zlib-dir  --with-mhash --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-mcrypt --enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip --enable-bcmath --disable-ipv6
make && make install

#7、复制php.ini文件
cp php.ini-production /etc/php.ini

#8、修改php.ini文件
sed -i 's@memory_limit = 128M@memory_limit = 512M@' /etc/php.ini
sed -i '919a date.timezone = "PRC"' /etc/php.ini
sed -i 's@;error_log = syslog@error_log = /data/www/log/php_error.log@' /etc/php.ini

#9、把PHP路径添加到环境变量
echo 'export PATH=$PATH:/data/soft/php/bin' >> /etc/profile
source /etc/profile

#10、修改httpd.conf的文件
sed -i '381a AddType application/x-httpd-php  .php .phtml' /etc/httpd/httpd.conf
sed -i '382a AddType application/x-httpd-php-source .phps' /etc/httpd/httpd.conf
sed -i '383a PHPIniDir "/etc/php.ini"' /etc/httpd/httpd.conf
sed -i 's@DirectoryIndex index.html@DirectoryIndex index.php index.html@' /etc/httpd/httpd.conf
sed -i 's@DocumentRoot "/data/soft/apache/htdocs"@#DocumentRoot "/data/soft/apache/htdocs"@' /etc/httpd/httpd.conf
sed -i 's@#Include /etc/httpd/extra/httpd-vhosts.conf@Include /etc/httpd/extra/httpd-vhosts.conf@' /etc/httpd/httpd.conf

#11、配置虚拟主机
cp /etc/httpd/extra/httpd-vhosts.conf /etc/httpd/extra/httpd-vhosts.conf.bak
cat > /etc/httpd/extra/httpd-vhosts.conf << EOF
<VirtualHost *:80>
    DocumentRoot "/data/www"
    ErrorLog "/data/www/logs/httpd_error_log"
  <Directory "/data/www">
    Options none
    AllowOverride None
    Require all granted
  </Directory>
</VirtualHost>
EOF

#12、创建网页目录和日志录
mkdir /data/www
chmod 777 /data/www
mkdir /data/www/logs
chmod 777 /data/www/logs

#13、修改完成后必须重启Apache服务器,才能重新加载配置文件使修改生效。
service httpd restart

#14、试PHP环境是否可以正常运行,在/data/www/目录下建一个test.php文件,内容如下:
cat > /data/www/test.php << EOF
<?php

phpinfo();

?>
EOF

#15、打开浏览器,在地址栏输入http://ip/test.php来打开测试网页

#################安装Xcache##################
#1、安装Xcache
cd /data/source_package/lamp/xcache
tar zxvf xcache-3.1.0.tar.gz
cd xcache-3.1.0
/data/soft/php/bin/phpize
./configure --with-php-config=/data/soft/php/bin/php-config --enable-xcache --enable-xcache-coverager --enable-xcache-optimizer
make && make install
#安装完毕之后,会提示一个安装路径,记下来。
#比如:Installing shared extensions: /data/soft/php/lib/php/extensions/no-debug-zts-20100525/

#2、复制xcache.so文件到/data/soft/php/include/php/ext/
cp /data/soft/php/lib/php/extensions/no-debug-zts-20100525/xcache.so /data/soft/php/include/php/ext/

#3、配置/etc/php.ini文件,在最后追加Xcache配置
echo '[xcache-common]
extension = xcache.so

[xcache.admin]
xcache.admin.user = "admin"
xcache.admin.pass = "f6c770a1c6a0cd6b5639baf16d4c6a3d"

[xcache]
xcache.cacher = On
xcache.shm_scheme = "mmap"
xcache.size = 32M
; cpu number (cat /proc/cpuinfo |grep -c processor)
xcache.count = 2
xcache.slots = 8k
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 2M'>> /etc/php.ini

#4、重启httpd服务。
service httpd restart

#5、重新测试入http://ip/test.php,看是否加载到xcache



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-158450-1-1.html 上篇帖子: LAMP平台部署及应用 下篇帖子: LAMP+event+xcache编译安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表